restore (1828B)
1 #!/bin/sh 2 3 set -eu 4 5 usage() 6 { 7 echo "Usage: BORG_PASSPHRASE=... $0 <inventory-host> <archive-name> [ansible-playbook options...]" >&2 8 } 9 10 if [ -z "${BORG_PASSPHRASE:-}" ] 11 then 12 echo "BORG_PASSPHRASE must be set." >&2 13 echo "It can be found encrypted in admin-log.git under the target host." >&2 14 exit 1 15 fi 16 17 if [ "$#" -lt 2 ] 18 then 19 usage 20 exit 1 21 fi 22 23 restore_target=$1 24 restore_archive=$2 25 shift 2 26 27 case "$restore_target" in 28 ''|*[!A-Za-z0-9._-]*) 29 echo "The target must be one exact inventory hostname." >&2 30 exit 1 31 ;; 32 esac 33 34 case "$restore_archive" in 35 latest|LATEST) 36 echo "Select an exact Borg archive; 'latest' is not accepted." >&2 37 exit 1 38 ;; 39 ''|*[!A-Za-z0-9._:+-]*) 40 echo "Invalid Borg archive name: $restore_archive" >&2 41 exit 1 42 ;; 43 esac 44 45 for restore_command in ansible-playbook borg gzip zgrep 46 do 47 if ! command -v "$restore_command" >/dev/null 2>&1 48 then 49 echo "Required command not found: $restore_command" >&2 50 exit 1 51 fi 52 done 53 54 restore_workdir=$(mktemp -d "${TMPDIR:-/tmp}/taler-database-restore.XXXXXX") 55 chmod 700 "$restore_workdir" 56 57 cleanup() 58 { 59 rm -f -- "$restore_workdir/postgres-backup.sql.gz" 60 rmdir -- "$restore_workdir" 2>/dev/null || true 61 } 62 trap cleanup EXIT 63 trap 'exit 1' HUP INT TERM 64 65 export TALER_RESTORE_TARGET="$restore_target" 66 export TALER_RESTORE_ARCHIVE="$restore_archive" 67 export TALER_RESTORE_CONTROLLER_DIRECTORY="$restore_workdir" 68 69 echo "Restoring $restore_target from exact archive $restore_archive" 70 71 ansible-playbook -v \ 72 --inventory inventories/default \ 73 --limit "$restore_target" \ 74 playbooks/restore.yml \ 75 "$@" 76 77 echo "Database restore and verification completed successfully." 78 echo "Inspect the host, then deploy the application with: ./deploy $restore_target"