def setUp(self): self.command = DbbackupCommand() self.command.database = TEST_DATABASE['NAME'] self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.storage = FakeStorage() self.command.clean = True self.command.clean_keep = 1 self.command.stdout = DEV_NULL
def setUp(self): self.command = DbbackupCommand() self.command.database = TEST_DATABASE['NAME'] self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.storage = FakeStorage() self.command.stdout = DEV_NULL self.command.filename = None self.command.path = None
def setUp(self): if six.PY3: self.skipTest("Compression isn't implemented in Python3") open(TEST_DATABASE['NAME'], 'a+b').close() self.command = DbbackupCommand() self.command.database = TEST_DATABASE['NAME'] self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.storage = FakeStorage() self.command.stdout = DEV_NULL
def setUp(self): open(TEST_DATABASE['NAME'], 'a+b').close() self.command = DbbackupCommand() self.command.servername = 'foo-server' self.command.encrypt = False self.command.compress = False self.command.database = TEST_DATABASE['NAME'] self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.storage = FakeStorage() self.command.stdout = DEV_NULL open(TEST_DATABASE['NAME']).close()
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.filepath = 'foofile' self.command.database = TEST_DATABASE self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.passphrase = None self.command.storage = FakeStorage()
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.filepath = 'foofile' self.command.database = TEST_DATABASE self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.passphrase = None self.command.storage = FakeStorage() cmd = ('gpg --import %s' % GPG_PRIVATE_PATH).split() subprocess.call(cmd, stdout=DEV_NULL, stderr=DEV_NULL)
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.dbcommands = DBCommands(TEST_DATABASE) self.command.passphrase = None self.command.interactive = True self.command.storage = FakeStorage() HANDLED_FILES.clean() add_private_gpg()
def handle(self, **options): """ Django command handler. """ try: connection.close() self.filepath = options.get('filepath') self.backup_extension = options.get('backup_extension') or 'backup' self.servername = options.get('servername') self.decrypt = options.get('decrypt') self.uncompress = options.get('uncompress') self.passphrase = options.get('passphrase') self.database = self._get_database(options) self.storage = BaseStorage.storage_factory() self.dbcommands = DBCommands(self.database) if options.get('list'): return self.list_backups() self.restore_backup() except StorageError as err: raise CommandError(err)
def handle(self, **options): """ Django command handler. """ try: self.clean = options.get('clean') self.clean_keep = getattr(settings, 'DBBACKUP_CLEANUP_KEEP', 10) self.database = options.get('database') self.servername = options.get('servername') self.compress = options.get('compress') self.encrypt = options.get('encrypt') self.storage = BaseStorage.storage_factory() if self.database: database_keys = self.database, else: database_keys = dbbackup_settings.DATABASES for database_key in database_keys: database = settings.DATABASES[database_key] self.dbcommands = DBCommands(database) self.save_new_backup(database, database_key) self.cleanup_old_backups(database) except StorageError as err: raise CommandError(err)
def restore_db(self): database = settings.DATABASES['default'] self.dbcommands = DBCommands(database) filepath = os.path.join(self.directory, 'dbbackup') with open(filepath, 'r') as inputfile: self.dbcommands.run_restore_commands(inputfile)
def backup_db(self): database = settings.DATABASES['default'] self.dbcommands = DBCommands(database) with open(os.path.join(self.directory, 'dbbackup'), 'w') as outputfile: self.dbcommands.run_backup_commands(outputfile)