Skip to content

Commit 6107410

Browse files
committed
Merge remote-tracking branch 'upstream/master' into sync-with-public-repo
2 parents 37426d4 + cd2c89b commit 6107410

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

share/github-backup-utils/ghe-backup-config

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#
1414
# . $( dirname "${BASH_SOURCE[0]}" )/../share/github-backup-utils/ghe-backup-config
1515
#
16-
16+
set +o posix
1717
# 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)"
1919

2020
# 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")"
2222

2323
# If a version check was requested, show the current version and exit
2424
if [ -n "$GHE_SHOW_VERSION" ]; then
@@ -28,9 +28,9 @@ fi
2828

2929
# Check for "--help|-h" in args or GHE_SHOW_HELP=true and show usage
3030
# shellcheck disable=SC2120 # the script name is always referenced
31-
print_usage () {
31+
print_usage() {
3232
grep '^#/' <"$0" | cut -c 4-
33-
exit ${1:-1}
33+
exit "${1:-1}"
3434
}
3535

3636
if [ -n "$GHE_SHOW_HELP" ]; then
@@ -46,7 +46,7 @@ fi
4646
# Add the bin and share/github-backup-utils dirs to PATH
4747
PATH="$GHE_BACKUP_ROOT/bin:$GHE_BACKUP_ROOT/share/github-backup-utils:$PATH"
4848
# 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"
5050

5151
# Save off GHE_HOSTNAME from the environment since we want it to override the
5252
# backup.config value when set.
@@ -87,7 +87,7 @@ ghe_parallel_check() {
8787
GHE_PARALLEL_COMMAND_OPTIONS="-j $GHE_PARALLEL_MAX_JOBS"
8888
# Default to the number of max rsync jobs to the same as GHE_PARALLEL_MAX_JOBS, if not set.
8989
# 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"}"
9191
fi
9292

9393
if [ -n "$GHE_PARALLEL_RSYNC_MAX_JOBS" ]; then
@@ -115,14 +115,14 @@ fi
115115
if [ -n "$GHE_VERBOSE" ]; then
116116
if [ -n "$GHE_VERBOSE_LOG" ]; then
117117
if [ "$GHE_PARALLEL_ENABLED" != "yes" ]; then
118-
exec 3>> "$GHE_VERBOSE_LOG"
118+
exec 3>>"$GHE_VERBOSE_LOG"
119119
else
120120
if ! echo | awk '{ print strftime("%b %d %H:%M:%S"); fflush(); }' &>/dev/null; then
121121
echo "Error: awk command failed. Please install https://www.gnu.org/software/gawk" 1>&2
122122
exit 1
123123
fi
124124
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")
126126
fi
127127
else
128128
exec 3>&1
@@ -149,13 +149,13 @@ fi
149149
# Convert the data directory path to an absolute path, basing any relative
150150
# paths on the backup-utils root, and using readlink, if available, to
151151
# 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")"
154154
fi
155155
export GHE_DATA_DIR
156156

157157
# 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"}"
159159

160160
# Check that utils are not being run directly on GHE appliance.
161161
if [ -f "$GHE_RELEASE_FILE" ]; then
@@ -239,7 +239,7 @@ export GHE_SNAPSHOT_DIR
239239
# Adjusts remote paths based on the version of the remote appliance. This is
240240
# called immediately after the remote version is obtained by
241241
# ghe_remote_version_required(). Child processes inherit the values set here.
242-
ghe_remote_version_config () {
242+
ghe_remote_version_config() {
243243
GHE_REMOTE_DATA_USER_DIR="$GHE_REMOTE_DATA_DIR/user"
244244
export GHE_REMOTE_DATA_DIR GHE_REMOTE_DATA_USER_DIR
245245
export GHE_REMOTE_LICENSE_FILE
@@ -250,7 +250,7 @@ ghe_remote_version_config () {
250250

251251
# If we don't have a readlink command, parse ls -l output.
252252
if ! type readlink 1>/dev/null 2>&1; then
253-
readlink () {
253+
readlink() {
254254
if [ -x "$1" ]; then
255255
ls -ld "$1" | sed 's/.*-> //'
256256
else
@@ -265,7 +265,7 @@ fi
265265
# that need the remote version should use this function instead of calling
266266
# ghe-host-check directly to reduce ssh roundtrips. The top-level ghe-backup and
267267
# ghe-restore commands establish the version for all subcommands.
268-
ghe_remote_version_required () {
268+
ghe_remote_version_required() {
269269
if [ -z "$GHE_REMOTE_VERSION" ]; then
270270
_out=$(ghe-host-check "$@")
271271
echo "$_out"
@@ -288,8 +288,8 @@ ghe_remote_version_required () {
288288
ghe_parse_version() {
289289
local version_major version_minor version_patch
290290
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 .)
293293
version_patch=${version_patch%%[a-zA-Z]*}
294294

295295
echo "$version_major $version_minor $version_patch"
@@ -301,7 +301,7 @@ ghe_parse_version() {
301301
#
302302
# Scripts use these variables to alter behavior based on what's supported on the
303303
# appliance version.
304-
ghe_parse_remote_version () {
304+
ghe_parse_remote_version() {
305305
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
306306
read -r GHE_VERSION_MAJOR GHE_VERSION_MINOR GHE_VERSION_PATCH <<<$(ghe_parse_version $1)
307307
export GHE_VERSION_MAJOR GHE_VERSION_MINOR GHE_VERSION_PATCH
@@ -310,23 +310,23 @@ ghe_parse_remote_version () {
310310
# Parses the <host> part out of a "<host>:<port>" or just "<host>" string.
311311
# This is used primarily to break hostspecs with non-standard ports down for
312312
# rsync commands.
313-
ssh_host_part () {
313+
ssh_host_part() {
314314
[ "${1##*:}" = "$1" ] && echo "$1" || echo "${1%:*}"
315315
}
316316

317317
# Parses the <port> part out of a "<host>:<port>" or just "<host>" string.
318318
# This is used primarily to break hostspecs with non-standard ports down for
319319
# rsync commands.
320-
ssh_port_part () {
320+
ssh_port_part() {
321321
[ "${1##*:}" = "$1" ] && echo 22 || echo "${1##*:}"
322322
}
323323

324324
# Usage: ghe_remote_logger <message>...
325325
# Log a message to /var/log/syslog on the remote instance.
326326
# Note: Use sparingly. Remote logging requires an ssh connection per invocation.
327-
ghe_remote_logger () {
327+
ghe_remote_logger() {
328328
echo "$@" |
329-
ghe-ssh "$GHE_HOSTNAME" -- logger -t backup-utils || true
329+
ghe-ssh "$GHE_HOSTNAME" -- logger -t backup-utils || true
330330
}
331331

332332
# Usage: ghe_verbose <message>
@@ -346,15 +346,14 @@ ghe_debug() {
346346
echo -e "Debug: $*" 1>&3
347347
elif [ -p /dev/stdin ]; then
348348
echo "\n" 1>&3
349-
while read line
350-
do
349+
while read line; do
351350
echo -e "Debug: $line" 1>&3
352-
done < /dev/stdin
351+
done </dev/stdin
353352
fi
354353
}
355354

356355
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); }'
358357
}
359358

360359
# The list of gists returned by the source changed in 2.16.23, 2.17.14,
@@ -363,10 +362,10 @@ version() {
363362
# In newer versions, gist paths are unmodified, and only other repo types
364363
# are truncated with `dirname`.
365364
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
370369
GIST_FILTER="-e /gist/b"
371370
else
372371
unset GIST_FILTER
@@ -383,12 +382,12 @@ fix_paths_for_ghe_version() {
383382
sed $GIST_FILTER -e 's/\/$//; s/^[^\/]*$/./; s/\/[^\/]*$//'
384383
}
385384

386-
is_binary_backup_feature_on(){
385+
is_binary_backup_feature_on() {
387386
ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary"
388387
}
389388

390389
# Check if the backup is binary by looking up the sentinel file
391-
is_binary_backup(){
390+
is_binary_backup() {
392391
test -f "$1/mysql-binary-backup-sentinel"
393392
}
394393

0 commit comments

Comments
 (0)