ansible-taler-exchange

Ansible playbook to deploy a production Taler Exchange
Log | Files | Refs | README | LICENSE

restore.sh (1782B)


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