diff options
author | Rob Austein <sra@hactrn.net> | 2016-02-18 00:31:00 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2016-02-18 00:31:00 +0000 |
commit | 7146bb6e3dc7137df87b79124f93ad59c6f5a24b (patch) | |
tree | 5132f0428edaa5654423d3d3bee02d3a8f239386 /rp/config | |
parent | 2d907b2d0499200fa5a7f69836fb452aa373b532 (diff) |
Dedupe to avoid backing up the same database more than once.
svn path=/branches/tk705/; revision=6268
Diffstat (limited to 'rp/config')
-rwxr-xr-x | rp/config/rpki-sql-backup | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/rp/config/rpki-sql-backup b/rp/config/rpki-sql-backup index c03a3aaf..097ad0d7 100755 --- a/rp/config/rpki-sql-backup +++ b/rp/config/rpki-sql-backup @@ -20,13 +20,16 @@ """ Back up data from SQL databases, looking at config file to figure out -which databases and what credentials to use with them. +which databases and what credentials to use with them, and eliminating +duplicates in cases where we've configured multiple applications to +share a single database. """ -import subprocess import os import sys import time +import argparse +import subprocess import rpki.config os.environ["TZ"] = "UTC" @@ -43,12 +46,18 @@ templates = dict(mysql = "mysqldump --add-drop-database -u{username} -p{pas sqlite3 = "sqlite3 {database} .dump", postgresql = "sudo -u {username} pg_dump {database}") +cmds = [] + for name in ("rpkid", "irdbd", "pubd"): if cfg.getboolean("start_" + name, False): 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) + if cmd not in cmds: + cmds.append(cmd) + +for cmd in cmds: + if args.verbose: + sys.stderr.write("[Running \"{}\"]\n".format(cmd)) + subprocess.check_call(cmd.split(), stdout = args.output) |