|
| 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