示例#1
0
        def assertLastExistingBackups(now, backup_full, backup_diff,
                                      backup_incr):
            database.point_in_time = now

            self.assertEqual(
                database.last_existing_backup(database.full),
                BackupProperties(backup_full[0], backup_full[1]))

            self.assertEqual(
                database.last_existing_backup(database.diff),
                BackupProperties(backup_diff[0], backup_diff[1]))

            self.assertEqual(
                database.last_existing_backup(database.incr),
                BackupProperties(backup_incr[0], backup_incr[1]))
示例#2
0
    def test_find_last_existing_backup(self):

        def assertLastExistingBackups(now, backup_full, backup_diff,
                                      backup_incr):
            database.point_in_time = now

            self.assertEqual(
                database.last_existing_backup(database.full),
                BackupProperties(backup_full[0], backup_full[1]))

            self.assertEqual(
                database.last_existing_backup(database.diff),
                BackupProperties(backup_diff[0], backup_diff[1]))

            self.assertEqual(
                database.last_existing_backup(database.incr),
                BackupProperties(backup_incr[0], backup_incr[1]))


        database = lalikan.database.BackupDatabase(
            self.settings, 'Test1')
        backup_directory = database.backup_directory

        try:
            assert not os.path.exists(backup_directory)
            os.makedirs(backup_directory)

            # valid (but faked) backups
            faked_backups = (
                ('2012-01-02_0201', 'full'),
                ('2012-01-03_2000', 'incr'),
                ('2012-01-04_2134', 'incr'),
                ('2012-01-05_2034', 'diff'),
                ('2012-01-05_2134', 'incr'),
            )

            self.__simulate_backups(database, backup_directory, faked_backups)

            database.point_in_time = datetime.datetime(
                year=2012, month=1, day=2,
                hour=2, minute=0)

            self.assertEqual(
                database.last_existing_backup(database.full),
                BackupProperties(None, database.full))

            self.assertEqual(
                database.last_existing_backup(database.diff),
                BackupProperties(None, database.diff))

            self.assertEqual(
                database.last_existing_backup(database.incr),
                BackupProperties(None, database.incr))


            assertLastExistingBackups(
                now=datetime.datetime(year=2012, month=1, day=2,
                                      hour=2, minute=1),
                backup_full=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full),
                backup_diff=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full),
                backup_incr=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full))


            assertLastExistingBackups(
                now=datetime.datetime(year=2012, month=1, day=3,
                                      hour=20, minute=1),
                backup_full=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full),
                backup_diff=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full),
                backup_incr=(datetime.datetime(2012,  1,  3, 20,  0),
                             database.incr))


            assertLastExistingBackups(
                now=datetime.datetime(year=2012, month=1, day=5,
                                      hour=6, minute=37),
                backup_full=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full),
                backup_diff=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full),
                backup_incr=(datetime.datetime(2012,  1,  4, 21, 34),
                             database.incr))


            assertLastExistingBackups(
                now=datetime.datetime(year=2012, month=1, day=5,
                                      hour=20, minute=35),
                backup_full=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full),
                backup_diff=(datetime.datetime(2012,  1,  5, 20, 34),
                             database.diff),
                backup_incr=(datetime.datetime(2012,  1,  5, 20, 34),
                             database.diff))


            assertLastExistingBackups(
                now=datetime.datetime(year=2012, month=1, day=5,
                                      hour=22, minute=14),
                backup_full=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full),
                backup_diff=(datetime.datetime(2012,  1,  5, 20, 34),
                             database.diff),
                backup_incr=(datetime.datetime(2012,  1,  5, 21, 34),
                             database.incr))


            assertLastExistingBackups(
                now=datetime.datetime(year=2099, month=12, day=31,
                                      hour=23, minute=59),
                backup_full=(datetime.datetime(2012,  1,  2,  2,  1),
                             database.full),
                backup_diff=(datetime.datetime(2012,  1,  5, 20, 34),
                             database.diff),
                backup_incr=(datetime.datetime(2012,  1,  5, 21, 34),
                             database.incr))

        finally:
            shutil.rmtree(backup_directory)