commit 84bfa0cedaa706615e3e6fe6cbaee74496b2b36a parent 500a0631d45c2f0a5068b81502a788446f916291 Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Wed, 6 Feb 2019 10:17:28 +0100 Generalize backup script Diffstat:
M | links/bin/backup-b2.sh | | | 58 | ++++++++++++++++++++++++++++++++++++++++++++++++++++------ |
1 file changed, 52 insertions(+), 6 deletions(-)
diff --git a/links/bin/backup-b2.sh b/links/bin/backup-b2.sh @@ -1,10 +1,56 @@ #!/usr/bin/env bash -account="$(pass Online/backblaze.com-anders@adamsgaard.dk-account-id)" -pass="$(pass Online/backblaze.com-anders@adamsgaard.dk-master-application-key)" -export PASSPHRASE="$(pass Online/backblaze.com-anders@adamsgaard.dk-backup-pass)" + +b2_account="$(pass Online/backblaze.com-anders@adamsgaard.dk-account-id)" +b2_key="$(pass Online/backblaze.com-anders@adamsgaard.dk-master-application-key)" + +# from `gpg --list-public-keys anders@adamsgaard.dk` +enc_key="5C959DF243CE4DD17A5B2610B790F4AD1BF858FE" +sgn_key="$enc_key" + +export PASSPHRASE="$(pass gpg-anders@adamsgaard.dk)" export SIGN_PASSPHRASE="$PASSPHRASE" -duplicity --progress --use-agent $HOME b2://$account:$pass@idkfa-new-home -duplicity --progress --use-agent /usr b2://$account:$pass@idkfa-new-usr -duplicity --progress --use-agent /etc b2://$account:$pass@idkfa-new-etc + +function duplicity_b2 { + + local_dir="$1" + b2_dir="$2" + + echo "Backing up home..." + duplicity --progress \ + --sign-key $sgn_key \ + --encrypt-key $enc_key \ + --full-if-older-than 30D \ + "$local_dir" b2://"$b2_account":"$b2_key"@"$b2_dir" + + echo "Cleaning up old backups..." + duplicity --progress \ + --sign-key $sgn_key \ + --encrypt-key $enc_key \ + remove-older-than 90D \ + b2://"$b2_account":"$b2_key"@"$b2_dir" + + echo "Cleaning up failures..." + duplicity --progress \ + --sign-key $sgn_key \ + --encrypt-key $enc_key \ + cleanup --force \ + b2://"$b2_account":"$b2_key"@"$b2_dir" + + echo "B2 collection status:" + duplicity --progress \ + --sign-key $sgn_key \ + --encrypt-key $enc_key \ + collection-status \ + b2://"$b2_account":"$b2_key"@"$b2_dir" +} + +duplicity_b2 /home "$(hostname)-new-home" +duplicity_b2 /etc "$(hostname)-new-etc" +duplicity_b2 /usr "$(hostname)-new-usr" + unset PASSPHRASE unset SIGN_PASSPHRASE +unset enc_key +unset sgn_key +unset b2_account +unset b2_key