diff options
author | P. J. McDermott <pj@pehjota.net> | 2018-05-24 17:45:05 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2018-05-24 17:45:05 (EDT) |
commit | 2c34290d5d7b9ff1cfb314e5d4cadab8acd595c7 (patch) | |
tree | a4526a7b66164310b46d11ff680b28dd5adc450d /bin | |
parent | 0cd64b92465be64e1fb55acf407830a97b2d4af5 (diff) | |
download | partsdb-backup-2c34290d5d7b9ff1cfb314e5d4cadab8acd595c7.zip partsdb-backup-2c34290d5d7b9ff1cfb314e5d4cadab8acd595c7.tar.gz partsdb-backup-2c34290d5d7b9ff1cfb314e5d4cadab8acd595c7.tar.bz2 |
bin/bakdbdr: New script
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/bakdbdr | 63 |
1 files changed, 63 insertions, 0 deletions
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 "${@}" |