Skip to content

Commit 63a6401

Browse files
authored
Merge pull request #209 from github/mckern/minio
minio backup support
2 parents da2d082 + 4ed84ce commit 63a6401

File tree

6 files changed

+161
-2
lines changed

6 files changed

+161
-2
lines changed

bin/ghe-backup

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
190190
ghe-backup-actions 1>&3 || failures="$failures actions"
191191
fi
192192

193+
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'; then
194+
echo "Backing up Minio data ..."
195+
ghe-backup-minio 1>&3 || failures="$failures minio"
196+
fi
197+
193198
commands=("
194199
echo \"Backing up Redis database ...\"
195200
ghe-backup-redis > redis.rdb || printf %s \"redis \" >> \"$failures_file\"")

bin/ghe-restore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
336336
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."
337337
fi
338338

339+
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'; then
340+
echo "Restoring MinIO data ..."
341+
ghe-restore-minio "$GHE_HOSTNAME" 1>&3
342+
fi
343+
339344
commands=("
340345
echo \"Restoring Redis database ...\"
341346
ghe-ssh \"$GHE_HOSTNAME\" -- 'ghe-import-redis' < \"$GHE_RESTORE_SNAPSHOT_PATH/redis.rdb\" 1>&3")
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-backup-minio
3+
#/ Take an online, incremental snapshot of all minio data
4+
#/
5+
#/ Note: This command typically isn't called directly. It's invoked by
6+
#/ ghe-backup.
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+
bm_start "$(basename "${0}")"
14+
15+
# Set up remote host and root backup snapshot directory based on config
16+
port="$(ssh_port_part "${GHE_HOSTNAME}")"
17+
host="$(ssh_host_part "${GHE_HOSTNAME}")"
18+
backup_dir="${GHE_SNAPSHOT_DIR}/minio"
19+
20+
# Verify rsync is available.
21+
if ! command -v rsync 1> /dev/null 2>&1; then
22+
echo "Error: rsync not found." 1>&2
23+
exit 1
24+
fi
25+
26+
# Perform a host-check and establish GHE_REMOTE_XXX variables.
27+
ghe_remote_version_required "${host}"
28+
29+
# Make sure root backup dir exists if this is the first run
30+
mkdir -p "${backup_dir}"
31+
32+
# If we have a previous increment and it is not empty, avoid transferring existing files via rsync's
33+
# --link-dest support. This also decreases physical space usage considerably.
34+
# Hilariously, this HAS to stay unquoted when you call `rsync` further
35+
# down because when the shell interpolates this out, `rsync` will throw
36+
# an absolute fit if this variable is quoted. Surprise!
37+
if [[ -d "${GHE_DATA_DIR}/current/minio" ]] &&
38+
[[ "$(ls -A "${GHE_DATA_DIR}/current/minio")" ]]; then
39+
link_dest="--link-dest=${GHE_DATA_DIR}/current/minio"
40+
fi
41+
42+
# Transfer all minio data from the user data directory using rsync.
43+
ghe_verbose "* Transferring minio files from ${host} ..."
44+
45+
ghe-rsync \
46+
--archive \
47+
--verbose \
48+
--compress \
49+
--rsh="ghe-ssh -p ${port}" \
50+
--rsync-path='sudo -u minio rsync' \
51+
--exclude=".minio.sys" \
52+
${link_dest} \
53+
"${host}:${GHE_REMOTE_DATA_USER_DIR}/minio/" \
54+
"${GHE_SNAPSHOT_DIR}/minio" 1>&3
55+
56+
bm_end "$(basename "${0}")"
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}")"

test/test-ghe-backup.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,16 @@ begin_test "ghe-backup has default cadence configured"
356356
(
357357
set -e
358358
enable_actions
359-
359+
360360
[ -n "$GHE_MSSQL_BACKUP_CADENCE" ]
361361
)
362362
end_test
363363

364364
# Override backup cadence for testing purposes
365365
GHE_MSSQL_BACKUP_CADENCE=10,5,1
366366
export GHE_MSSQL_BACKUP_CADENCE
367-
setup_actions_test_data $GHE_REMOTE_DATA_USER_DIR
367+
setup_actions_test_data "$GHE_REMOTE_DATA_USER_DIR"
368+
setup_minio_test_data "$GHE_REMOTE_DATA_USER_DIR"
368369

369370
begin_test "ghe-backup takes full backup on first run"
370371
(
@@ -373,6 +374,7 @@ begin_test "ghe-backup takes full backup on first run"
373374
# setup_mssql_backup_file uses "current"
374375
set -e
375376
enable_actions
377+
enable_minio
376378

377379
rm -rf "$GHE_REMOTE_DATA_USER_DIR"/mssql/backups/*
378380
rm -rf "$GHE_DATA_DIR"/current/mssql/*
@@ -386,6 +388,7 @@ begin_test "ghe-backup takes full backup upon expiration"
386388
(
387389
set -e
388390
enable_actions
391+
enable_minio
389392
export REMOTE_DBS="full_mssql"
390393

391394
setup_mssql_backup_file "full_mssql" 11 "bak"
@@ -400,6 +403,7 @@ begin_test "ghe-backup takes diff backup upon expiration"
400403
(
401404
set -e
402405
enable_actions
406+
enable_minio
403407
export REMOTE_DBS="full_mssql"
404408

405409
setup_mssql_backup_file "full_mssql" 7 "bak"

test/testlib.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ setup_test_data () {
319319
echo "rsync" > "$loc/strategy"
320320
echo "$GHE_REMOTE_VERSION" > "$loc/version"
321321
fi
322+
323+
setup_minio_test_data "$GHE_DATA_DIR"
322324
}
323325

324326
setup_actions_test_data() {
@@ -350,6 +352,23 @@ cleanup_actions_test_data() {
350352
rm -rf "$loc/actions"
351353
}
352354

355+
setup_minio_test_data() {
356+
local loc=$1
357+
358+
mkdir -p "$loc/minio/"
359+
cd "$loc/minio/"
360+
bucket="packages"
361+
362+
mkdir -p "$bucket"
363+
echo "an example blob" "$bucket/91dfa09f-1801-4e00-95ee-6b763d7da3e2"
364+
}
365+
366+
cleanup_minio_test_data() {
367+
local loc=$1
368+
369+
rm -rf "$loc/minio"
370+
}
371+
353372
# A unified method to check everything backed up or restored during testing.
354373
# Everything tested here should pass regardless of whether we're testing a backup
355374
# or a restore.
@@ -374,6 +393,11 @@ verify_common_data() {
374393
diff -ru "$GHE_REMOTE_DATA_USER_DIR/mssql/backups" "$GHE_DATA_DIR/current/mssql"
375394
fi
376395

396+
if is_minio_enabled; then
397+
# verify minio object storge backups were transferred
398+
diff -ru "$GHE_REMOTE_DATA_USER_DIR/minio" "$GHE_DATA_DIR/minio"
399+
fi
400+
377401
# tests that differ for cluster and single node backups and restores
378402
if [ "$(cat $GHE_DATA_DIR/current/strategy)" = "rsync" ]; then
379403
# verify the UUID was transferred
@@ -528,6 +552,14 @@ is_actions_enabled() {
528552
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'
529553
}
530554

555+
enable_minio() {
556+
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config app.minio.enabled true'
557+
}
558+
559+
is_minio_enabled() {
560+
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'
561+
}
562+
531563
setup_moreutils_parallel() {
532564
# CI servers may have moreutils parallel and GNU parallel installed.
533565
# We need moreutils parallel

0 commit comments

Comments
 (0)