File tree Expand file tree Collapse file tree 6 files changed +79
-17
lines changed
share/github-backup-utils Expand file tree Collapse file tree 6 files changed +79
-17
lines changed Original file line number Diff line number Diff line change @@ -261,9 +261,7 @@ if [ -s "$GHE_RESTORE_SNAPSHOT_PATH/uuid" ] && ! $CLUSTER; then
261
261
fi
262
262
263
263
echo " Restoring MySQL database ..."
264
- bm_start " ghe-import-mysql"
265
- gzip -dc " $GHE_RESTORE_SNAPSHOT_PATH /mysql.sql.gz" | ghe-ssh " $GHE_HOSTNAME " -- ' ghe-import-mysql'
266
- bm_end " ghe-import-mysql"
264
+ ghe-restore-mysql " $GHE_HOSTNAME " 1>&3
267
265
268
266
echo " Restoring Redis database ..."
269
267
bm_start " ghe-import-redis"
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ for index in $indices; do
48
48
ln $GHE_DATA_DIR /current/audit-log/$index_name .gz $GHE_SNAPSHOT_DIR /audit-log/$index_name .gz
49
49
ln $GHE_DATA_DIR /current/audit-log/$index_name .gz.size $GHE_SNAPSHOT_DIR /audit-log/$index_name .gz.size
50
50
else
51
- ghe-ssh " $host " " /usr/local/share/enterprise/ghe-es-dump-json \" http://localhost:9201/$index_name \" " | gzip > $GHE_SNAPSHOT_DIR /audit-log/$index_name .gz
51
+ echo " /usr/local/share/enterprise/ghe-es-dump-json \" http://localhost:9201/$index_name \" | gzip" | ghe-ssh " $host " -- /bin/bash > $GHE_SNAPSHOT_DIR /audit-log/$index_name .gz
52
52
echo $index_size > $GHE_SNAPSHOT_DIR /audit-log/$index_name .gz.size
53
53
fi
54
54
done
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ for index in $indices; do
41
41
ln $GHE_DATA_DIR /current/hookshot/$index_name .gz $GHE_SNAPSHOT_DIR /hookshot/$index_name .gz
42
42
ln $GHE_DATA_DIR /current/hookshot/$index_name .gz.size $GHE_SNAPSHOT_DIR /hookshot/$index_name .gz.size
43
43
else
44
- ghe-ssh " $host " " /usr/local/share/enterprise/ghe-es-dump-json \" http://localhost:9201/$index_name \" " | gzip > $GHE_SNAPSHOT_DIR /hookshot/$index_name .gz
44
+ echo " /usr/local/share/enterprise/ghe-es-dump-json \" http://localhost:9201/$index_name \" | gzip" | ghe-ssh " $host " -- /bin/bash > $GHE_SNAPSHOT_DIR /hookshot/$index_name .gz
45
45
echo $index_size > $GHE_SNAPSHOT_DIR /hookshot/$index_name .gz.size
46
46
fi
47
47
done
Original file line number Diff line number Diff line change 43
43
# Only restore indices that don't exist and the last two months' indices.
44
44
for index in $indices ; do
45
45
if ! ghe-ssh " $GHE_HOSTNAME " " curl -f -s -XGET http://localhost:9201/$index > /dev/null" || [[ $index =~ $last_month ]] || [[ $index =~ $current_month ]]; then
46
- if $CLUSTER || [ -n " $configured " ]; then
47
- ghe_verbose " * Restoring $index "
48
- gzip -dc $GHE_DATA_DIR /$GHE_RESTORE_SNAPSHOT /audit-log/$index .gz | ghe-ssh " $GHE_HOSTNAME " " /usr/local/share/enterprise/ghe-es-load-json 'http://localhost:9201/$index '" 1>&3
49
- else
50
- echo " $index .gz" >> $tmp_list
51
- fi
46
+ echo " $index .gz" >> $tmp_list
52
47
fi
53
48
done
54
49
55
50
if [ -s " $tmp_list " ]; then
51
+ ghe-ssh " $GHE_HOSTNAME " -- " sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore'" 1>&3
52
+ ghe-ssh " $GHE_HOSTNAME " -- " sudo chown elasticsearch:elasticsearch '$GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore'" 1>&3
53
+
56
54
ghe-rsync -avz --delete \
57
55
-e " ghe-ssh -p $( ssh_port_part " $GHE_HOSTNAME " ) " \
58
56
--rsync-path=" sudo -u elasticsearch rsync" \
59
57
--files-from=$tmp_list \
60
58
" $GHE_DATA_DIR /$GHE_RESTORE_SNAPSHOT /audit-log/" \
61
59
" $( ssh_host_part " $GHE_HOSTNAME " ) :$GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore/" 1>&3
60
+
61
+ if $CLUSTER || [ -n " $configured " ]; then
62
+ for index in $( cat $tmp_list | sed ' s/\.gz$//g' ) ; do
63
+ ghe_verbose " * Restoring $index "
64
+ echo " export PATH=\$ PATH:/usr/local/share/enterprise && gzip -dc $GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore/$index | ghe-es-load-json 'http://localhost:9201/$index '" |
65
+ ghe-ssh " $GHE_HOSTNAME " -- /bin/bash 1>&3
66
+ done
67
+
68
+ ghe-ssh " $GHE_HOSTNAME " -- " sudo rm $GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore/*.gz" 1>&3
69
+ fi
70
+
62
71
rm $tmp_list
63
72
fi
73
+
64
74
bm_end " $( basename $0 ) "
Original file line number Diff line number Diff line change 30
30
31
31
for index in $indices ; do
32
32
if [ -z " $last_index " ] || ! [ $index \< $last_index ]; then
33
- if $CLUSTER || [ -n " $configured " ]; then
34
- ghe_verbose " * Restoring $index "
35
- gzip -dc $GHE_DATA_DIR /$GHE_RESTORE_SNAPSHOT /hookshot/$index .gz | ghe-ssh " $GHE_HOSTNAME " " /usr/local/share/enterprise/ghe-es-load-json 'http://localhost:9201/$index '" 1>&3
36
- else
37
- echo " $index .gz" >> $tmp_list
38
- fi
33
+ echo " $index .gz" >> $tmp_list
39
34
fi
40
35
done
41
36
42
37
if [ -s " $tmp_list " ]; then
38
+ ghe-ssh " $GHE_HOSTNAME " -- " sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore'" 1>&3
39
+ ghe-ssh " $GHE_HOSTNAME " -- " sudo chown elasticsearch:elasticsearch '$GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore'" 1>&3
40
+
43
41
ghe-rsync -avz --delete \
44
42
-e " ghe-ssh -p $( ssh_port_part " $GHE_HOSTNAME " ) " \
45
43
--rsync-path=" sudo -u elasticsearch rsync" \
46
44
--files-from=$tmp_list \
47
45
" $GHE_DATA_DIR /$GHE_RESTORE_SNAPSHOT /hookshot/" \
48
46
" $( ssh_host_part " $GHE_HOSTNAME " ) :$GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore/" 1>&3
47
+
48
+ if $CLUSTER || [ -n " $configured " ]; then
49
+ for index in $( cat $tmp_list | sed ' s/\.gz$//g' ) ; do
50
+ ghe_verbose " * Restoring $index "
51
+ echo " export PATH=\$ PATH:/usr/local/share/enterprise && gzip -dc $GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore/$index | ghe-es-load-json 'http://localhost:9201/$index '" |
52
+ ghe-ssh " $GHE_HOSTNAME " -- /bin/bash 1>&3
53
+ done
54
+
55
+ ghe-ssh " $GHE_HOSTNAME " -- " sudo rm $GHE_REMOTE_DATA_USER_DIR /elasticsearch-restore/*.gz" 1>&3
56
+ fi
57
+
49
58
rm $tmp_list
50
59
fi
51
60
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ # / Usage: ghe-restore-mysql <host>
3
+ # / Restore MySQL backup to a GitHub instance.
4
+ # /
5
+ # / Note: This script typically isn't called directly. It's invoked by the
6
+ # / ghe-restore command when the rsync strategy is used.
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
+ # Show usage and bail with no arguments
14
+ [ -z " $* " ] && print_usage
15
+
16
+ bm_start " $( basename $0 ) "
17
+
18
+ # Grab host arg
19
+ GHE_HOSTNAME=" $1 "
20
+
21
+ # Perform a host-check and establish the remote version in GHE_REMOTE_VERSION.
22
+ ghe_remote_version_required " $GHE_HOSTNAME "
23
+
24
+ # The snapshot to restore should be set by the ghe-restore command but this lets
25
+ # us run this script directly.
26
+ : ${GHE_RESTORE_SNAPSHOT:= current}
27
+
28
+ # The directory holding the snapshot to restore
29
+ snapshot_dir=" $GHE_DATA_DIR /$GHE_RESTORE_SNAPSHOT "
30
+
31
+ cleanup () {
32
+ ghe-ssh " $GHE_HOSTNAME " -- " sudo rm -rf $GHE_REMOTE_DATA_USER_DIR /tmp/mysql.sql.gz"
33
+ }
34
+ trap ' cleanup' INT TERM EXIT
35
+
36
+ ghe-ssh " $GHE_HOSTNAME " -- " sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR /tmp'" 1>&3
37
+
38
+ # Transfer MySQL data from the snapshot to the GitHub instance.
39
+ cat $snapshot_dir /mysql.sql.gz | ghe-ssh " $GHE_HOSTNAME " -- " sudo dd of=$GHE_REMOTE_DATA_USER_DIR /tmp/mysql.sql.gz >/dev/null 2>&1"
40
+
41
+ # Import the database
42
+ echo " gunzip -cd $GHE_REMOTE_DATA_USER_DIR /tmp/mysql.sql.gz | ghe-import-mysql" | ghe-ssh " $GHE_HOSTNAME " -- /bin/bash 1>&3
43
+
44
+
45
+ bm_end " $( basename $0 ) "
You can’t perform that action at this time.
0 commit comments