Skip to content

Commit f9c7a72

Browse files
committed
Add minio restore script
1 parent 2c661db commit f9c7a72

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

bin/ghe-restore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
320320
echo " See https://docs.github.com/en/actions/hosting-your-own-runners/adding-self-hosted-runners for more details on how to reconfigure self-hosted Actions runners."
321321
fi
322322

323+
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'; then
324+
echo "Restoring MinIO data ..."
325+
ghe-restore-minio "$GHE_HOSTNAME" 1>&3
326+
fi
327+
323328
commands=("
324329
echo \"Restoring Redis database ...\"
325330
ghe-ssh \"$GHE_HOSTNAME\" -- 'ghe-import-redis' < \"$GHE_RESTORE_SNAPSHOT_PATH/redis.rdb\" 1>&3")
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
 (0)