Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no-drop parameter dbrestore #400

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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