From acda77a9bc6390be49a367e5f1199a71b9ac375a Mon Sep 17 00:00:00 2001 From: Twan Wolthof Date: Sat, 18 Oct 2014 18:35:00 +0200 Subject: [PATCH 001/288] Add .travis.yml Runs debuild -uc -us. Unfortunately runs the tests twice due to the default target also running the tests --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..82488dcf2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +--- +script: + - debuild -uc -us +before_install: + - sudo apt-get update -qq + - sudo apt-get install -y devscripts From c8a998d7360f52c4c8757eccf941803be8fb387d Mon Sep 17 00:00:00 2001 From: Twan Wolthof Date: Thu, 6 Nov 2014 02:27:20 +0100 Subject: [PATCH 002/288] override_dh_auto_build to prevent from running tests when 'building' --- debian/rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian/rules b/debian/rules index 4915d7afb..290fed548 100755 --- a/debian/rules +++ b/debian/rules @@ -1,5 +1,7 @@ #!/usr/bin/make -f build-indep: +override_dh_auto_build: + %: dh $@ From 3a3a1270f590e161218b19a846edf1026b2a16a0 Mon Sep 17 00:00:00 2001 From: Andy Walker Date: Thu, 13 Nov 2014 11:15:49 -0600 Subject: [PATCH 003/288] Enable SSH BatchMode --- share/github-backup-utils/ghe-ssh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/github-backup-utils/ghe-ssh b/share/github-backup-utils/ghe-ssh index 6a066e9a4..1ecab00a0 100755 --- a/share/github-backup-utils/ghe-ssh +++ b/share/github-backup-utils/ghe-ssh @@ -61,4 +61,4 @@ fi $GHE_VERBOSE_SSH && set -x # Exec ssh command with modified host / port args and add nice to command. -exec ssh $opts "$host" -- $GHE_NICE $GHE_IONICE "$@" +exec ssh $opts -o 'BatchMode yes' "$host" -- $GHE_NICE $GHE_IONICE "$@" From 263ebf29acf7e59ccb3358dd804326f0c3a78c74 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Thu, 13 Nov 2014 09:30:15 -0800 Subject: [PATCH 004/288] Tighten git-gc and git-nw-repack patterns to avoid false positives --- share/github-backup-utils/ghe-backup-repositories-rsync | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/github-backup-utils/ghe-backup-repositories-rsync b/share/github-backup-utils/ghe-backup-repositories-rsync index 9c2a98310..062983fb9 100755 --- a/share/github-backup-utils/ghe-backup-repositories-rsync +++ b/share/github-backup-utils/ghe-backup-repositories-rsync @@ -76,7 +76,7 @@ echo " while [ \$sanity -lt $GHE_GIT_COOLDOWN_PERIOD ]; do # note: the bracket synta[x] below is to prevent matches against the # grep process itself. - if ps axo pid,args | grep -q -e 'git.*nw-repac[k]' -e 'git.*g[c]'; then + if ps axo pid,args | grep -q -e 'git[ -].*nw-repac[k]' -e 'git[ -].*g[c]'; then sleep 1 sanity=\$(( sanity + 1 )) else From d3d3d8c4560b20a639d6079180a23f0108d65159 Mon Sep 17 00:00:00 2001 From: Andy Walker Date: Fri, 14 Nov 2014 11:02:50 -0600 Subject: [PATCH 005/288] Override BatchMode in ghe-host-check --- bin/ghe-host-check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ghe-host-check b/bin/ghe-host-check index faf5317fa..17012a397 100755 --- a/bin/ghe-host-check +++ b/bin/ghe-host-check @@ -24,7 +24,7 @@ port=$(ssh_port_part "$host") hostname=$(ssh_host_part "$host") set +e -output=$(echo "cat \"$GHE_REMOTE_METADATA_FILE\" 2>/dev/null || exit 101" | ghe-ssh $options $host -- /bin/sh 2>&1) +output=$(echo "cat \"$GHE_REMOTE_METADATA_FILE\" 2>/dev/null || exit 101" | ghe-ssh -o 'BatchMode no' $options $host -- /bin/sh) rc=$? set -e From 214fd4e4576d5aec4a6ee4a740765a1d34249ce6 Mon Sep 17 00:00:00 2001 From: Andy Walker Date: Fri, 14 Nov 2014 11:03:21 -0600 Subject: [PATCH 006/288] Turn ssh opts into array. Helps with quoted args --- share/github-backup-utils/ghe-ssh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/share/github-backup-utils/ghe-ssh b/share/github-backup-utils/ghe-ssh index 1ecab00a0..aed686d97 100755 --- a/share/github-backup-utils/ghe-ssh +++ b/share/github-backup-utils/ghe-ssh @@ -10,11 +10,11 @@ set -e cd $(dirname "$0")/../.. . share/github-backup-utils/ghe-backup-config -opts=$GHE_EXTRA_SSH_OPTS +eval opts=($GHE_EXTRA_SSH_OPTS) while true; do case "$1" in -p|-l|-o) - opts="$opts $1 $2" + opts=("${opts[@]}" $1 "$2") shift 2 ;; --) @@ -42,12 +42,12 @@ port=$(ssh_port_part "$host") host=$(ssh_host_part "$host") # Add port / -p option when non-standard port given. -[ "$port" != "22" ] && opts="-p $port $opts" +[ "$port" != "22" ] && opts=(-p $port "${opts[@]}") # Add user / -l option user="${host%@*}" [ "$user" = "$host" ] && user="admin" -opts="-l $user $opts" +opts=(-l "$user" "${opts[@]}") # Bail out with error if the simple command form is used with complex commands. # Complex @@ -61,4 +61,4 @@ fi $GHE_VERBOSE_SSH && set -x # Exec ssh command with modified host / port args and add nice to command. -exec ssh $opts -o 'BatchMode yes' "$host" -- $GHE_NICE $GHE_IONICE "$@" +exec ssh "${opts[@]}" -o 'BatchMode yes' "$host" -- $GHE_NICE $GHE_IONICE "$@" From a1ca969127a28b6df5aa3c3664846b1c252f4b9a Mon Sep 17 00:00:00 2001 From: Andy Walker Date: Fri, 14 Nov 2014 11:11:05 -0600 Subject: [PATCH 007/288] Replace accidentallied redirection --- bin/ghe-host-check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ghe-host-check b/bin/ghe-host-check index 17012a397..9ccfd09fa 100755 --- a/bin/ghe-host-check +++ b/bin/ghe-host-check @@ -24,7 +24,7 @@ port=$(ssh_port_part "$host") hostname=$(ssh_host_part "$host") set +e -output=$(echo "cat \"$GHE_REMOTE_METADATA_FILE\" 2>/dev/null || exit 101" | ghe-ssh -o 'BatchMode no' $options $host -- /bin/sh) +output=$(echo "cat \"$GHE_REMOTE_METADATA_FILE\" 2>/dev/null || exit 101" | ghe-ssh -o 'BatchMode no' $options $host -- /bin/sh 2>&1) rc=$? set -e From fa683114460602cafab0925f90f12e3190d24bb2 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Fri, 14 Nov 2014 13:40:12 -0800 Subject: [PATCH 008/288] Anchor git-gc proc matches to start of line, further tightening Additional enhancements to reduce the likelihood of false positive matches causing backups to fail after the GC cooldown window is exceeded. These should be much more resilient to matching either "gc" or "nw-repack" in other commands. The changes here introduce the following new rules for matching gc / repack processes::w - Only match "git" at the beginning of the line. Verified all GC / nw-repack invocations follow this pattern. - Match either "git gc" or "git --opts ... gc" but require a space before the subcommand (gc / nw-repack) in either case. i.e. Don't match "git somethingc". - Match "git ... gc" where "gc" is anchored at end of line. - Match "git gc --opts" where gc is followed by a space. --- share/github-backup-utils/ghe-backup-repositories-rsync | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/github-backup-utils/ghe-backup-repositories-rsync b/share/github-backup-utils/ghe-backup-repositories-rsync index 062983fb9..1f4a1a4ec 100755 --- a/share/github-backup-utils/ghe-backup-repositories-rsync +++ b/share/github-backup-utils/ghe-backup-repositories-rsync @@ -76,7 +76,7 @@ echo " while [ \$sanity -lt $GHE_GIT_COOLDOWN_PERIOD ]; do # note: the bracket synta[x] below is to prevent matches against the # grep process itself. - if ps axo pid,args | grep -q -e 'git[ -].*nw-repac[k]' -e 'git[ -].*g[c]'; then + if ps axo args | grep -q -E -e '^git( -.*)? nw-repac[k]( |$)' -e '^git( -.*)? g[c]( |$)'; then sleep 1 sanity=\$(( sanity + 1 )) else From 63990dec56d95db1a5c155ca0d84824713902bcb Mon Sep 17 00:00:00 2001 From: Twan Wolthof Date: Thu, 6 Nov 2014 01:11:32 +0100 Subject: [PATCH 009/288] Source /etc/github-backup-utils/backup.config if it exists --- share/github-backup-utils/ghe-backup-config | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/share/github-backup-utils/ghe-backup-config b/share/github-backup-utils/ghe-backup-config index 0b78d3a8f..1832090c6 100755 --- a/share/github-backup-utils/ghe-backup-config +++ b/share/github-backup-utils/ghe-backup-config @@ -20,6 +20,9 @@ PATH="$GHE_BACKUP_ROOT/bin:$GHE_BACKUP_ROOT/share/github-backup-utils:$PATH" # The backup config file. This may be set in the environment. : ${GHE_BACKUP_CONFIG:="$GHE_BACKUP_ROOT/backup.config"} +if [ ! -f $GHE_BACKUP_CONFIG ]; then + GHE_BACKUP_CONFIG="/etc/github-backup-utils/backup.config" +fi # Parse out -v (verbose) argument if [ "$1" = "-v" ]; then @@ -38,7 +41,9 @@ fi # Check that the config file exists before we source it in. if [ ! -f "$GHE_BACKUP_CONFIG" ]; then - echo "Error: The backup config file ('$GHE_BACKUP_CONFIG') doesn't exist." 1>&2 + echo "Error: No backup configuration file found. Tried:" + echo " - $GHE_BACKUP_ROOT/backup.config" + echo " - /etc/github-backup-utils/backup.config" exit 2 fi From 93cfc1d10b495518b9cff7c30089260d18e14932 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Mon, 17 Nov 2014 08:09:15 -0800 Subject: [PATCH 010/288] Move backup.config file finding around a bit --- share/github-backup-utils/ghe-backup-config | 32 ++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/share/github-backup-utils/ghe-backup-config b/share/github-backup-utils/ghe-backup-config index 1832090c6..6bc0fba13 100755 --- a/share/github-backup-utils/ghe-backup-config +++ b/share/github-backup-utils/ghe-backup-config @@ -20,9 +20,6 @@ PATH="$GHE_BACKUP_ROOT/bin:$GHE_BACKUP_ROOT/share/github-backup-utils:$PATH" # The backup config file. This may be set in the environment. : ${GHE_BACKUP_CONFIG:="$GHE_BACKUP_ROOT/backup.config"} -if [ ! -f $GHE_BACKUP_CONFIG ]; then - GHE_BACKUP_CONFIG="/etc/github-backup-utils/backup.config" -fi # Parse out -v (verbose) argument if [ "$1" = "-v" ]; then @@ -39,20 +36,29 @@ else exec 3>/dev/null fi -# Check that the config file exists before we source it in. -if [ ! -f "$GHE_BACKUP_CONFIG" ]; then - echo "Error: No backup configuration file found. Tried:" - echo " - $GHE_BACKUP_ROOT/backup.config" - echo " - /etc/github-backup-utils/backup.config" - exit 2 -fi - # Save off GHE_HOSTNAME from the environment since we want it to override the # backup.config value when set. GHE_HOSTNAME_PRESERVE="$GHE_HOSTNAME" -# Source in the backup config file. -. "$GHE_BACKUP_CONFIG" +# Source in the backup config file from the local working copy location first +# and then falling back to the system location. +config_found=false +for f in "$GHE_BACKUP_CONFIG" "/etc/github-backup-utils/backup.config"; do + if [ -f "$f" ]; then + GHE_BACKUP_CONFIG="$f" + . "$GHE_BACKUP_CONFIG" + config_found=true + break + fi +done + +# Check that the config file exists before we source it in. +if ! $config_found; then + echo "Error: No backup configuration file found. Tried:" 1>&2 + echo " - $GHE_BACKUP_CONFIG" 1>&2 + echo " - /etc/github-backup-utils/backup.config" 1>&2 + exit 2 +fi # Restore saved of hostname. [ -n "$GHE_HOSTNAME_PRESERVE" ] && GHE_HOSTNAME="$GHE_HOSTNAME_PRESERVE" From 377dab5ca616541a7b4d254c6a0ad9f472d7fd1d Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Mon, 17 Nov 2014 08:10:45 -0800 Subject: [PATCH 011/288] Typo --- share/github-backup-utils/ghe-backup-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/github-backup-utils/ghe-backup-config b/share/github-backup-utils/ghe-backup-config index 6bc0fba13..4b9df7f6a 100755 --- a/share/github-backup-utils/ghe-backup-config +++ b/share/github-backup-utils/ghe-backup-config @@ -60,7 +60,7 @@ if ! $config_found; then exit 2 fi -# Restore saved of hostname. +# Restore saved off hostname. [ -n "$GHE_HOSTNAME_PRESERVE" ] && GHE_HOSTNAME="$GHE_HOSTNAME_PRESERVE" # Check that the GHE hostname is set. From 959b6241d8fad329244f75b94a7b83a70d1c2f00 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Mon, 17 Nov 2014 08:22:48 -0800 Subject: [PATCH 012/288] Use -o Opt=val syntax instead of -o 'Opt val' This just lets us not deal with quoted values here just yet. --- bin/ghe-host-check | 2 +- share/github-backup-utils/ghe-ssh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/ghe-host-check b/bin/ghe-host-check index 9ccfd09fa..51a7d7232 100755 --- a/bin/ghe-host-check +++ b/bin/ghe-host-check @@ -24,7 +24,7 @@ port=$(ssh_port_part "$host") hostname=$(ssh_host_part "$host") set +e -output=$(echo "cat \"$GHE_REMOTE_METADATA_FILE\" 2>/dev/null || exit 101" | ghe-ssh -o 'BatchMode no' $options $host -- /bin/sh 2>&1) +output=$(echo "cat \"$GHE_REMOTE_METADATA_FILE\" 2>/dev/null || exit 101" | ghe-ssh -o BatchMode=no $options $host -- /bin/sh 2>&1) rc=$? set -e diff --git a/share/github-backup-utils/ghe-ssh b/share/github-backup-utils/ghe-ssh index aed686d97..c7bef198a 100755 --- a/share/github-backup-utils/ghe-ssh +++ b/share/github-backup-utils/ghe-ssh @@ -61,4 +61,4 @@ fi $GHE_VERBOSE_SSH && set -x # Exec ssh command with modified host / port args and add nice to command. -exec ssh "${opts[@]}" -o 'BatchMode yes' "$host" -- $GHE_NICE $GHE_IONICE "$@" +exec ssh "${opts[@]}" -o BatchMode=yes "$host" -- $GHE_NICE $GHE_IONICE "$@" From 46ee8af57a5de36812183fabc4866f1e7da87edb Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Mon, 17 Nov 2014 08:29:18 -0800 Subject: [PATCH 013/288] Flip back to non-bash-array option building for now I'd like to bring this back at some point because it does make things a lot more complete but I want to get some guidelines for using bash features in place before switching shebangs. --- share/github-backup-utils/ghe-ssh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/share/github-backup-utils/ghe-ssh b/share/github-backup-utils/ghe-ssh index c7bef198a..270db5cc8 100755 --- a/share/github-backup-utils/ghe-ssh +++ b/share/github-backup-utils/ghe-ssh @@ -10,11 +10,11 @@ set -e cd $(dirname "$0")/../.. . share/github-backup-utils/ghe-backup-config -eval opts=($GHE_EXTRA_SSH_OPTS) +opts="$GHE_EXTRA_SSH_OPTS" while true; do case "$1" in -p|-l|-o) - opts=("${opts[@]}" $1 "$2") + opts="$opts $1 $2" shift 2 ;; --) @@ -42,12 +42,12 @@ port=$(ssh_port_part "$host") host=$(ssh_host_part "$host") # Add port / -p option when non-standard port given. -[ "$port" != "22" ] && opts=(-p $port "${opts[@]}") +[ "$port" != "22" ] && opts="-p $port $opts" # Add user / -l option user="${host%@*}" [ "$user" = "$host" ] && user="admin" -opts=(-l "$user" "${opts[@]}") +opts="-l $user $opts" # Bail out with error if the simple command form is used with complex commands. # Complex @@ -61,4 +61,4 @@ fi $GHE_VERBOSE_SSH && set -x # Exec ssh command with modified host / port args and add nice to command. -exec ssh "${opts[@]}" -o BatchMode=yes "$host" -- $GHE_NICE $GHE_IONICE "$@" +exec ssh $opts -o BatchMode=yes "$host" -- $GHE_NICE $GHE_IONICE "$@" From 53e493a924eee3e335825a6c9624619e1a9dd40e Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Mon, 17 Nov 2014 21:46:41 -0800 Subject: [PATCH 014/288] Update debian/changelog for v2.0 release --- debian/changelog | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/debian/changelog b/debian/changelog index 394ae6c49..630cffbdd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,17 @@ +github-backup-utils (2.0.0) UNRELEASED; urgency=medium + + * Support for GitHub Enterprise 2.0. + * Support for migrating from GitHub Enterprise 11.10.34x to 2.0 (including from + VMware to AWS). + * ghe-backup retains hardlinks present on VM in backup snapshots, saving space. + * ghe-restore retains hardlinks present in backup snapshot when restoring to VM. + * backup-utils now includes debian packaging support. + * Fixes an issue with ghe-restore -s not using the snapshot specified. + * Fixes an issue with ghe-backup not waiting for nw-repack processes to finish + in some instances. + + -- Ryan Tomayko Mon, 10 Nov 2014 10:48:36 +0000 + github-backup-utils (1.1.0) UNRELEASED; urgency=medium * Updated documentation on minimum GitHub Enterprise version requirements for From e8b9111c4d11fa407b4ae589f2daa7a00e31a916 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Mon, 17 Nov 2014 21:49:07 -0800 Subject: [PATCH 015/288] Update debian/changelog for v2.0.1 release --- debian/changelog | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/debian/changelog b/debian/changelog index 630cffbdd..ded922013 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,19 @@ +github-backup-utils (2.0.1) UNRELEASED; urgency=medium + + * Adds /etc/github-backup-utils/backup.config as a default config file search + location for deb / system installs. + * Enables SSH BatchMode for all remote command invocation except initial host + check / version identification. + * Fixes a bug in ghe-backup where Git GC process detection would misclassify + long-running server processes matching /git.*gc/, causing the backup operation + to timeout. + * Adds a note and link to the Migrating from GitHub Enterprise v11.10.34x to + v2.0 documentation in the README. + * Adds example / documentation for the GHE_EXTRA_SSH_OPTS config value to the + backup.config-example file. + + -- Ryan Tomayko Mon, 17 Nov 2014 12:47:22 +0000 + github-backup-utils (2.0.0) UNRELEASED; urgency=medium * Support for GitHub Enterprise 2.0. From b3e5e6c21311ec7ec32946a1cacc926dd49e2373 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Mon, 17 Nov 2014 22:02:00 -0800 Subject: [PATCH 016/288] v2.0.1 release From f15cc95503f3f82474fd8ad0f197b1b1deffc3f8 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 1 Dec 2014 13:19:15 +0000 Subject: [PATCH 017/288] ghe-restore: check maintenance mode is enabled. Do this instead of just enabling it unconditionally. Fixes #62. --- bin/ghe-restore | 8 +++-- .../ghe-maintenance-mode-status | 30 ++++++++++++++++ test/test-ghe-restore.sh | 36 +++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100755 share/github-backup-utils/ghe-maintenance-mode-status diff --git a/bin/ghe-restore b/bin/ghe-restore index 48ab357e6..9db3d6c0c 100755 --- a/bin/ghe-restore +++ b/bin/ghe-restore @@ -147,10 +147,12 @@ if [ "$GHE_VERSION_MAJOR" -le 1 ] && [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then fi fi -# Make sure the GitHub appliance is in maintenance mode and all writing -# processes have bled out. +# Make sure the GitHub appliance is in maintenance mode. if $instance_configured; then - ghe-maintenance-mode-enable "$GHE_HOSTNAME" + if ! ghe-maintenance-mode-status "$GHE_HOSTNAME"; then + echo "Error: $GHE_HOSTNAME must be put in maintenance mode before restoring. Aborting." 1>&2 + exit 1 + fi fi # Restore settings and license if restoring to an unconfigured appliance or when diff --git a/share/github-backup-utils/ghe-maintenance-mode-status b/share/github-backup-utils/ghe-maintenance-mode-status new file mode 100755 index 000000000..0d88181ef --- /dev/null +++ b/share/github-backup-utils/ghe-maintenance-mode-status @@ -0,0 +1,30 @@ +#!/bin/sh +#/ Usage: ghe-maintenance-mode-status +#/ Checks the status of maintenance mode on GitHub appliance at . +set -e + +# Bring in the backup configuration +cd $(dirname "$0")/../.. +. share/github-backup-utils/ghe-backup-config + +# Parse args +while true; do + case "$1" in + -*) + echo "ghe-maintenance-mode-enable: illegal argument: $1" 1>&2 + exit 1 + ;; + *) + break + ;; + esac +done + +# Show usage and bail with no arguments +[ -z "$*" ] && print_usage + +# Grab host arg +host="$1" + +# Check if the maintenance page is present +ghe-ssh "$host" -- test -e $GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html diff --git a/test/test-ghe-restore.sh b/test/test-ghe-restore.sh index f4e3b509a..9d2570329 100755 --- a/test/test-ghe-restore.sh +++ b/test/test-ghe-restore.sh @@ -76,6 +76,10 @@ begin_test "ghe-restore into configured vm" touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured" fi + # create file used to determine if instance is in maintenance mode. + mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system" + touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" + # set restore host environ var GHE_RESTORE_HOST=127.0.0.1 export GHE_RESTORE_HOST @@ -133,6 +137,10 @@ begin_test "ghe-restore aborts without user verification" touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured" fi + # create file used to determine if instance is in maintenance mode. + mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system" + touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" + # set restore host environ var GHE_RESTORE_HOST=127.0.0.1 export GHE_RESTORE_HOST @@ -160,6 +168,10 @@ begin_test "ghe-restore accepts user verification" touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured" fi + # create file used to determine if instance is in maintenance mode. + mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system" + touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" + # set restore host environ var GHE_RESTORE_HOST=127.0.0.1 export GHE_RESTORE_HOST @@ -182,6 +194,10 @@ begin_test "ghe-restore -c into unconfigured vm" GHE_RESTORE_HOST=127.0.0.1 export GHE_RESTORE_HOST + # create file used to determine if instance is in maintenance mode. + mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system" + touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" + # run ghe-restore and write output to file for asserting against if ! ghe-restore -v -f -c > "$TRASHDIR/restore-out" 2>&1; then cat "$TRASHDIR/restore-out" @@ -227,6 +243,10 @@ begin_test "ghe-restore into unconfigured vm" GHE_RESTORE_HOST=127.0.0.1 export GHE_RESTORE_HOST + # create file used to determine if instance is in maintenance mode. + mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system" + touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" + if [ "$GHE_VERSION_MAJOR" -le 1 ]; then # run ghe-restore and write output to file for asserting against # this should fail due to the appliance being in an unconfigured state @@ -284,6 +304,10 @@ begin_test "ghe-restore with host arg" touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured" fi + # create file used to determine if instance is in maintenance mode. + mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system" + touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" + # set restore host environ var GHE_RESTORE_HOST=127.0.0.1 export GHE_RESTORE_HOST @@ -323,6 +347,10 @@ begin_test "ghe-restore no host arg or configured restore host" touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured" fi + # create file used to determine if instance is in maintenance mode. + mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system" + touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" + # unset configured restore host unset GHE_RESTORE_HOST @@ -344,6 +372,10 @@ begin_test "ghe-restore with no pages backup" touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured" fi + # create file used to determine if instance is in maintenance mode. + mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system" + touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" + # remove pages data rm -rf "$GHE_DATA_DIR/1/pages" @@ -365,6 +397,10 @@ begin_test "ghe-restore with tarball strategy" touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured" fi + # create file used to determine if instance is in maintenance mode. + mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system" + touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" + # run it echo "tarball" > "$GHE_DATA_DIR/current/strategy" output=$(ghe-restore -v -f localhost) From ac3588466231d36541f5a1b0d5ac2c3af626dc45 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 8 Dec 2014 18:50:38 +0000 Subject: [PATCH 018/288] Fix quoting of GHE_REMOTE_DATA_DIR Handle the case in which it might have spaces. --- share/github-backup-utils/ghe-maintenance-mode-status | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/github-backup-utils/ghe-maintenance-mode-status b/share/github-backup-utils/ghe-maintenance-mode-status index 0d88181ef..679ebb894 100755 --- a/share/github-backup-utils/ghe-maintenance-mode-status +++ b/share/github-backup-utils/ghe-maintenance-mode-status @@ -27,4 +27,4 @@ done host="$1" # Check if the maintenance page is present -ghe-ssh "$host" -- test -e $GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html +ghe-ssh "$host" -- test -e "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html" From a826aca5f6e975cd3127bb08052670ba3a439cfb Mon Sep 17 00:00:00 2001 From: Colin Seymour Date: Fri, 12 Dec 2014 18:09:08 +0000 Subject: [PATCH 019/288] Append newline when reading in settings Some sed implementations, like that on Solaris, don't process lines which don't end in EOL/newline. Forcing a newline helps these versions. --- share/github-backup-utils/ghe-restore-settings | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/github-backup-utils/ghe-restore-settings b/share/github-backup-utils/ghe-restore-settings index f3decf008..0c5aaa054 100755 --- a/share/github-backup-utils/ghe-restore-settings +++ b/share/github-backup-utils/ghe-restore-settings @@ -26,11 +26,11 @@ GHE_RESTORE_SNAPSHOT_PATH="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT" echo "Restoring settings ..." if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then # work around issue importing settings with bad storage mode values - cat "$GHE_RESTORE_SNAPSHOT_PATH/settings.json" | + ( cat "$GHE_RESTORE_SNAPSHOT_PATH/settings.json" && echo ) | sed 's/"storage_mode": "device"/"storage_mode": "rootfs"/' | ghe-ssh "$GHE_HOSTNAME" -- '/usr/bin/env GHEBUVER=2 ghe-import-settings' 1>&3 else - cat "$GHE_RESTORE_SNAPSHOT_PATH/settings.json" | + ( cat "$GHE_RESTORE_SNAPSHOT_PATH/settings.json" && echo ) | ghe-ssh "$GHE_HOSTNAME" -- '/usr/bin/env GHEBUVER=2 ghe-import-settings' 1>&3 fi From f7c15c5d4afad52fe4875a1af890c74442cec41f Mon Sep 17 00:00:00 2001 From: Colin Seymour Date: Fri, 12 Dec 2014 18:24:38 +0000 Subject: [PATCH 020/288] Switch grep -q for >/dev/null This makes the grep commands cross-platform compatible. --- bin/ghe-host-check | 4 ++-- bin/ghe-restore | 2 +- share/github-backup-utils/ghe-backup-repositories-rsync | 2 +- share/github-backup-utils/ghe-restore-es-rsync | 2 +- share/github-backup-utils/ghe-ssh | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/ghe-host-check b/bin/ghe-host-check index 51a7d7232..60d1c5766 100755 --- a/bin/ghe-host-check +++ b/bin/ghe-host-check @@ -31,7 +31,7 @@ set -e if [ $rc -ne 0 ]; then case $rc in 255) - if echo "$output" | grep -i -q "port 22: connection refused"; then + if echo "$output" | grep -i "port 22: connection refused" >/dev/null; then exec "$0" "$hostname:122" fi @@ -44,7 +44,7 @@ if [ $rc -ne 0 ]; then echo "Error: couldn't read GitHub Enterprise fingerprint on '$host' or this isn't a GitHub appliance." 1>&2 ;; 1) - if [ "${port:-22}" -eq 22 ] && echo "$output" | grep -q "use port 122"; then + if [ "${port:-22}" -eq 22 ] && echo "$output" | grep "use port 122" >/dev/null; then exec "$0" "$hostname:122" else echo "$output" 1>&2 diff --git a/bin/ghe-restore b/bin/ghe-restore index 9db3d6c0c..eeab45fd1 100755 --- a/bin/ghe-restore +++ b/bin/ghe-restore @@ -139,7 +139,7 @@ fi # Restoring Elasticsearch to 11.10.3x via rsync requires GNU tar if [ "$GHE_VERSION_MAJOR" -le 1 ] && [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then - if ! tar --version | grep -q GNU; then + if ! tar --version | grep GNU >/dev/null; then if ! command -v gtar >/dev/null 2>&1; then echo "GNU tar is required. Aborting." >&2 exit 1 diff --git a/share/github-backup-utils/ghe-backup-repositories-rsync b/share/github-backup-utils/ghe-backup-repositories-rsync index 1f4a1a4ec..ee8182b4c 100755 --- a/share/github-backup-utils/ghe-backup-repositories-rsync +++ b/share/github-backup-utils/ghe-backup-repositories-rsync @@ -76,7 +76,7 @@ echo " while [ \$sanity -lt $GHE_GIT_COOLDOWN_PERIOD ]; do # note: the bracket synta[x] below is to prevent matches against the # grep process itself. - if ps axo args | grep -q -E -e '^git( -.*)? nw-repac[k]( |$)' -e '^git( -.*)? g[c]( |$)'; then + if ps axo args | grep -E -e '^git( -.*)? nw-repac[k]( |$)' -e '^git( -.*)? g[c]( |$)' >/dev/null; then sleep 1 sanity=\$(( sanity + 1 )) else diff --git a/share/github-backup-utils/ghe-restore-es-rsync b/share/github-backup-utils/ghe-restore-es-rsync index 19a78f4d7..d1b769339 100755 --- a/share/github-backup-utils/ghe-restore-es-rsync +++ b/share/github-backup-utils/ghe-restore-es-rsync @@ -57,7 +57,7 @@ elif [ "$GHE_VERSION_MAJOR" -gt 1 ]; then else # Use GNU tar on BSDs. TAR=tar - if ! tar --version | grep -q GNU; then + if ! tar --version | grep GNU >/dev/null; then TAR=gtar fi cd "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT" diff --git a/share/github-backup-utils/ghe-ssh b/share/github-backup-utils/ghe-ssh index 270db5cc8..ec161297e 100755 --- a/share/github-backup-utils/ghe-ssh +++ b/share/github-backup-utils/ghe-ssh @@ -51,7 +51,7 @@ opts="-l $user $opts" # Bail out with error if the simple command form is used with complex commands. # Complex -if echo "$*" | grep -q "[|;]" || [ $(echo "$*" | wc -l) -gt 1 ]; then +if echo "$*" | grep "[|;]" >/dev/null || [ $(echo "$*" | wc -l) -gt 1 ]; then echo "fatal: ghe-ssh: Attempt to invoke complex command with simple command form." 1>&2 echo "See ghe-ssh --help for more on correcting." 1>&2 exit 1 From 101cfb5764f433da3f5775daf9e40a9d572af020 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 16 Dec 2014 14:27:18 +0000 Subject: [PATCH 021/288] Add test to check for bashisms. As discussed here: https://github.com/github/backup-utils/issues/85#issuecomment-66679219 --- test/test-bashisms.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 test/test-bashisms.sh diff --git a/test/test-bashisms.sh b/test/test-bashisms.sh new file mode 100755 index 000000000..a419ed797 --- /dev/null +++ b/test/test-bashisms.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# bashisms tests + +# Bring in testlib +. $(dirname "$0")/testlib.sh + +begin_test "ghe-* bashisms" +( + set -e + checkbashisms -f "$ROOTDIR/bin/ghe-"* +) +end_test From e828772285109f6fc71e4560a5febcd55009bb69 Mon Sep 17 00:00:00 2001 From: Elijah Buck Date: Wed, 14 Jan 2015 09:44:02 -0800 Subject: [PATCH 022/288] report mysqldump failures --- bin/ghe-backup | 4 ++-- share/github-backup-utils/ghe-ssh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/ghe-backup b/bin/ghe-backup index 9c42bc6eb..47031ccad 100755 --- a/bin/ghe-backup +++ b/bin/ghe-backup @@ -100,8 +100,8 @@ ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-ssh-host-keys' > ssh-host-keys.tar || failures="$failures ssh-host-keys" echo "Backing up MySQL database ..." -echo 'ghe-export-mysql | gzip' | -ghe-ssh "$GHE_HOSTNAME" -- /bin/sh > mysql.sql.gz || +echo 'set -o pipefail; ghe-export-mysql | gzip' | +ghe-ssh "$GHE_HOSTNAME" -- /bin/bash > mysql.sql.gz || failures="$failures mysql" echo "Backing up Redis database ..." diff --git a/share/github-backup-utils/ghe-ssh b/share/github-backup-utils/ghe-ssh index ec161297e..c10e3848f 100755 --- a/share/github-backup-utils/ghe-ssh +++ b/share/github-backup-utils/ghe-ssh @@ -1,6 +1,6 @@ #!/bin/sh #/ Usage: ghe-ssh [