13
13
#
14
14
# . $( dirname "${BASH_SOURCE[0]}" )/../share/github-backup-utils/ghe-backup-config
15
15
#
16
-
16
+ set +o posix
17
17
# Assume this script lives in share/github-backup-utils/ when setting the root
18
- GHE_BACKUP_ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /../.." && pwd ) "
18
+ GHE_BACKUP_ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /../.." && pwd) "
19
19
20
20
# Get the version from the version file.
21
- BACKUP_UTILS_VERSION=" $( cat $GHE_BACKUP_ROOT /share/github-backup-utils/version) "
21
+ BACKUP_UTILS_VERSION=" $( cat " $GHE_BACKUP_ROOT /share/github-backup-utils/version" ) "
22
22
23
23
# If a version check was requested, show the current version and exit
24
24
if [ -n " $GHE_SHOW_VERSION " ]; then
28
28
29
29
# Check for "--help|-h" in args or GHE_SHOW_HELP=true and show usage
30
30
# shellcheck disable=SC2120 # the script name is always referenced
31
- print_usage () {
31
+ print_usage () {
32
32
grep ' ^#/' < " $0 " | cut -c 4-
33
- exit ${1:- 1}
33
+ exit " ${1:- 1} "
34
34
}
35
35
36
36
if [ -n " $GHE_SHOW_HELP " ]; then
46
46
# Add the bin and share/github-backup-utils dirs to PATH
47
47
PATH=" $GHE_BACKUP_ROOT /bin:$GHE_BACKUP_ROOT /share/github-backup-utils:$PATH "
48
48
# shellcheck source=share/github-backup-utils/bm.sh
49
- . $GHE_BACKUP_ROOT /share/github-backup-utils/bm.sh
49
+ . " $GHE_BACKUP_ROOT /share/github-backup-utils/bm.sh"
50
50
51
51
# Save off GHE_HOSTNAME from the environment since we want it to override the
52
52
# backup.config value when set.
@@ -87,7 +87,7 @@ ghe_parallel_check() {
87
87
GHE_PARALLEL_COMMAND_OPTIONS=" -j $GHE_PARALLEL_MAX_JOBS "
88
88
# Default to the number of max rsync jobs to the same as GHE_PARALLEL_MAX_JOBS, if not set.
89
89
# This is only applicable to ghe-restore-repositories currently.
90
- : ${GHE_PARALLEL_RSYNC_MAX_JOBS:= " $GHE_PARALLEL_MAX_JOBS " }
90
+ : " ${GHE_PARALLEL_RSYNC_MAX_JOBS:= " $GHE_PARALLEL_MAX_JOBS " } "
91
91
fi
92
92
93
93
if [ -n " $GHE_PARALLEL_RSYNC_MAX_JOBS " ]; then
115
115
if [ -n " $GHE_VERBOSE " ]; then
116
116
if [ -n " $GHE_VERBOSE_LOG " ]; then
117
117
if [ " $GHE_PARALLEL_ENABLED " != " yes" ]; then
118
- exec 3>> " $GHE_VERBOSE_LOG "
118
+ exec 3>> " $GHE_VERBOSE_LOG "
119
119
else
120
120
if ! echo | awk ' { print strftime("%b %d %H:%M:%S"); fflush(); }' & > /dev/null; then
121
121
echo " Error: awk command failed. Please install https://www.gnu.org/software/gawk" 1>&2
122
122
exit 1
123
123
fi
124
124
calling_script_name=" $( caller | sed ' s:.*/::' ) "
125
- exec 3> >( awk -v c=$calling_script_name ' { print strftime("%b %d %H:%M:%S"), c":", $0; fflush(); }' >> " $GHE_VERBOSE_LOG " )
125
+ exec 3> >( awk -v c=" $calling_script_name " ' { print strftime("%b %d %H:%M:%S"), c":", $0; fflush(); }' >> " $GHE_VERBOSE_LOG " )
126
126
fi
127
127
else
128
128
exec 3>&1
149
149
# Convert the data directory path to an absolute path, basing any relative
150
150
# paths on the backup-utils root, and using readlink, if available, to
151
151
# canonicalize the path.
152
- if [ ${GHE_DATA_DIR: 0: 1} != " /" ]; then
153
- GHE_DATA_DIR=" $( cd " $GHE_BACKUP_ROOT " && readlink -m " $GHE_DATA_DIR " 2> /dev/null || echo " $GHE_BACKUP_ROOT /$GHE_DATA_DIR " ) "
152
+ if [ " ${GHE_DATA_DIR: 0: 1} " != " /" ]; then
153
+ GHE_DATA_DIR=" $( cd " $GHE_BACKUP_ROOT " && readlink -m " $GHE_DATA_DIR " 2> /dev/null || echo " $GHE_BACKUP_ROOT /$GHE_DATA_DIR " ) "
154
154
fi
155
155
export GHE_DATA_DIR
156
156
157
157
# Assign the Release File path if it hasn't been provided (eg: by test suite)
158
- : ${GHE_RELEASE_FILE:= " /etc/github/enterprise-release" }
158
+ : " ${GHE_RELEASE_FILE:= " /etc/github/enterprise-release" } "
159
159
160
160
# Check that utils are not being run directly on GHE appliance.
161
161
if [ -f " $GHE_RELEASE_FILE " ]; then
@@ -239,7 +239,7 @@ export GHE_SNAPSHOT_DIR
239
239
# Adjusts remote paths based on the version of the remote appliance. This is
240
240
# called immediately after the remote version is obtained by
241
241
# ghe_remote_version_required(). Child processes inherit the values set here.
242
- ghe_remote_version_config () {
242
+ ghe_remote_version_config () {
243
243
GHE_REMOTE_DATA_USER_DIR=" $GHE_REMOTE_DATA_DIR /user"
244
244
export GHE_REMOTE_DATA_DIR GHE_REMOTE_DATA_USER_DIR
245
245
export GHE_REMOTE_LICENSE_FILE
@@ -250,7 +250,7 @@ ghe_remote_version_config () {
250
250
251
251
# If we don't have a readlink command, parse ls -l output.
252
252
if ! type readlink 1> /dev/null 2>&1 ; then
253
- readlink () {
253
+ readlink () {
254
254
if [ -x " $1 " ]; then
255
255
ls -ld " $1 " | sed ' s/.*-> //'
256
256
else
265
265
# that need the remote version should use this function instead of calling
266
266
# ghe-host-check directly to reduce ssh roundtrips. The top-level ghe-backup and
267
267
# ghe-restore commands establish the version for all subcommands.
268
- ghe_remote_version_required () {
268
+ ghe_remote_version_required () {
269
269
if [ -z " $GHE_REMOTE_VERSION " ]; then
270
270
_out=$( ghe-host-check " $@ " )
271
271
echo " $_out "
@@ -288,8 +288,8 @@ ghe_remote_version_required () {
288
288
ghe_parse_version () {
289
289
local version_major version_minor version_patch
290
290
version_major=$( echo " ${1# v} " | cut -f 1 -d .)
291
- version_minor=$( echo " $1 " | cut -f 2 -d .)
292
- version_patch=$( echo " $1 " | cut -f 3 -d .)
291
+ version_minor=$( echo " $1 " | cut -f 2 -d .)
292
+ version_patch=$( echo " $1 " | cut -f 3 -d .)
293
293
version_patch=${version_patch%% [a-zA-Z]* }
294
294
295
295
echo " $version_major $version_minor $version_patch "
@@ -301,7 +301,7 @@ ghe_parse_version() {
301
301
#
302
302
# Scripts use these variables to alter behavior based on what's supported on the
303
303
# appliance version.
304
- ghe_parse_remote_version () {
304
+ ghe_parse_remote_version () {
305
305
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
306
306
read -r GHE_VERSION_MAJOR GHE_VERSION_MINOR GHE_VERSION_PATCH <<< $( ghe_parse_version $1 )
307
307
export GHE_VERSION_MAJOR GHE_VERSION_MINOR GHE_VERSION_PATCH
@@ -310,23 +310,23 @@ ghe_parse_remote_version () {
310
310
# Parses the <host> part out of a "<host>:<port>" or just "<host>" string.
311
311
# This is used primarily to break hostspecs with non-standard ports down for
312
312
# rsync commands.
313
- ssh_host_part () {
313
+ ssh_host_part () {
314
314
[ " ${1##*: } " = " $1 " ] && echo " $1 " || echo " ${1%:* } "
315
315
}
316
316
317
317
# Parses the <port> part out of a "<host>:<port>" or just "<host>" string.
318
318
# This is used primarily to break hostspecs with non-standard ports down for
319
319
# rsync commands.
320
- ssh_port_part () {
320
+ ssh_port_part () {
321
321
[ " ${1##*: } " = " $1 " ] && echo 22 || echo " ${1##*: } "
322
322
}
323
323
324
324
# Usage: ghe_remote_logger <message>...
325
325
# Log a message to /var/log/syslog on the remote instance.
326
326
# Note: Use sparingly. Remote logging requires an ssh connection per invocation.
327
- ghe_remote_logger () {
327
+ ghe_remote_logger () {
328
328
echo " $@ " |
329
- ghe-ssh " $GHE_HOSTNAME " -- logger -t backup-utils || true
329
+ ghe-ssh " $GHE_HOSTNAME " -- logger -t backup-utils || true
330
330
}
331
331
332
332
# Usage: ghe_verbose <message>
@@ -346,15 +346,14 @@ ghe_debug() {
346
346
echo -e " Debug: $* " 1>&3
347
347
elif [ -p /dev/stdin ]; then
348
348
echo " \n" 1>&3
349
- while read line
350
- do
349
+ while read line; do
351
350
echo -e " Debug: $line " 1>&3
352
- done < /dev/stdin
351
+ done < /dev/stdin
353
352
fi
354
353
}
355
354
356
355
version () {
357
- echo " ${@# v} " | awk -F. ' { printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }' ;
356
+ echo " ${@# v} " | awk -F. ' { printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
358
357
}
359
358
360
359
# The list of gists returned by the source changed in 2.16.23, 2.17.14,
@@ -363,10 +362,10 @@ version() {
363
362
# In newer versions, gist paths are unmodified, and only other repo types
364
363
# are truncated with `dirname`.
365
364
fix_paths_for_ghe_version () {
366
- if [[ " $GHE_REMOTE_VERSION " =~ 2.16. && " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.16.23) " ]] || \
367
- [[ " $GHE_REMOTE_VERSION " =~ 2.17. && " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.17.14) " ]] || \
368
- [[ " $GHE_REMOTE_VERSION " =~ 2.18. && " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.18.8) " ]] || \
369
- [[ " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.19.3) " ]]; then
365
+ if [[ " $GHE_REMOTE_VERSION " =~ 2.16. && " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.16.23) " ]] ||
366
+ [[ " $GHE_REMOTE_VERSION " =~ 2.17. && " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.17.14) " ]] ||
367
+ [[ " $GHE_REMOTE_VERSION " =~ 2.18. && " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.18.8) " ]] ||
368
+ [[ " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.19.3) " ]]; then
370
369
GIST_FILTER=" -e /gist/b"
371
370
else
372
371
unset GIST_FILTER
@@ -383,12 +382,12 @@ fix_paths_for_ghe_version() {
383
382
sed $GIST_FILTER -e ' s/\/$//; s/^[^\/]*$/./; s/\/[^\/]*$//'
384
383
}
385
384
386
- is_binary_backup_feature_on (){
385
+ is_binary_backup_feature_on () {
387
386
ghe-ssh " $GHE_HOSTNAME " ghe-config --true " mysql.backup.binary"
388
387
}
389
388
390
389
# Check if the backup is binary by looking up the sentinel file
391
- is_binary_backup (){
390
+ is_binary_backup () {
392
391
test -f " $1 /mysql-binary-backup-sentinel"
393
392
}
394
393
0 commit comments