Example #1
0
 def setUp(self):
     self.storage = get_storage()
     HANDLED_FILES['written_files'] = [(f, None) for f in [
         '2015-02-06-042810.bak',
         '2015-02-07-042810.bak',
         '2015-02-08-042810.bak',
     ]]
Example #2
0
 def setUp(self):
     HANDLED_FILES.clean()
     self.storage = get_storage()
     # foodb files
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'foodb'), None) for ext in
         ('db', 'db.gz', 'db.gpg', 'db.gz.gpg')
     ]
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'hamdb', 'fooserver'), None) for ext in
         ('db', 'db.gz', 'db.gpg', 'db.gz.gpg')
     ]
     # Media file
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, None, None, 'media'), None) for ext in
         ('tar', 'tar.gz', 'tar.gpg', 'tar.gz.gpg')
     ]
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'bardb', 'barserver'), None) for ext in
         ('db', 'db.gz', 'db.gpg', 'db.gz.gpg')
     ]
     # barserver files
     HANDLED_FILES['written_files'] += [
         ('file_without_date', None)
     ]
Example #3
0
 def setUp(self):
     self.storage = get_storage()
     HANDLED_FILES['written_files'] = [(f, None) for f in [
         '2015-02-06-042810.bak',
         '2015-02-07-042810.bak',
         '2015-02-08-042810.bak',
     ]]
 def setUp(self):
     HANDLED_FILES.clean()
     self.storage = get_storage()
     # foodb files
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'foodb'), None) for ext in
         ('db', 'db.gz', 'db.gpg', 'db.gz.gpg')
     ]
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'hamdb', 'fooserver'), None) for ext in
         ('db', 'db.gz', 'db.gpg', 'db.gz.gpg')
     ]
     # Media file
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, None, None, 'media'), None) for ext in
         ('tar', 'tar.gz', 'tar.gpg', 'tar.gz.gpg')
     ]
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'bardb', 'barserver'), None) for ext in
         ('db', 'db.gz', 'db.gpg', 'db.gz.gpg')
     ]
     # barserver files
     HANDLED_FILES['written_files'] += [
         ('file_without_date', None)
     ]
 def setUp(self):
     self.command = ListbackupsCommand()
     self.command.storage = get_storage()
     HANDLED_FILES['written_files'] = [(f, None) for f in [
         '2015-02-06-042810.bak',
         '2015-02-07-042810.bak',
         '2015-02-08-042810.bak',
     ]]
 def setUp(self):
     self.command = ListbackupsCommand()
     self.command.storage = get_storage()
     HANDLED_FILES['written_files'] = [(f, None) for f in [
         '2015-02-06-042810.bak',
         '2015-02-07-042810.bak',
         '2015-02-08-042810.bak',
     ]]
 def setUp(self):
     self.command = DbbackupCommand()
     self.command.servername = 'foo-server'
     self.command.encrypt = False
     self.command.compress = False
     self.command.storage = get_storage()
     self.command.stdout = DEV_NULL
     self.command.filename = None
     self.command.path = None
     self.command.connector = get_connector('default')
 def setUp(self):
     HANDLED_FILES.clean()
     self.command = DbbackupCommand()
     self.command.servername = 'foo-server'
     self.command.storage = get_storage()
     self.command.stdout = DEV_NULL
     self.command.compress = False
     self.command.encrypt = False
     self.command.path = None
     self.command.media_storage = get_storage_class()()
Example #9
0
 def setUp(self):
     self.command = DbbackupCommand()
     self.command.servername = 'foo-server'
     self.command.encrypt = False
     self.command.compress = False
     self.command.storage = get_storage()
     self.command.stdout = DEV_NULL
     self.command.filename = None
     self.command.path = None
     self.command.connector = get_connector('default')
 def setUp(self):
     HANDLED_FILES.clean()
     self.command = DbbackupCommand()
     self.command.servername = 'foo-server'
     self.command.storage = get_storage()
     self.command.stdout = DEV_NULL
     self.command.compress = False
     self.command.encrypt = False
     self.command.path = None
     self.command.media_storage = get_storage_class()()
 def setUp(self):
     self.command = DbbackupCommand()
     self.command.servername = 'foo-server'
     self.command.encrypt = False
     self.command.compress = False
     self.command.database = TEST_DATABASE['NAME']
     self.command.storage = get_storage()
     self.command.connector = get_connector()
     self.command.stdout = DEV_NULL
     self.command.filename = None
     self.command.path = None
