Skip to content

Commit

Permalink
Add support for exclude tables data in the command interface (#375)
Browse files Browse the repository at this point in the history
Sometimes we have some tables in the database that are generated automatically and we don't want to backup the data of these tables if the process take a lot of time, instead we'll generate them again automatically.

Co-authored-by: Mohamed KESSOUM <[email protected]>
  • Loading branch information
KessoumML and Mohamed KESSOUM authored Nov 24, 2020
1 parent ac01065 commit f38626e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ filename. ::
Specify filename on storage
-O OUTPUT_PATH, --output-path=OUTPUT_PATH
Specify where to store on local filesystem
-x EXCLUDE_TABLES, --exclude-tables=EXCLUDE_TABLES
Exclude tables data from backup (-x 'public.table1, public.table2')

dbrestore
---------
Expand Down
7 changes: 6 additions & 1 deletion dbbackup/management/commands/dbbackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class Command(BaseDbBackupCommand):
make_option("-o", "--output-filename", default=None,
help="Specify filename on storage"),
make_option("-O", "--output-path", default=None,
help="Specify where to store on local filesystem")
help="Specify where to store on local filesystem"),
make_option("-x", "--exclude-tables", default=None,
help="Exclude tables from backup")
)

@utils.email_uncaught_exception
Expand All @@ -49,13 +51,16 @@ def handle(self, **options):

self.filename = options.get('output_filename')
self.path = options.get('output_path')
self.exclude_tables = options.get("exclude_tables")
self.storage = get_storage()

self.database = options.get('database') or ''
database_keys = self.database.split(',') or settings.DATABASES

for database_key in database_keys:
self.connector = get_connector(database_key)
if self.connector and self.exclude_tables:
self.connector.exclude.extend(list(self.exclude_tables.replace(" ", "").split(',')))
database = self.connector.settings
try:
self._save_new_backup(database)
Expand Down

0 comments on commit f38626e

Please sign in to comment.