Ejemplo n.º 1
0
def backup2(task):
    if not _quiet:
        kits.stdout('Backup {}'.format(task['name']))
    task['filter'].extend(config['global_filter'])
    rsync = kits.rsync.RSync(task['src'], task['dst'], sshkey=config['ssh_key'],
        sshport=config['ssh_port'],
        backup_dir=task['bak'], filter_rule=task['filter'], quiet=_quiet)
    args = ['-h', '--stats', '--progress'] if not _quiet else ['--quiet']
    cmd = rsync.toCmd(*args)
    print(cmd)
    subprocess.call(cmd, shell=True)
    print('')
Ejemplo n.º 2
0
def backup(task):
    if not _quiet:
        kits.stdout('Backup {}'.format(task['name']))
    try:
        task['filter'].extend(config['global_filter'])
        rsync = kits.rsync.RSync(task['src'], task['dst'], sshkey=config['ssh_key'], backup_dir=task['bak'], 
            filter_rule=task['filter'], quiet=_quiet)
        # print(rsync.toCmd('--stats', '--dry-run'))
        # return
        total, size, elapsed = rsync.run(exact_progress=_exact_progress)
        if size != 0:
            logger.info('%s backup finished. Num: %d, Size: %s Elapsed: %s, Speed: %s, Source: %s',
                task['name'], total, kits.util.hrData(size), kits.util.hrTime(elapsed),
                kits.util.hrData(float(size) / elapsed), task['src'])
        else:
            logger.info('%s backup finished, already up-to-date. Elapsed: %s, Source: %s',
                task['name'], kits.util.hrTime(elapsed), task['src'])
        if not _quiet:
            kits.stdout('')
    except KeyboardInterrupt, e:
        kits.exit('\n\nCanceled.')
Ejemplo n.º 3
0
        # return
        total, size, elapsed = rsync.run(exact_progress=_exact_progress)
        if size != 0:
            logger.info('%s backup finished. Num: %d, Size: %s Elapsed: %s, Speed: %s, Source: %s',
                task['name'], total, kits.util.hrData(size), kits.util.hrTime(elapsed),
                kits.util.hrData(float(size) / elapsed), task['src'])
        else:
            logger.info('%s backup finished, already up-to-date. Elapsed: %s, Source: %s',
                task['name'], kits.util.hrTime(elapsed), task['src'])
        if not _quiet:
            kits.stdout('')
    except KeyboardInterrupt, e:
        kits.exit('\n\nCanceled.')
    except Exception, e:
        logger.error(e)
        kits.stdout('{} backup fail.'.format(task['name']));
        # raise e

def main():
    global _exact_progress, _quiet, logger
    if '--no-exact-progress' in sys.argv:
        _exact_progress = False
    if '--quiet' in sys.argv:
        _quiet = True 
    logger = kits.getLogger('backup', stdout=False if _quiet else True)
    if not config['backup_server']:
        logger.error('backup_server is non-existent.')
        kits.die()
    tasks = parseTasks()
    prepare(tasks)
    map(lambda t: backup(t), tasks)