commit 4d48d910bf321a94d06950ce5b5f87bf223d92b6 parent 5496fadad74f106e94eb2b83a0d3d7b98033bc90 Author: dwrz <dwrz@dwrz.net> Date: Sun, 24 Dec 2023 15:18:36 +0000 Update backup script Diffstat:
M | scripts/backup | | | 64 | +++++++++++++++++++++++++++++++++++++++++++++++----------------- |
1 file changed, 47 insertions(+), 17 deletions(-)
diff --git a/scripts/backup b/scripts/backup @@ -1,8 +1,8 @@ #!/usr/bin/env bash readonly TARGETS=( - "$HOME/.config/gnupg/" - "$HOME/.config/pass/" + "${HOME}/.config/gnupg/" + "${HOME}/.config/pass/" ) readonly HOSTS=( @@ -30,37 +30,61 @@ backup-hosts() { done } -main() { - # Backup to B2. +backup-b2() { local id bucket key bucket="$(pass backblaze/bucket)" id="$(pass backblaze/duplicity/keyID)" key="$(pass backblaze/duplicity/applicationKey)" - # Config - env "B2_APPLICATION_KEY_ID"="${id}" "B2_APPLICATION_KEY"="${key}" \ + if ! env "B2_APPLICATION_KEY_ID"="${id}" "B2_APPLICATION_KEY"="${key}" \ b2 sync --delete --excludeDirRegex="Signal" \ - "${HOME}/.config/" "b2://${bucket}/${HOSTNAME}/config" - if [[ "$?" -ne 0 ]]; then - err "$0: failed b2 sync config" + "${HOME}/.config/" "b2://${bucket}/${HOSTNAME}/config"; + then + err "$0: failed b2 'config' sync" fi # Org - env "B2_APPLICATION_KEY_ID"="${id}" "B2_APPLICATION_KEY"="${key}" \ + if ! env "B2_APPLICATION_KEY_ID"="${id}" "B2_APPLICATION_KEY"="${key}" \ b2 sync --delete --excludeDirRegex="email" \ - "${HOME}/org/" "b2://${bucket}/${HOSTNAME}/org" - if [[ "$?" -ne 0 ]]; then - err "$0: failed b2 sync org" + "${HOME}/org/" "b2://${bucket}/${HOSTNAME}/org"; + then + err "$0: failed b2 'org' sync" fi # Projects - env "B2_APPLICATION_KEY_ID"="${id}" "B2_APPLICATION_KEY"="${key}" \ - b2 sync --delete "${HOME}/projects/" "b2://${bucket}/${HOSTNAME}/projects" - if [[ "$?" -ne 0 ]]; then - err "$0: failed b2 sync projects" + if ! env "B2_APPLICATION_KEY_ID"="${id}" "B2_APPLICATION_KEY"="${key}" \ + b2 sync --delete "${HOME}/projects/" \ + "b2://${bucket}/${HOSTNAME}/projects"; + then + err "$0: failed b2 'projects' sync" + fi +} + +backup-srv() { + if ! rsync --archive --delete --progress --verbose "${HOME}/archive/" \ + "${USER}@srv":"${HOME}/archive/"; + then + err "$0: failed srv 'archive' sync" + fi + if ! rsync --archive --delete --progress --verbose "${HOME}/journal/" \ + "${USER}@srv":"${HOME}/journal/"; + then + err "$0: failed srv 'journal' sync" fi + if ! rsync --archive --delete --progress --verbose "${HOME}/org/" \ + "${USER}@srv":"${HOME}/org/"; + then + err "$0: failed srv 'org' sync" + fi + if ! rsync --archive --delete --progress --verbose "${HOME}/projects/" \ + "${USER}@srv":"${HOME}/projects/"; + then + err "$0: failed srv 'projects' sync" + fi +} +main() { # Backup targets. for target in "${TARGETS[@]}"; do if [[ ! -e "${target}" ]]; then @@ -70,6 +94,12 @@ main() { backup-hosts "${target}" done + + # Backup srv. + backup-srv + + # Backup B2. + backup-b2 } main "$@"