Skip to content

Commit cb32614

Browse files
committed
Merge backup-utils-internal/master into backup-utils
2 parents 1efb09d + 0f5c0d7 commit cb32614

File tree

8 files changed

+118
-189
lines changed

8 files changed

+118
-189
lines changed

README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ This repository includes backup and recovery utilities for [GitHub Enterprise][1
55

66
- **[Features](#features)**
77
- **[Requirements](#requirements)**
8-
- **[Backup host](#backup-host)**
9-
- **[Storage](#storage)**
10-
- **[GitHub Enterprise version](#github-enterprise-version)**
8+
- **[Backup host requirements](#backup-host-requirements)**
9+
- **[Storage requirements](#storage-requirements)**
10+
- **[GitHub Enterprise version requirements](#github-enterprise-version-requirements)**
1111
- **[Getting started](#getting-started)**
1212
- **[Using the backup and restore commands](#using-the-backup-and-restore-commands)**
1313
- **[Scheduling backups](#scheduling-backups)**
@@ -20,8 +20,6 @@ The backup utilities implement a number of advanced capabilities for backup
2020
hosts, built on top of the backup and restore features already included in
2121
GitHub Enterprise.
2222

23-
These advanced features include:
24-
2523
- Complete GitHub Enterprise backup and recovery system via two simple utilities:<br>
2624
`ghe-backup` and `ghe-restore`.
2725
- Online backups. The GitHub appliance need not be put in maintenance mode for
@@ -42,31 +40,30 @@ These advanced features include:
4240
The backup utilities should be run on a host dedicated to long-term permanent
4341
storage and must have network connectivity with the GitHub Enterprise appliance.
4442

45-
##### Backup host
43+
##### Backup host requirements
4644

4745
Backup host software requirements are modest: Linux or other modern Unix
4846
operating system with [rsync][4] v2.6.4 or newer.
4947

5048
The backup host must be able to establish network connections outbound to the
5149
GitHub appliance over SSH (port 22).
5250

53-
##### Storage
51+
##### Storage requirements
5452

5553
Storage requirements vary based on current Git repository disk usage and growth
5654
patterns of the GitHub appliance. We recommend allocating at least 5x the amount
5755
of storage allocated to the primary GitHub appliance for historical snapshots
5856
and growth over time.
5957

60-
##### GitHub Enterprise version
58+
##### GitHub Enterprise version requirements
6159

6260
For online and incremental backup support, the GitHub Enterprise instance must
6361
be running version 11.10.342 or above.
6462

65-
Earlier versions are supported by the backup utilities, but online and
66-
incremental backups are not supported. We strongly recommend upgrading to the
67-
latest release if you're running a version prior to 11.10.342. Visit
68-
https://enterprise.github.com to [download the most recent GitHub Enterprise
69-
version][5].
63+
Earlier versions are supported, but online and incremental backups are not
64+
supported. We strongly recommend upgrading to the latest release if you're
65+
running a version prior to 11.10.342. Visit [enterprise.github.com][5] to
66+
download the most recent GitHub Enterprise version.
7067

7168
### Getting started
7269

@@ -98,8 +95,7 @@ After the initial backup, use the following commands:
9895
along with full snapshots of all other pertinent data stores.
9996
- The `ghe-restore` command restores snapshots to the same or separate GitHub
10097
Enterprise appliance. If you are restoring to a separate appliance, follow
101-
the steps in
102-
[Migrating GitHub Enterprise](https://enterprise.github.com/help/articles/migrating-github-enterprise).
98+
the steps in [Migrating GitHub Enterprise][10].
10399

104100
##### Example backup and restore usage
105101

@@ -233,3 +229,4 @@ site setup or recovery, please contact our [Enterprise support team][7] instead.
233229
[7]: https://enterprise.github.com/support/
234230
[8]: https://enterprise.github.com/help/articles/backing-up-enterprise-data
235231
[9]: https://enterprise.github.com/help/articles/restoring-enterprise-data
232+
[10]: https://enterprise.github.com/help/articles/migrating-github-enterprise

libexec/ghe-backup-es-rsync

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,87 @@ set -e
1010
cd $(dirname "$0")/..
1111
. libexec/ghe-backup-config
1212

13+
# Set up remote host and root elastic backup directory based on config
14+
host="$GHE_HOSTNAME"
15+
1316
# Perform a host-check and establish GHE_REMOTE_XXX variables.
14-
ghe_remote_version_required "$GHE_HOSTNAME"
17+
ghe_remote_version_required "$host"
18+
19+
# Verify rsync is available.
20+
if ! rsync --version 1>/dev/null 2>&1; then
21+
echo "Error: rsync not found." 1>&2
22+
exit 1
23+
fi
24+
25+
# Make sure root backup dir exists if this is the first run
26+
mkdir -p "$GHE_SNAPSHOT_DIR/elasticsearch"
27+
28+
# Verify that the /data/elasticsearch directory exists.
29+
if ! ghe-ssh "$host" -- "[ -d '$GHE_REMOTE_DATA_USER_DIR/elasticsearch' ]"; then
30+
echo "* The '$GHE_REMOTE_DATA_USER_DIR/elasticsearch' directory doesn't exist." 1>&3
31+
exit 0
32+
fi
33+
34+
# Grab the elasticsearch.yml file which is root owned and mode -rw------- so
35+
# can't be read via rsync or cat. We use the root allowed grep -F as a cat
36+
# replacement. This is necessary on v11.10.x appliances only.
37+
if [ "$GHE_VERSION_MAJOR" -lt 2 ]; then
38+
echo "* Retrieving elasticsearch.yml config file ..." 1>&3
39+
ghe-ssh "$host" -- "sudo grep -F '' '$GHE_REMOTE_DATA_USER_DIR/elasticsearch/elasticsearch.yml'" \
40+
> "$GHE_SNAPSHOT_DIR/elasticsearch/elasticsearch.yml"
41+
chmod 0600 "$GHE_SNAPSHOT_DIR/elasticsearch/elasticsearch.yml"
42+
fi
43+
44+
# If we have a previous increment, avoid transferring existing files via rsync's
45+
# --link-dest support. This also decreases physical space usage considerably.
46+
if [ -d "$GHE_DATA_DIR/current/elasticsearch" ]; then
47+
link_dest="--link-dest=../../current/elasticsearch"
48+
fi
1549

16-
# Determine which version of ES we're backing up based on appliance version and
17-
# run the appropriate command.
50+
# Determine which user to run the rsync operation under. This is the git user on
51+
# v11.10.34x appliances and the elasticsearch user under >= v2.x appliances.
1852
if [ "$GHE_VERSION_MAJOR" -eq 1 ]; then
19-
exec ghe-backup-es-v0.9-rsync "$@"
53+
rsync_user=git
54+
elif [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
55+
rsync_user=elasticsearch
2056
else
21-
exec ghe-backup-es-v1.x-rsync "$@"
57+
echo "Error: invalid remote version: $GHE_REMOTE_VERSION" 1>&2
58+
exit 1
2259
fi
60+
61+
# Transfer ES indices from a GitHub instance to the current snapshot
62+
# directory, using a previous snapshot to avoid transferring files that have
63+
# already been transferred.
64+
echo "* Performing initial sync of ES indices ..." 1>&3
65+
ghe-rsync -avz \
66+
-e "ghe-ssh -p $(ssh_port_part "$host")" \
67+
--rsync-path="sudo -u $rsync_user rsync" \
68+
$link_dest \
69+
--exclude='elasticsearch.yml' \
70+
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch/" \
71+
"$GHE_SNAPSHOT_DIR/elasticsearch" 1>&3
72+
73+
# Set up a trap to re-enable flushing on exit
74+
cleanup () {
75+
echo "* Enabling ES index flushing ..." 1>&3
76+
echo '{"index":{"translog.disable_flush":false}}' |
77+
ghe-ssh "$host" -- curl -s -XPUT "localhost:9200/_settings" -d @- >/dev/null
78+
}
79+
trap 'cleanup' EXIT
80+
trap 'exit $?' INT # ^C always terminate
81+
82+
# Disable ES flushing and force a flush right now
83+
echo "* Disabling ES index flushing ..." 1>&3
84+
echo '{"index":{"translog.disable_flush":true}}' |
85+
ghe-ssh "$host" -- curl -s -XPUT "localhost:9200/_settings" -d @- >/dev/null
86+
ghe-ssh "$host" -- curl -s -XPOST "localhost:9200/_flush" >/dev/null
87+
88+
# Transfer all ES indices again
89+
echo "* Performing follow-up sync of ES indices ..." 1>&3
90+
ghe-rsync -avz \
91+
-e "ghe-ssh -p $(ssh_port_part "$host")" \
92+
--rsync-path="sudo -u $rsync_user rsync" \
93+
$link_dest \
94+
--exclude='elasticsearch.yml' \
95+
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch/" \
96+
"$GHE_SNAPSHOT_DIR/elasticsearch" 1>&3

libexec/ghe-backup-es-v0.9-rsync

Lines changed: 0 additions & 86 deletions
This file was deleted.

libexec/ghe-backup-es-v1.x-rsync

Lines changed: 0 additions & 49 deletions
This file was deleted.

libexec/ghe-restore-es-rsync

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,25 @@ if [ ! -d "$snapshot_dir/elasticsearch" ]; then
3333

3434
# restoring v11.10.x ES snapshot into a v2.0 appliance
3535
elif [ "$GHE_VERSION_MAJOR" -gt 1 -a -f "$snapshot_dir/elasticsearch/elasticsearch.yml" ]; then
36-
cd "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/elasticsearch"
3736
ghe-ssh "$host" -- "sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR/elasticsearch-legacy'" 1>&3
38-
tar -cf - . |
39-
ghe-ssh "$host" -- "sudo tar --no-same-owner -xf - -C '$GHE_REMOTE_DATA_USER_DIR/elasticsearch-legacy'" 1>&3
37+
ghe-ssh "$host" -- "sudo chown elasticsearch:elasticsearch '$GHE_REMOTE_DATA_USER_DIR/elasticsearch-legacy'" 1>&3
38+
39+
ghe-rsync -avz --delete \
40+
-e "ghe-ssh -p $(ssh_port_part "$host")" \
41+
--rsync-path="sudo -u elasticsearch rsync" \
42+
"$snapshot_dir/elasticsearch/" \
43+
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch-legacy" 1>&3
4044

4145
# restoring v2.0 ES snapshot into a v2.0 appliance
4246
elif [ "$GHE_VERSION_MAJOR" -gt 1 ]; then
43-
ghe-ssh "$host" -- "sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR/elasticsearch-snapshots'" 1>&3
44-
ghe-ssh "$host" -- "sudo chown elasticsearch:elasticsearch '$GHE_REMOTE_DATA_USER_DIR/elasticsearch-snapshots'" 1>&3
47+
ghe-ssh "$host" -- "sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR/elasticsearch-restore'" 1>&3
48+
ghe-ssh "$host" -- "sudo chown elasticsearch:elasticsearch '$GHE_REMOTE_DATA_USER_DIR/elasticsearch-restore'" 1>&3
4549

4650
ghe-rsync -avz --delete \
4751
-e "ghe-ssh -p $(ssh_port_part "$host")" \
4852
--rsync-path="sudo -u elasticsearch rsync" \
4953
"$snapshot_dir/elasticsearch/" \
50-
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch-snapshots" 1>&3
51-
52-
ghe-ssh "$host" -- "ghe-es-restore"
54+
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch-restore" 1>&3
5355

5456
# restoring v11.10.x ES snapshot into a v11.10.x appliance
5557
else

test/bin/chown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# Fake chown command for tests. Avoids needing to creating special users for
3+
# utlities that chown on the remote side.
4+
true

0 commit comments

Comments
 (0)