@@ -10,76 +10,13 @@ set -e
1010cd $( 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-
1613# Perform a host-check and establish GHE_REMOTE_XXX variables.
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.
37- # XXX This should be fixed on the appliance side but will need to be maintained
38- # for versions up to at least 11.10.343.
39- echo " * Retrieving elasticsearch.yml config file ..." 1>&3
40- ghe-ssh " $host " -- " sudo grep -F '' '$GHE_REMOTE_DATA_USER_DIR /elasticsearch/elasticsearch.yml'" \
41- > " $GHE_SNAPSHOT_DIR /elasticsearch/elasticsearch.yml"
42- chmod 0600 " $GHE_SNAPSHOT_DIR /elasticsearch/elasticsearch.yml"
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"
14+ ghe_remote_version_required " $GHE_HOSTNAME "
15+
16+ # Determine which version of ES we're backing up based on appliance version and
17+ # run the appropriate command.
18+ if [ " $GHE_VERSION_MAJOR " -eq 1 ]; then
19+ exec ghe-backup-es-v0.9-rsync " $@ "
20+ else
21+ exec ghe-backup-es-v1.x-rsync " $@ "
4822fi
49-
50- # Transfer ES indices from a GitHub instance to the current snapshot
51- # directory, using a previous snapshot to avoid transferring files that have
52- # already been transferred.
53- echo " * Performing initial sync of ES indices ..." 1>&3
54- ghe-rsync -avz \
55- -e " ghe-ssh -p $( ssh_port_part " $host " ) " \
56- --rsync-path=' sudo -u git rsync' \
57- $link_dest \
58- --exclude=' elasticsearch.yml' \
59- " $( ssh_host_part " $host " ) :$GHE_REMOTE_DATA_USER_DIR /elasticsearch/" \
60- " $GHE_SNAPSHOT_DIR /elasticsearch" 1>&3
61-
62- # Set up a trap to re-enable flushing on exit
63- cleanup () {
64- echo " * Enabling ES index flushing ..." 1>&3
65- echo ' {"index":{"translog.disable_flush":false}}' |
66- ghe-ssh " $host " -- curl -s -XPUT " localhost:9200/_settings" -d @- > /dev/null
67- }
68- trap ' cleanup' EXIT
69- trap ' exit $?' INT # ^C always terminate
70-
71- # Disable ES flushing and force a flush right now
72- echo " * Disabling ES index flushing ..." 1>&3
73- echo ' {"index":{"translog.disable_flush":true}}' |
74- ghe-ssh " $host " -- curl -s -XPUT " localhost:9200/_settings" -d @- > /dev/null
75- ghe-ssh " $host " -- curl -s -XPOST " localhost:9200/_flush" > /dev/null
76-
77- # Transfer all ES indices again
78- echo " * Performing follow-up sync of ES indices ..." 1>&3
79- ghe-rsync -avz \
80- -e " ghe-ssh -p $( ssh_port_part " $host " ) " \
81- --rsync-path=' sudo -u git rsync' \
82- $link_dest \
83- --exclude=' elasticsearch.yml' \
84- " $( ssh_host_part " $host " ) :$GHE_REMOTE_DATA_USER_DIR /elasticsearch/" \
85- " $GHE_SNAPSHOT_DIR /elasticsearch" 1>&3
0 commit comments