Exemple #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]))
Exemple #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)
Exemple #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'])
Exemple #4
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])
Exemple #5
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)
Exemple #6
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'])