From 2c34290d5d7b9ff1cfb314e5d4cadab8acd595c7 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 24 May 2018 17:45:05 -0400 Subject: bin/bakdbdr: New script --- 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 [@]:\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 "${@}" -- cgit v0.9.1