Example #12
0
 def setUp(self):
     self.command = DbbackupCommand()
     self.command.servername = 'foo-server'
     self.command.encrypt = False
     self.command.compress = False
     self.command.database = TEST_DATABASE['NAME']
     self.command.storage = get_storage()
     self.command.connector = get_connector()
     self.command.stdout = DEV_NULL
     self.command.filename = None
     self.command.path = None
 def setUp(self):
     HANDLED_FILES.clean()
     self.storage = get_storage()
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'foo'), None)
         for ext in ('db', 'db.gz', 'db.gpg', 'db.gz.gpg')
     ]
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'foo', None, 'media'), None)
         for ext in ('tar', 'tar.gz', 'tar.gpg', 'tar.gz.gpg')
     ]
     HANDLED_FILES['written_files'] += [('file_without_date', None)]
Example #14
0
 def setUp(self):
     self.command = DbrestoreCommand()
     self.command.stdout = DEV_NULL
     self.command.uncompress = False
     self.command.decrypt = False
     self.command.backup_extension = 'bak'
     self.command.filename = 'foofile'
     self.command.database = TEST_DATABASE
     self.command.passphrase = None
     self.command.interactive = True
     self.command.storage = get_storage()
     self.command.connector = get_connector()
     HANDLED_FILES.clean()
 def setUp(self):
     self.command = DbrestoreCommand()
     self.command.stdout = DEV_NULL
     self.command.uncompress = False
     self.command.decrypt = False
     self.command.backup_extension = 'bak'
     self.command.filename = 'foofile'
     self.command.database = TEST_DATABASE
     self.command.passphrase = None
     self.command.interactive = True
     self.command.storage = get_storage()
     self.command.connector = get_connector()
     HANDLED_FILES.clean()
 def setUp(self):
     HANDLED_FILES.clean()
     self.storage = get_storage()
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'foo'), None) for ext in
         ('db', 'db.gz', 'db.gpg', 'db.gz.gpg')
     ]
     HANDLED_FILES['written_files'] += [
         (utils.filename_generate(ext, 'foo', None, 'media'), None) for ext in
         ('tar', 'tar.gz', 'tar.gpg', 'tar.gz.gpg')
     ]
     HANDLED_FILES['written_files'] += [
         ('file_without_date', None)
     ]
 def setUp(self):
     self.command = DbrestoreCommand()
     self.command.stdout = DEV_NULL
     self.command.uncompress = False
     self.command.decrypt = False
     self.command.backup_extension = 'bak'
     self.command.path = None
     self.command.filename = 'foofile'
     self.command.database = TEST_MONGODB
     self.command.passphrase = None
     self.command.interactive = True
     self.command.storage = get_storage()
     self.command.connector = MongoDumpConnector()
     HANDLED_FILES.clean()
     add_private_gpg()
Example #18
0
 def setUp(self):
     self.command = DbrestoreCommand()
     self.command.stdout = DEV_NULL
     self.command.uncompress = False
     self.command.decrypt = False
     self.command.backup_extension = 'bak'
     self.command.path = None
     self.command.filename = 'foofile'
     self.command.database = TEST_MONGODB
     self.command.passphrase = None
     self.command.interactive = True
     self.command.storage = get_storage()
     self.command.connector = MongoDumpConnector()
     HANDLED_FILES.clean()
     add_private_gpg()
