aboutsummaryrefslogtreecommitdiff
path: root/rpkid/backup-sql.in
diff options
context:
space:
mode:
Diffstat (limited to 'rpkid/backup-sql.in')
-rw-r--r--rpkid/backup-sql.in56
1 files changed, 56 insertions, 0 deletions
diff --git a/rpkid/backup-sql.in b/rpkid/backup-sql.in
new file mode 100644
index 00000000..80c3d69f
--- /dev/null
+++ b/rpkid/backup-sql.in
@@ -0,0 +1,56 @@
+#!@PYTHON@
+# -*- Python -*-
+
+"""
+Back up data from SQL databases, looking at config file to figure out
+which databases and what credentials to use with them.
+
+For the moment, this just writes all the SQL to stdout.
+
+$Id$
+
+Copyright (C) 2010 Internet Systems Consortium ("ISC")
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+"""
+
+import subprocess, os, getopt, sys, time, rpki.config
+
+os.environ["TZ"] = "UTC"
+time.tzset()
+
+cfg_file = "myrpki.conf"
+
+opts, argv = getopt.getopt(sys.argv[1:], "c:h?", ["config=", "help"])
+for o, a in opts:
+ if o in ("-h", "--help", "-?"):
+ print __doc__
+ sys.exit(0)
+ elif o in ("-c", "--config"):
+ cfg_file = a
+
+cfg = rpki.config.parser(cfg_file, "myrpki")
+
+def dump(section):
+ subprocess.check_call(
+ ("mysqldump", "--add-drop-database",
+ "-u", cfg.get("sql-username", section = section),
+ "-p" + cfg.get("sql-password", section = section),
+ "-B", cfg.get("sql-database", section = section)))
+
+if cfg.getboolean("run_rpkid", False):
+ dump("irdbd")
+ dump("rpkid")
+
+if cfg.getboolean("run_pubd", False):
+ dump("pubd")