|
| 1 | +#!/usr/bin/env bash |
| 2 | +#/ Usage: ghe-restore-minio <host> |
| 3 | +#/ Restore additional minio files from an rsync snapshot. |
| 4 | +#/ |
| 5 | +#/ Note: This script typically isn't called directly. It's invoked by the |
| 6 | +#/ ghe-restore command. |
| 7 | +set -e |
| 8 | + |
| 9 | +# Bring in the backup configuration |
| 10 | +# shellcheck source=share/github-backup-utils/ghe-backup-config |
| 11 | +. "$(dirname "${BASH_SOURCE[0]}")/ghe-backup-config" |
| 12 | + |
| 13 | +# Show usage and bail with no arguments |
| 14 | +[[ -z ${*} ]] && print_usage |
| 15 | + |
| 16 | +bm_start "$(basename "${0}")" |
| 17 | + |
| 18 | +# Grab host arg |
| 19 | +GHE_HOSTNAME="${1}" |
| 20 | + |
| 21 | +# The snapshot to restore should be set by the ghe-restore command but this lets |
| 22 | +# us run this script directly. |
| 23 | +: "${GHE_RESTORE_SNAPSHOT:=current}" |
| 24 | + |
| 25 | +# Path to snapshot dir we're restoring from |
| 26 | +GHE_RESTORE_SNAPSHOT_PATH="${GHE_DATA_DIR}/${GHE_RESTORE_SNAPSHOT}" |
| 27 | + |
| 28 | +port="$(ssh_port_part "${GHE_HOSTNAME}")" |
| 29 | +host="$(ssh_host_part "${GHE_HOSTNAME}")" |
| 30 | + |
| 31 | +# No need to restore anything, early exit |
| 32 | +if [ ! -d "${GHE_RESTORE_SNAPSHOT_PATH}/minio" ]; then |
| 33 | + echo "Warning: minio backup missing. Skipping ..." |
| 34 | + exit 0 |
| 35 | +fi |
| 36 | + |
| 37 | +# Perform a host-check and establish GHE_REMOTE_XXX variables. |
| 38 | +ghe_remote_version_required "${host}" |
| 39 | + |
| 40 | +# Transfer all minio data from the snapshot to the user data directory using rsync. |
| 41 | +ghe_verbose "* Transferring minio files to ${host} ..." |
| 42 | + |
| 43 | +ghe-ssh -p "${port}" "${host}" -- sudo mkdir -p "${GHE_REMOTE_DATA_USER_DIR}/minio" |
| 44 | +ghe-ssh -p "${port}" "${host}" -- sudo chown -R minio:minio "${GHE_REMOTE_DATA_USER_DIR}/minio" |
| 45 | + |
| 46 | +ghe-rsync \ |
| 47 | + --verbose \ |
| 48 | + --archive \ |
| 49 | + --hard-links \ |
| 50 | + --relative \ |
| 51 | + --delete \ |
| 52 | + --rsh="ghe-ssh -p ${port}" \ |
| 53 | + --rsync-path='sudo -u minio rsync' \ |
| 54 | + "${GHE_RESTORE_SNAPSHOT_PATH}/minio/./" \ |
| 55 | + "${host}:${GHE_REMOTE_DATA_USER_DIR}/minio/" 1>&3 |
| 56 | + |
| 57 | +bm_end "$(basename "${0}")" |
0 commit comments