Skip to content

Commit

Permalink
backupdb: Allows to specify the db schema to backup.
Browse files Browse the repository at this point in the history
fixes #37
  • Loading branch information
lmignon committed Mar 24, 2019
1 parent 2187bda commit e512c53
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 16 additions & 4 deletions click_odoo_contrib/backupdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e512c53

Please sign in to comment.