Esempio n. 1
0
def remove_duplicates():
    global __cl_sync
    common.print_line('removing duplicates')
    if __cl_sync is None:
        __cl_sync = clsync.ClSync(__config)
    if len(__args) == 1:
        logging.error('invalid removedups command')
        usage_removedups()
        sys.exit(-1)
    __cl_sync.remove_duplicates(common.remove_ending_slash(__args[1]))
Esempio n. 2
0
 def run(self):
     logging.info('starting daemom to backup path: ' + self.__local_dir)
     sleep_interval = self.__config['daemon_interval'] * 60
     while True:
         __cl_sync = clsync.ClSync(self.__config)
         local_dir = common.remove_ending_slash(self.__local_dir)
         common.print_line('backing up ' + local_dir + '...')
         __cl_sync.backup(local_dir, self.__config['delete_files'], self.__config['dry_run'])
         logging.info('sleeping for ' + str(sleep_interval) + ' seconds...')
         time.sleep(sleep_interval)
Esempio n. 3
0
def backup():
    global __cl_sync
    if __cl_sync is None:
        __cl_sync = clsync.ClSync(__config)
    if len(__args) == 1:
        logging.error('invalid backup command')
        usage_backup()
        sys.exit(-1)
    local_dir = common.remove_ending_slash(__args[1])
    common.print_line('backing up ' + local_dir + '...')
    __cl_sync.backup(local_dir, __config['delete_files'], __config['dry_run'])
Esempio n. 4
0
def check_prerequisites():
    logging.info('checking prerequisites, examine the error messages below...')
    check_reault = True
    try:
        __cl_sync = clsync.ClSync(__config)
        __cl_sync.get_remotes()
    except:
        check_reault = False
    if check_reault is True:
        logging.info('**** PASSED! ****')
    else:
        logging.info('**** FAILED! *****')
Esempio n. 5
0
def stats():
    global __cl_sync
    logging.debug('display stats about the volumes')
    common.print_line('calculating total and free space...')
    if __cl_sync is None:
        __cl_sync = clsync.ClSync(__config)
    common.print_line('REMOTE'.ljust(15) + " " + 'SIZE'.rjust(20) + " " +
                      'FREE'.rjust(20) + " " + '%FREE'.rjust(10))
    common.print_line(''.join('=' for i in range(15)) + " " +
                      ''.join('=' for i in range(20)) + " " +
                      ''.join('=' for i in range(20)) + " " +
                      ''.join('=' for i in range(10)))
    sizes = __cl_sync.get_sizes()
    frees = __cl_sync.get_frees()
    display_unit = __config['display_unit']
    for remote in sizes:
        percent_use = frees[remote] * 100 / sizes[remote]
        size_d = common.convert_unit(sizes[remote], display_unit)
        free_d = common.convert_unit(frees[remote], display_unit)
        common.print_line(
            remote.ljust(15) + " " + "{:,}".format(size_d).rjust(19) +
            display_unit + " " + "{:,}".format(free_d).rjust(19) +
            display_unit + " " + "{:,}".format(int(percent_use)).rjust(10))

    size = __cl_sync.get_size()
    free = __cl_sync.get_free()
    logging.debug('size: ' + "{:,}".format(size))
    logging.debug('free: ' + "{:,}".format(free))
    percent_use = free * 100 / size
    common.print_line(''.join('-' for i in range(15)) + " " +
                      ''.join('-' for i in range(20)) + " " +
                      ''.join('-' for i in range(20)) + " " +
                      ''.join('-' for i in range(10)))
    size_d = common.convert_unit(size, display_unit)
    free_d = common.convert_unit(free, display_unit)
    common.print_line("total:".ljust(15) + " " +
                      "{:,}".format(size_d).rjust(19) + display_unit + " " +
                      "{:,}".format(free_d).rjust(19) + display_unit + " " +
                      "{:,}".format(int(percent_use)).rjust(10))
Esempio n. 6
0
def lsmd5():
    global __cl_sync
    if __cl_sync is None:
        __cl_sync = clsync.ClSync(__config)
    if len(__args) == 1:
        logging.error('invalid lsmd5 command')
        usage_lsmd5()
        sys.exit(-1)
    files = __cl_sync.lsmd5(common.remove_ending_slash(__args[1]))
    largest_length = 25
    keys = common.sort_dict_keys(files)
    for tmp_file in keys:
        filename_length = len(tmp_file)
        if filename_length > largest_length:
            largest_length = filename_length
    common.print_line('NAME'.ljust(largest_length) + " " + 'MD5'.ljust(32))
    common.print_line(''.join('-' for i in range(largest_length)) + " " +
                      ''.join('-' for i in range(32)))

    for tmp_file in keys:
        file_name = tmp_file
        common.print_line(
            file_name.ljust(largest_length) + " " + files[tmp_file])
Esempio n. 7
0
def find():
    global __cl_sync
    if __cl_sync is None:
        __cl_sync = clsync.ClSync(__config)
    if len(__args) == 1:
        logging.error('invalid find command')
        usage_find()
        sys.exit(-1)
    files = __cl_sync.find(common.remove_ending_slash(__args[1]))
    largest_length = 25
    keys = common.sort_dict_keys(files)
    for tmp_file in keys:
        filename_length = len(files[tmp_file].path)
        if not files[tmp_file].is_dir and filename_length > largest_length:
            largest_length = filename_length
    common.print_line('---' + " " + 'NAME'.ljust(largest_length) + " " +
                      'SIZE'.rjust(9) + " " + 'MOD TIME'.ljust(19) + " " +
                      'REMOTE')
    common.print_line('---' + " " + ''.join('-'
                                            for i in range(largest_length)) +
                      " " + ''.join('-' for i in range(9)) + " " +
                      ''.join('-' for i in range(19)) + " " +
                      ''.join('-' for i in range(15)))
    for tmp_file in keys:
        if files[tmp_file].is_dir is True:
            first_chars = '-d-'
        else:
            first_chars = '---'
        file_name = files[tmp_file].path
        if file_name.startswith('//'):
            file_name = file_name[1:len(file_name)]
        common.print_line(
            first_chars + " " + file_name.ljust(largest_length) + " " +
            str(files[tmp_file].size).rjust(9) + " " +
            common.get_printable_datetime(files[tmp_file].mod_time).ljust(19) +
            " " + files[tmp_file].remote)
Esempio n. 8
0
def restore():
    global __cl_sync
    if __cl_sync is None:
        __cl_sync = clsync.ClSync(__config)
    if len(__args) < 3:
        logging.error('invalid remote command')
        usage_restore()
        sys.exit(-1)
    remote_path = __args[2]
    local_dir = common.remove_ending_slash(__args[1])
    if __config['restore_duplicates'] is False:
        common.print_line(
            'checking if duplicates are present before restoring...')
        duplicates = __cl_sync.remove_duplicates(local_dir, True)
        if len(duplicates) > 0:
            common.print_line('DUPLICATE FILES FOUND:')
            for duplicate in duplicates:
                common.print_line("\t" + duplicate)
            common.print_line(
                'restore cannot proceed! Use remove duplicates function before continuing'
            )
            return
    common.print_line('restoring ' + remote_path + ' from ' + local_dir)
    __cl_sync.restore(local_dir, remote_path, __config['dry_run'])