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
156
156
# Assign the Release File path if it hasn't been provided (eg: by test suite)
157
- : ${GHE_RELEASE_FILE:= " /etc/github/enterprise-release" }
157
+ : " ${GHE_RELEASE_FILE:= " /etc/github/enterprise-release" } "
158
158
159
159
# Check that utils are not being run directly on GHE appliance.
160
160
if [ -f " $GHE_RELEASE_FILE " ]; then
@@ -238,7 +238,7 @@ export GHE_SNAPSHOT_DIR
238
238
# Adjusts remote paths based on the version of the remote appliance. This is
239
239
# called immediately after the remote version is obtained by
240
240
# ghe_remote_version_required(). Child processes inherit the values set here.
241
- ghe_remote_version_config () {
241
+ ghe_remote_version_config () {
242
242
GHE_REMOTE_DATA_USER_DIR=" $GHE_REMOTE_DATA_DIR /user"
243
243
export GHE_REMOTE_DATA_DIR GHE_REMOTE_DATA_USER_DIR
244
244
export GHE_REMOTE_LICENSE_FILE
@@ -249,7 +249,7 @@ ghe_remote_version_config () {
249
249
250
250
# If we don't have a readlink command, parse ls -l output.
251
251
if ! type readlink 1> /dev/null 2>&1 ; then
252
- readlink () {
252
+ readlink () {
253
253
if [ -x " $1 " ]; then
254
254
ls -ld " $1 " | sed ' s/.*-> //'
255
255
else
264
264
# that need the remote version should use this function instead of calling
265
265
# ghe-host-check directly to reduce ssh roundtrips. The top-level ghe-backup and
266
266
# ghe-restore commands establish the version for all subcommands.
267
- ghe_remote_version_required () {
267
+ ghe_remote_version_required () {
268
268
if [ -z " $GHE_REMOTE_VERSION " ]; then
269
269
_out=$( ghe-host-check " $@ " )
270
270
echo " $_out "
@@ -287,8 +287,8 @@ ghe_remote_version_required () {
287
287
ghe_parse_version () {
288
288
local version_major version_minor version_patch
289
289
version_major=$( echo " ${1# v} " | cut -f 1 -d .)
290
- version_minor=$( echo " $1 " | cut -f 2 -d .)
291
- version_patch=$( echo " $1 " | cut -f 3 -d .)
290
+ version_minor=$( echo " $1 " | cut -f 2 -d .)
291
+ version_patch=$( echo " $1 " | cut -f 3 -d .)
292
292
version_patch=${version_patch%% [a-zA-Z]* }
293
293
294
294
echo " $version_major $version_minor $version_patch "
@@ -300,7 +300,7 @@ ghe_parse_version() {
300
300
#
301
301
# Scripts use these variables to alter behavior based on what's supported on the
302
302
# appliance version.
303
- ghe_parse_remote_version () {
303
+ ghe_parse_remote_version () {
304
304
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
305
305
read -r GHE_VERSION_MAJOR GHE_VERSION_MINOR GHE_VERSION_PATCH <<< $( ghe_parse_version $1 )
306
306
export GHE_VERSION_MAJOR GHE_VERSION_MINOR GHE_VERSION_PATCH
@@ -309,23 +309,23 @@ ghe_parse_remote_version () {
309
309
# Parses the <host> part out of a "<host>:<port>" or just "<host>" string.
310
310
# This is used primarily to break hostspecs with non-standard ports down for
311
311
# rsync commands.
312
- ssh_host_part () {
312
+ ssh_host_part () {
313
313
[ " ${1##*: } " = " $1 " ] && echo " $1 " || echo " ${1%:* } "
314
314
}
315
315
316
316
# Parses the <port> part out of a "<host>:<port>" or just "<host>" string.
317
317
# This is used primarily to break hostspecs with non-standard ports down for
318
318
# rsync commands.
319
- ssh_port_part () {
319
+ ssh_port_part () {
320
320
[ " ${1##*: } " = " $1 " ] && echo 22 || echo " ${1##*: } "
321
321
}
322
322
323
323
# Usage: ghe_remote_logger <message>...
324
324
# Log a message to /var/log/syslog on the remote instance.
325
325
# Note: Use sparingly. Remote logging requires an ssh connection per invocation.
326
- ghe_remote_logger () {
326
+ ghe_remote_logger () {
327
327
echo " $@ " |
328
- ghe-ssh " $GHE_HOSTNAME " -- logger -t backup-utils || true
328
+ ghe-ssh " $GHE_HOSTNAME " -- logger -t backup-utils || true
329
329
}
330
330
331
331
# Usage: ghe_verbose <message>
@@ -345,15 +345,14 @@ ghe_debug() {
345
345
echo -e " Debug: $* " 1>&3
346
346
elif [ -p /dev/stdin ]; then
347
347
echo " \n" 1>&3
348
- while read line
349
- do
348
+ while read line; do
350
349
echo -e " Debug: $line " 1>&3
351
- done < /dev/stdin
350
+ done < /dev/stdin
352
351
fi
353
352
}
354
353
355
354
version () {
356
- echo " ${@# v} " | awk -F. ' { printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }' ;
355
+ echo " ${@# v} " | awk -F. ' { printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
357
356
}
358
357
359
358
# The list of gists returned by the source changed in 2.16.23, 2.17.14,
@@ -362,10 +361,10 @@ version() {
362
361
# In newer versions, gist paths are unmodified, and only other repo types
363
362
# are truncated with `dirname`.
364
363
fix_paths_for_ghe_version () {
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
364
+ if [[ " $GHE_REMOTE_VERSION " =~ 2.16. && " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.16.23) " ]] ||
365
+ [[ " $GHE_REMOTE_VERSION " =~ 2.17. && " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.17.14) " ]] ||
366
+ [[ " $GHE_REMOTE_VERSION " =~ 2.18. && " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.18.8) " ]] ||
367
+ [[ " $( version $GHE_REMOTE_VERSION ) " -ge " $( version 2.19.3) " ]]; then
369
368
GIST_FILTER=" -e /gist/b"
370
369
else
371
370
unset GIST_FILTER
@@ -382,11 +381,11 @@ fix_paths_for_ghe_version() {
382
381
sed $GIST_FILTER -e ' s/\/$//; s/^[^\/]*$/./; s/\/[^\/]*$//'
383
382
}
384
383
385
- is_binary_backup_feature_on (){
384
+ is_binary_backup_feature_on () {
386
385
ghe-ssh " $GHE_HOSTNAME " ghe-config --true " mysql.backup.binary"
387
386
}
388
387
389
388
# Check if the backup is binary by looking up the sentinel file
390
- is_binary_backup (){
389
+ is_binary_backup () {
391
390
test -f " $1 /mysql-binary-backup-sentinel"
392
- }
391
+ }
0 commit comments