Example #19
0
    def check_status(self):
        storage = get_storage()
        backups = storage.list_backups(content_type=self.content_type)
        if not storage.storage.exists(""):
            self.add_error(_("The backup folder doesn't exist."))
            return
        if backups:
            last_backup = backups[:1]
            last_backup_time = dbbackup_utils.filename_to_date(last_backup[0])
            time_gone_since_backup = datetime.now() - last_backup_time

            # Check if backup is older than configured time
            if time_gone_since_backup.seconds > self.configured_seconds:
                self.add_error(_(f"Last backup {time_gone_since_backup}!"))
        else:
            self.add_error(_("No backup found!"))
Example #20
0
 def setUp(self):
     HANDLED_FILES.clean()
     self.command = BaseDbBackupCommand()
     self.command.stdout = DEV_NULL
     self.command.encrypt = False
     self.command.compress = False
     self.command.servername = 'foo-server'
     self.command.storage = get_storage()
     HANDLED_FILES['written_files'] = [(f, None) for f in [
         '2015-02-06-042810.tar',
         '2015-02-07-042810.tar',
         '2015-02-08-042810.tar',
         'foodb-2015-02-06-042810.dump',
         'foodb-2015-02-07-042810.dump',
         'foodb-2015-02-08-042810.dump',
     ]]
Example #21
0
 def setUp(self):
     HANDLED_FILES.clean()
     self.command = BaseDbBackupCommand()
     self.command.stdout = DEV_NULL
     self.command.encrypt = False
     self.command.compress = False
     self.command.servername = 'foo-server'
     self.command.storage = get_storage()
     HANDLED_FILES['written_files'] = [(f, None) for f in [
         '2015-02-06-042810.tar',
         '2015-02-07-042810.tar',
         '2015-02-08-042810.tar',
         'foodb-2015-02-06-042810.dump',
         'foodb-2015-02-07-042810.dump',
         'foodb-2015-02-08-042810.dump',
     ]]
Example #22
0
    def handle(self, restore, migrate_options, *args, **options):
        hashes = []
        for app_config in apps.get_app_configs():
            migrations_dir = self._migrations_dir(app_config)
            if migrations_dir and os.path.exists(migrations_dir):
                for migration in glob.glob(os.path.join(
                        migrations_dir, "*.py")):
                    if os.path.basename(migration) == "__init__.py":
                        continue
                    hashes.append(self._hash(migration))

        bam_id = (
            "bam-" +
            hashlib.md5("".join(sorted(hashes)).encode("utf-8")).hexdigest())

        storage = get_storage()
        has_backup = bam_id in storage.list_directory()

        if restore:
            if has_backup:
                call_command("reset_db")
                call_command("migrate")
                call_command("dbrestore", "-i", bam_id)
            else:
                print("No backup for the current set of migrations exists")
        else:
            if has_backup:
                if query_yes_no(
                        "A backup (%s) for the current set of migrations" %
                        bam_id + " already exists, continue?"):
                    storage.delete_file(bam_id)
                else:
                    return

            call_command("migrate", *migrate_options)
            call_command("dbbackup", "-o", bam_id)
Example #23
0
 def test_set_options(self, *args):
     storage = get_storage(options=STORAGE_OPTIONS)
     self.assertEqual(storage.storage.__module__, 'django.core.files.storage')
Example #24
0
 def test_set_path(self):
     fake_storage_path = 'dbbackup.tests.utils.FakeStorage'
     storage = get_storage(fake_storage_path)
     self.assertIsInstance(storage.storage, FakeStorage)
Example #25
0
 def test_func(self, *args):
     self.assertIsInstance(get_storage(), Storage)
Example #26
0
 def test_func(self, *args):
     self.assertIsInstance(get_storage(), Storage)
Example #27
0
 def test_set_path(self):
     fake_storage_path = 'dbbackup.tests.utils.FakeStorage'
     storage = get_storage(fake_storage_path)
     self.assertIsInstance(storage.storage, FakeStorage)
Example #28
0
 def test_set_options(self, *args):
     storage = get_storage(options=STORAGE_OPTIONS)
     self.assertEqual(storage.storage.__module__,
                      'django.core.files.storage')
Example #29
0
 def setUp(self):
     HANDLED_FILES.clean()
     self.command = BaseDbBackupCommand()
     self.command.storage = get_storage()