From 1aca3fdca55e8ab0182496866af78075d17cc0d4 Mon Sep 17 00:00:00 2001 From: Emiliano Beronich Date: Wed, 20 Oct 2021 11:48:56 -0300 Subject: [PATCH 1/4] Add a parameter to configure if cleaning the database during a backup restoration. --- dbbackup/management/commands/dbrestore.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dbbackup/management/commands/dbrestore.py b/dbbackup/management/commands/dbrestore.py index 4cacfab3..469ff767 100644 --- a/dbbackup/management/commands/dbrestore.py +++ b/dbbackup/management/commands/dbrestore.py @@ -18,19 +18,23 @@ class Command(BaseDbBackupCommand): help = """Restore a database backup from storage, encrypted and/or compressed.""" content_type = 'db' + nodrop = False option_list = BaseDbBackupCommand.option_list + ( make_option("-d", "--database", help="Database to restore"), make_option("-i", "--input-filename", help="Specify filename to backup from"), make_option("-I", "--input-path", help="Specify path on local filesystem to backup from"), make_option("-s", "--servername", - help="If backup file is not specified, filter the " - "existing ones with the given servername"), + help="If backup file is not specified, filter the " + "existing ones with the given servername"), make_option("-c", "--decrypt", default=False, action='store_true', help="Decrypt data before restoring"), - make_option("-p", "--passphrase", help="Passphrase for decrypt file", default=None), + make_option("-p", "--passphrase", + help="Passphrase for decrypt file", default=None), make_option("-z", "--uncompress", action='store_true', default=False, - help="Uncompress gzip data before restoring") + help="Uncompress gzip data before restoring"), + make_option("-r", "--nodrop", action="store_true", + default=False, help="Don't clean (drop) database",) ) def handle(self, *args, **options): @@ -50,6 +54,7 @@ def handle(self, *args, **options): self.interactive = options.get('interactive') self.database_name, self.database = self._get_database(options) self.storage = get_storage() + self.nodrop = options.get("nodrop") self._restore_backup() except StorageError as err: raise CommandError(err) @@ -91,4 +96,5 @@ def _restore_backup(self): input_file.seek(0) self.connector = get_connector(self.database_name) + self.connector.drop = not self.nodrop self.connector.restore_dump(input_file) From 6fe220cb0ebab84d35dc895f0e214d2295ebd957 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:23:53 -0700 Subject: [PATCH 2/4] nodrop -> no_drop --- dbbackup/management/commands/dbrestore.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dbbackup/management/commands/dbrestore.py b/dbbackup/management/commands/dbrestore.py index 17d12963..a452c6ca 100644 --- a/dbbackup/management/commands/dbrestore.py +++ b/dbbackup/management/commands/dbrestore.py @@ -15,7 +15,7 @@ class Command(BaseDbBackupCommand): help = "Restore a database backup from storage, encrypted and/or compressed." content_type = "db" - nodrop = False + no_drop = False option_list = BaseDbBackupCommand.option_list + ( make_option("-d", "--database", help="Database to restore"), @@ -55,10 +55,10 @@ class Command(BaseDbBackupCommand): ), make_option( "-r", - "--nodrop", + "--no-drop", action="store_true", default=False, - help="Don't clean (drop) database", + help="Don't clean (drop) the database", ), ) @@ -82,7 +82,7 @@ def handle(self, *args, **options): self.input_database_name ) self.storage = get_storage() - self.nodrop = options.get("nodrop") + self.no_drop = options.get("no_drop") self.schemas = options.get("schema") self._restore_backup() except StorageError as err: @@ -138,7 +138,7 @@ def _restore_backup(self): input_file.seek(0) self.connector = get_connector(self.database_name) - self.connector.drop = not self.nodrop - self.connector.restore_dump(input_file) if self.schemas: self.connector.schemas = self.schemas + self.connector.restore_dump(input_file) + self.connector.drop = not self.no_drop From 1a5651a8240bc1be80a2e52cf283df3058886a6f Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:34:15 -0700 Subject: [PATCH 3/4] Add note that it only works with mongo/postgres --- dbbackup/management/commands/dbrestore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbbackup/management/commands/dbrestore.py b/dbbackup/management/commands/dbrestore.py index a452c6ca..ce0ad7ee 100644 --- a/dbbackup/management/commands/dbrestore.py +++ b/dbbackup/management/commands/dbrestore.py @@ -58,7 +58,7 @@ class Command(BaseDbBackupCommand): "--no-drop", action="store_true", default=False, - help="Don't clean (drop) the database", + help="Don't clean (drop) the database. This only works with mongodb and postgresql.", ), ) From f4e0e60879dcb7fd629a1ddc64404a1be302e70e Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:36:29 -0700 Subject: [PATCH 4/4] Add changelog --- docs/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 88fbda35..34724520 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,7 +4,7 @@ Changelog Unreleased ---------- -* Nothing (yet)! +* Add `--no-drop` option to `dbrestore` command to prevent dropping tables before restoring data. 4.2.0 (2024-08-22) ------------------