Skip to content

Commit

Permalink
Merge branch 'main' into db-restore
Browse files Browse the repository at this point in the history
  • Loading branch information
copelco committed Dec 1, 2022
2 parents 580f60c + a3fbdb3 commit abd8b82
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions kubesae/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ def get_db_dump(c, db_var=DEFAULT_DB_VAR, filename=None):
Usage:
inv <ENVIRONMENT> pod.get-db-dump --db-var="<DB_VAR_NAME>"
"""
database_url = fetch_namespace_var(c, fetch_var=db_var, hide=True).stdout.strip()
if not filename:
filename = f"{c.config.namespace}_database.dump"
command = (
f"kubectl --namespace {c.config.namespace} exec -i "
f"deploy/{c.config.container_name} -- pg_dump -Fc --no-owner --clean "
f"--dbname {database_url} > {filename}"
f"deploy/{c.config.container_name} -- sh -c 'pg_dump -Fc --no-owner --clean "
f"--dbname ${db_var}' > {filename}"
)
c.run(command)

Expand All @@ -116,11 +115,10 @@ def restore_db_from_dump(c, filename, db_var=DEFAULT_DB_VAR):
Usage:
inv <ENVIRONMENT> pod.restore-db-from-dump --db-var="<DB_VAR_NAME>" --filename="<PATH/TO/DBFILE>"
"""
database_url = fetch_namespace_var(c, fetch_var=db_var, hide=True).stdout.strip()
command = (
f"kubectl --namespace {c.config.namespace} exec -i "
f"deploy/{c.config.container_name} -- "
f"pg_restore --no-privileges --no-owner --clean --if-exists --dbname {database_url} < {filename}"
f"deploy/{c.config.container_name} -- sh -c '"
f"pg_restore --no-privileges --no-owner --clean --if-exists --dbname ${db_var}' < {filename}"
)
c.run(command)

Expand Down

0 comments on commit abd8b82

Please sign in to comment.