Skip to content

Commit fdc52f8

Browse files
rubiojrsnh
authored andcommitted
Use the rsync backup strategy to backup all ha configurations
1 parent 9d57819 commit fdc52f8

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

bin/ghe-backup

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,33 +85,13 @@ echo "Starting backup of $GHE_HOSTNAME in snapshot $GHE_SNAPSHOT_TIMESTAMP"
8585
ghe_remote_version_required
8686
echo "$GHE_REMOTE_VERSION" > version
8787

88-
# Figure out if we're restoring into cluster
89-
cluster=false
90-
if ghe-ssh "$GHE_HOSTNAME" -- \
91-
"[ -f '$GHE_REMOTE_ROOT_DIR/etc/github/cluster' ]"; then
92-
cluster=true
93-
fi
94-
9588
# Log backup start message in /var/log/syslog on remote instance
9689
ghe_remote_logger "Starting backup from $(hostname) in snapshot $GHE_SNAPSHOT_TIMESTAMP ..."
9790

98-
# Determine whether to use the rsync or tarball backup strategy based on the
99-
# remote appliance version. The tarball strategy must be used with GitHub
100-
# Enterprise versions prior to 11.10.340 since rsync is not available.
101-
# The tarball strategy may be forced for newer versions by setting
102-
# GHE_BACKUP_STRATEGY=tarball in backup.config but this is not recommended.
103-
: ${GHE_BACKUP_STRATEGY:=rsync}
104-
if [ $GHE_VERSION_MAJOR -eq 1 -a $GHE_VERSION_PATCH -lt 340 ]; then
105-
GHE_BACKUP_STRATEGY="tarball"
106-
fi
107-
108-
if $cluster; then
109-
GHE_BACKUP_STRATEGY="cluster"
110-
fi
91+
export GHE_BACKUP_STRATEGY=${GHE_BACKUP_STRATEGY:-$(ghe-backup-strategy)}
11192

11293
# Record the strategy with the snapshot so we will know how to restore.
11394
echo "$GHE_BACKUP_STRATEGY" > strategy
114-
export GHE_BACKUP_STRATEGY
11595

11696
# If we're using the tarball backup strategy, put the appliance in maintenance
11797
# mode and wait for all writing processes to bleed out.
@@ -150,7 +130,7 @@ failures="$failures mysql"
150130
bm_end "ghe-export-mysql"
151131

152132
echo "Backing up Redis database ..."
153-
if $cluster; then
133+
if [ "$GHE_BACKUP_STRATEGY" = "cluster" ]; then
154134
ghe-backup-redis-cluster > redis.rdb ||
155135
failures="$failures redis"
156136
else
@@ -187,7 +167,7 @@ ghe-backup-pages-${GHE_BACKUP_STRATEGY} ||
187167
failures="$failures pages"
188168

189169
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
190-
if $cluster; then
170+
if [ "$GHE_BACKUP_STRATEGY" = "cluster" ]; then
191171
echo "Backing up asset attachments ..."
192172
ghe-backup-alambic-cluster ||
193173
failures="$failures alambic_assets"
@@ -216,7 +196,7 @@ if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
216196
fi
217197
fi
218198

219-
if ! $cluster; then
199+
if [ "$GHE_BACKUP_STRATEGY" != "cluster" ]; then
220200
echo "Backing up Elasticsearch indices ..."
221201
ghe-backup-es-${GHE_BACKUP_STRATEGY} ||
222202
failures="$failures elasticsearch"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-backup-strategy
3+
#/
4+
#/ Determine the backup strategy that will be used.
5+
#/
6+
#/ The tarball strategy must be used with GitHub Enterprise versions prior to
7+
#/ 11.10.340 since rsync is not available.
8+
#/
9+
#/ The rsync strategy should be used for single VMs and all HA configurations.
10+
#/
11+
#/ The cluster strategy should be used to backup GHE clusters.
12+
set -e
13+
14+
# Bring in the backup configuration
15+
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config
16+
17+
if [ $GHE_VERSION_MAJOR -eq 1 -a $GHE_VERSION_PATCH -lt 340 ]; then
18+
echo "tarball"
19+
elif ghe-ssh "$GHE_HOSTNAME" -- \
20+
"[ -f '$GHE_REMOTE_ROOT_DIR/etc/github/repl-state' ]"; then
21+
echo "rsync"
22+
elif ghe-ssh "$GHE_HOSTNAME" -- \
23+
"[ -f '$GHE_REMOTE_ROOT_DIR/etc/github/cluster' ]"; then
24+
echo "cluster"
25+
else
26+
echo "rsync"
27+
fi

0 commit comments

Comments
 (0)