Skip to content

Commit 20d7f00

Browse files
committed
Add initial minio backup script
1 parent 4e4148a commit 20d7f00

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
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\"")
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
if [ -d "$GHE_DATA_DIR/current/minio" ] && [ "$(ls -A $GHE_DATA_DIR/current/minio)" ]; then
35+
link_dest="--link-dest=$GHE_DATA_DIR/current/minio"
36+
fi
37+
38+
# Transfer all minio data from the user data directory using rsync.
39+
ghe_verbose "* Transferring minio files from $host ..."
40+
41+
ghe-rsync -avz \
42+
-e "ghe-ssh -p $port" \
43+
--rsync-path='sudo -u minio rsync' \
44+
--exclude ".minio.sys" \
45+
$link_dest \
46+
"$host:$GHE_REMOTE_DATA_USER_DIR/minio/" \
47+
"$GHE_SNAPSHOT_DIR/minio" 1>&3
48+
49+
bm_end "$(basename $0)"

0 commit comments

Comments
 (0)