From e512c5339291cc399623cdd5d045c546e61ab221 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Sun, 24 Mar 2019 09:31:56 +0100 Subject: [PATCH] backupdb: Allows to specify the db schema to backup. fixes #37 --- CHANGES.rst | 5 +++++ README.rst | 3 +++ click_odoo_contrib/backupdb.py | 20 ++++++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1cebe84..b08d9dd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,11 @@ Changes ~~~~~~~ +Unreleased +---------- +- click-odoo-backupdb: Allows to specify the db schema to backup. + + 1.5.0 (2019-02-05) ------------------ - add click-odoo-backupdb diff --git a/README.rst b/README.rst index 1f95dab..ba9d42d 100644 --- a/README.rst +++ b/README.rst @@ -128,6 +128,9 @@ click-odoo-backupdb (beta) exists. [default: False] --if-exists Don't report error if database does not exist. --format [zip|folder] Expected dump format [default: zip] + -s, --schema TEXT Dump only schemas matching schema. Multiple schemas + can be selected by writing multiple -s switches + [default: public] --help Show this message and exit. diff --git a/click_odoo_contrib/backupdb.py b/click_odoo_contrib/backupdb.py index f3385ed..ddc9232 100644 --- a/click_odoo_contrib/backupdb.py +++ b/click_odoo_contrib/backupdb.py @@ -16,8 +16,11 @@ from ._dbutils import db_exists -def _dump_db(dbname, backup): - cmd = ["pg_dump", "--no-owner", dbname] +def _dump_db(dbname, schemas, backup): + cmd = ["pg_dump", "--no-owner"] + for schema in schemas: + cmd.extend(["-n", schema]) + cmd.append(dbname) filename = "dump.sql" if backup.format == "folder": cmd.insert(-1, "--format=c") @@ -60,9 +63,18 @@ def _backup_filestore(dbname, backup): show_default=True, help="Expected dump format", ) +@click.option( + "--schema", + "-s", + default=["public"], + multiple=True, + show_default=True, + help="Dump only schemas matching schema. Multiple schemas can be selected " + "by writing multiple -s switches", +) @click.argument("dbname", nargs=1) @click.argument("dest", nargs=1, required=1) -def main(env, dbname, dest, force, if_exists, format): +def main(env, dbname, dest, force, if_exists, format, schema): """ Create an Odoo database backup from an existing one. This script dumps the database using pg_dump. @@ -103,7 +115,7 @@ def main(env, dbname, dest, force, if_exists, format): with backup(format, dest, "w") as _backup, db.cursor() as cr: _create_manifest(cr, dbname, _backup) _backup_filestore(dbname, _backup) - _dump_db(dbname, _backup) + _dump_db(dbname, schema, _backup) finally: odoo.sql_db.close_db(dbname)