summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore.d/partsdb-backup1
-rwxr-xr-xbin/bakdbdr63
2 files changed, 64 insertions, 0 deletions
diff --git a/.gitignore.d/partsdb-backup b/.gitignore.d/partsdb-backup
index 7ab1392..4eb0e2c 100644
--- a/.gitignore.d/partsdb-backup
+++ b/.gitignore.d/partsdb-backup
@@ -6,6 +6,7 @@
!/.gitignore.d/partsdb-backup
!/bin/
!/bin/bakdb
+!/bin/bakdbdr
# Exclude swap and backup files
*.s[a-w]?
diff --git a/bin/bakdbdr b/bin/bakdbdr
new file mode 100755
index 0000000..4ece6fa
--- /dev/null
+++ b/bin/bakdbdr
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+set -eu
+
+backup()
+{
+ local db_file="${1}"
+ shift 1
+ local bk_file=
+
+ bk_file="${db_file}.$(TZ=UTC date '+%Y%m%dT%H%M%SZ')"
+
+ bakdb "${db_file}" "${bk_file}"
+
+ printf '%s.xz' "${bk_file}"
+ return 0
+}
+
+remote_copy()
+{
+ local bk_file="${1}"
+ local remote="${2}"
+ shift 1
+
+ rsync -a "${bk_file}" "${remote}"
+
+ return 0
+}
+
+usage()
+{
+ printf 'Usage: %s <database-file> [<user>@]<host>:<dest>\n' "${0}"
+
+ return 0
+}
+
+main()
+{
+ local db_file=
+ local remote=
+
+ if [ ${#} -ne 2 ]; then
+ usage 1>&2
+ return 1
+ fi
+ db_file="${1}"
+ remote="${2}"
+ shift 2
+
+ case "${remote}" in
+ ?*':'*) ;;
+ *)
+ usage 1>&2
+ return 1
+ ;;
+ esac
+
+ remote_copy "$(backup "${db_file}")" "${remote}"
+
+ return 0
+}
+
+main "${@}"