예제 #1
0
def test_find_old_backups_weekly():
    cs = CauSync(config, src, dst, task='cleanup')
    cs.config.DATE_FORMAT = "%Y%m%d"
    cs.config.BACKUPS_TO_KEEP = {
        'yearly': 10,
        'monthly': 6,
        'weekly': 4,
        'daily': 7
    }
    cs.config.BACKUP_MULTIPLIERS = {
        'yearly': 365,
        'monthly': 31,
        'weekly': 7,
        'daily': 1
    }
    cs.config.BACKUPS_LINK_DEST_COUNT = 5
    cs.curdate = datetime(year=2018, month=4, day=11)

    (dirnames_keep, dirnames_delete) = ([
        datetime(2018, 4, 9, 0, 0),
        datetime(2018, 4, 2, 0, 0)
    ], [
        datetime(2018, 1, 1, 0, 0),
        datetime(2016, 4, 11, 0, 0),
        datetime(2016, 2, 1, 0, 0),
        datetime(2007, 1, 1, 0, 0)
    ])

    assert cs.find_old_backups(dirnames,
                               'weekly') == (dirnames_keep, dirnames_delete)
예제 #2
0
def test_cleanup():
    remove_temp()

    cs = CauSync(config, src, dst, task='cleanup')
    cs.config.DATE_FORMAT = "%Y%m%d"
    cs.config.BACKUPS_TO_KEEP = {
        'yearly': 10,
        'monthly': 6,
        'weekly': 4,
        'daily': 7
    }
    cs.config.BACKUP_MULTIPLIERS = {
        'yearly': 365,
        'monthly': 31,
        'weekly': 7,
        'daily': 1
    }
    cs.config.BACKUPS_LINK_DEST_COUNT = 5
    cs.curdate = curdate

    create_temp()

    os.makedirs(dst)
    [os.makedirs(os.path.join(dst, i)) for i in dirnames]

    dirnames_delete = list(set(dirnames) - set(dirnames_keep))

    cs.run_cleanup()

    for dirname in dirnames_keep:
        isdircheck = os.path.realpath(
            os.path.join("./temp/causync_dst", dirname))
        assert_true(os.path.isdir(isdircheck))

    for dirname in dirnames_delete:
        isdircheck = os.path.realpath(
            os.path.join("./temp/causync_dst", dirname))
        assert_false(os.path.isdir(isdircheck))

    remove_temp()