Exemplo n.º 1
0
def parseTasks():
    weekday = int(time.strftime('%w'))
    if weekday == 0:
        weekday = 7
    weekday = '{:02d}'.format(weekday)
    new_tasks = []
    task_names = []
    for task in config['tasks']:
        src = task.get('src', '').strip()
        src = os.path.expanduser(src)
        name = task.get('name', '').strip('/')
        if not src or not name:
            continue
        if not os.path.exists(src):
            logger.warn('\n`{}` is non-existent.\n'.format(src))
            continue
        # 检查任务名是否有相同
        if name in task_names:
            logger.error('duplication of task name: {}'.format(task['name']))
            kits.die()
        task_names.append(name)

        dst = '{}@{}:{}'.format(config['backup_user'], config['backup_server'], os.path.join(config['backup_dst'], name, 'current'))
        backup_dir = os.path.join(config['backup_dst'], name, weekday)
        new_tasks.append({
            'src'       : src,
            'dst'       : dst,
            'bak'       : backup_dir,
            'name'      : name,
            'filter'    : task.get('filter', []),
        })
    return new_tasks
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def main():
    # 检查 smartctl 是否存在
    try:
        subprocess.check_output(['which', 'smartctl'])
    except Exception, e:
        kits.die('出错了, 没有找到 smartctl, 访问 www.smartmontools.org')