diff options
author | Rob Austein <sra@hactrn.net> | 2016-02-17 20:17:55 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2016-02-17 20:17:55 +0000 |
commit | 2d907b2d0499200fa5a7f69836fb452aa373b532 (patch) | |
tree | 29c19d9970fa0f203305604c5e38b498b563431a /rp/config | |
parent | 2c91218213b78ab754f4cbebb3d8f0d03029f8c8 (diff) |
Add PostgreSQL and SQLite3 backup templates.
svn path=/branches/tk705/; revision=6267
Diffstat (limited to 'rp/config')
-rwxr-xr-x | rp/config/rpki-sql-backup | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/rp/config/rpki-sql-backup b/rp/config/rpki-sql-backup index 986e10b1..c03a3aaf 100755 --- a/rp/config/rpki-sql-backup +++ b/rp/config/rpki-sql-backup @@ -25,7 +25,6 @@ which databases and what credentials to use with them. import subprocess import os -import argparse import sys import time import rpki.config @@ -33,21 +32,23 @@ import rpki.config os.environ["TZ"] = "UTC" time.tzset() -parser = argparse.ArgumentParser(description = __doc__) -parser.add_argument("-c", "--config", - help = "override default location of configuration file") -parser.add_argument("-o", "--output", - type = argparse.FileType("wb"), default = sys.stdout, +cfg, parser = rpki.config.argparser(doc = __doc__, section = "myrpki") +parser.add_argument("-o", "--output", type = argparse.FileType("wb"), default = sys.stdout, help = "destination for SQL dump (default: stdout)") +parser.add_argument("-v", "--verbose", action = "store_true", + help = "whistle while you work") args = parser.parse_args() -cfg = rpki.config.parser(set_filename = args.config, section = "myrpki") +templates = dict(mysql = "mysqldump --add-drop-database -u{username} -p{password} -B{database}", + sqlite3 = "sqlite3 {database} .dump", + postgresql = "sudo -u {username} pg_dump {database}") for name in ("rpkid", "irdbd", "pubd"): if cfg.getboolean("start_" + name, False): - subprocess.check_call( - ("mysqldump", "--add-drop-database", - "-u", cfg.get("sql-username", section = name), - "-p" + cfg.get("sql-password", section = name), - "-B", cfg.get("sql-database", section = name)), - stdout = args.output) + cmd = templates[cfg.get("sql-engine", section = name)] + cmd = cmd.format(database = cfg.get("sql-database", section = name), + username = cfg.get("sql-username", section = name), + password = cfg.get("sql-password", section = name)) + if args.verbose: + sys.stderr.write("[Running \"{}\"]\n".format(cmd)) + subprocess.check_call(cmd.split(), stdout = args.output) |