Skip to content

Commit

Permalink
Add no-drop parameter dbrestore (#400)
Browse files Browse the repository at this point in the history
Co-authored-by: Emiliano Beronich <[email protected]>
Co-authored-by: Mark <[email protected]>
  • Loading branch information
3 people authored Aug 23, 2024
1 parent 103c756 commit 163bd9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions dbbackup/management/commands/dbrestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class Command(BaseDbBackupCommand):
help = "Restore a database backup from storage, encrypted and/or compressed."
content_type = "db"
no_drop = False

option_list = BaseDbBackupCommand.option_list + (
make_option("-d", "--database", help="Database to restore"),
Expand Down Expand Up @@ -52,6 +53,13 @@ class Command(BaseDbBackupCommand):
default=[],
help="Specify schema(s) to restore. Can be used multiple times.",
),
make_option(
"-r",
"--no-drop",
action="store_true",
default=False,
help="Don't clean (drop) the database. This only works with mongodb and postgresql.",
),
)

def handle(self, *args, **options):
Expand All @@ -74,6 +82,7 @@ def handle(self, *args, **options):
self.input_database_name
)
self.storage = get_storage()
self.no_drop = options.get("no_drop")
self.schemas = options.get("schema")
self._restore_backup()
except StorageError as err:
Expand Down Expand Up @@ -129,8 +138,7 @@ def _restore_backup(self):

input_file.seek(0)
self.connector = get_connector(self.database_name)

if self.schemas:
self.connector.schemas = self.schemas

self.connector.restore_dump(input_file)
self.connector.drop = not self.no_drop
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down

0 comments on commit 163bd9e

Please sign in to comment.