Skip to content

Commit 54ec3ab

Browse files
authored
Merge branch 'master' into master
2 parents 8ed75d4 + af25034 commit 54ec3ab

File tree

7 files changed

+113
-58
lines changed

7 files changed

+113
-58
lines changed

bin/ghe-restore

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ while true; do
8686
esac
8787
done
8888

89+
start_cron () {
90+
echo "Starting cron ..."
91+
if $CLUSTER; then
92+
if ! ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-each -- sudo service cron start"; then
93+
echo "* Warning: Failed to start cron on one or more nodes"
94+
fi
95+
else
96+
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo service cron start"; then
97+
echo "* Warning: Failed to start cron"
98+
fi
99+
fi
100+
}
101+
89102
cleanup () {
90103
if [ -n "$1" ]; then
91104
update_restore_status "$1"
@@ -103,6 +116,10 @@ cleanup () {
103116
fi
104117
fi
105118

119+
if ! $CRON_RUNNING; then
120+
start_cron
121+
fi
122+
106123
# Cleanup SSH multiplexing
107124
ghe-ssh --clean
108125
}
@@ -249,6 +266,7 @@ update_restore_status () {
249266
fi
250267
}
251268

269+
CRON_RUNNING=true
252270
# Update remote restore state file and setup failure trap
253271
trap "cleanup failed" EXIT
254272
update_restore_status "restoring"
@@ -271,9 +289,15 @@ if [ -d "$GHE_RESTORE_SNAPSHOT_PATH/mssql" ] || [ -d "$GHE_RESTORE_SNAPSHOT_PATH
271289
ac_db_ghe=$(echo 'ghe-mssql-console -y -n -q "SELECT name FROM sys.databases" | grep -i "ArtifactCache" | wc -l | tr -d " "' | ghe-ssh "$GHE_HOSTNAME" /bin/bash)
272290
ac_db_snapshot=$(find "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/mssql/" -maxdepth 1 -name 'ArtifactCache*.bak' | wc -l | tr -d " ")
273291
if [[ $ac_db_ghe -gt 0 && $ac_db_snapshot -eq 0 ]]; then
274-
echo "Error: $GHE_HOSTNAME contains ArtifactCache databases but no ArtifactCache databases are present in snapshot. Aborting" 1>&2
275-
echo "Please delete ArtifactCache databases from $GHE_HOSTNAME and retry" 1>&2
276-
echo "Steps to delete ArtifactCache databases can be found here: https://docs.github.com/en/enterprise-server@$RELEASE_VERSION/admin/github-actions/advanced-configuration-and-troubleshooting/deleting-artifact-cache-databases" 1>&2
292+
echo "Error: $GHE_HOSTNAME has Actions Cache service enabled but no Actions Cache data is present in snapshot to restore. Aborting" 1>&2
293+
echo "Please disable Actions cache service in $GHE_HOSTNAME and retry" 1>&2
294+
echo "To disable Actions Cache service run as admin: ghe-actions-cache-disable" 1>&2
295+
exit 1
296+
fi
297+
if [[ $ac_db_ghe -eq 0 && $ac_db_snapshot -gt 0 && ! $RESTORE_SETTINGS ]]; then
298+
echo "Error: $GHE_HOSTNAME has Actions Cache service disabled but the snapshot is attempting to restore data for the service. Aborting" 1>&2
299+
echo "Please enable Actions cache service in $GHE_HOSTNAME and retry" 1>&2
300+
echo "To enable Actions Cache service run as admin: ghe-actions-cache-enable" 1>&2
277301
exit 1
278302
fi
279303
else
@@ -324,7 +348,7 @@ else
324348
fi
325349
fi
326350
fi
327-
351+
CRON_RUNNING=false
328352

329353
# Restore settings and license if restoring to an unconfigured appliance or when
330354
# specified manually.
@@ -492,16 +516,8 @@ if ! $RESTORE_SETTINGS; then
492516
fi
493517

494518
# Start cron. Timerd will start automatically as part of the config run.
495-
echo "Starting cron ..."
496-
if $CLUSTER; then
497-
if ! ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-each -- sudo service cron start"; then
498-
echo "* Warning: Failed to start cron on one or more nodes"
499-
fi
500-
else
501-
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo service cron start"; then
502-
echo "* Warning: Failed to start cron"
503-
fi
504-
fi
519+
start_cron
520+
CRON_RUNNING=true
505521

506522
# Clean up all stale replicas on configured instances.
507523
if ! $CLUSTER && $instance_configured; then

debian/changelog

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,39 @@
1-
github-backup-utils (3.4.0) UNRELEASED; urgency=medium
2-
3-
* Add anchor to usage doc for settings restore #865
4-
5-
-- Steve Culver <[email protected]> Tue, 15 Feb 2022 19:25:09 +0000
6-
7-
github-backup-utils (3.3.1) UNRELEASED; urgency=medium
8-
9-
* Fix compat issue with ghe-actions-start during maintenance mode #836
10-
11-
-- [email protected] Tue, 21 Dec 2021 23:38:01 +0000
12-
13-
github-backup-utils (3.3.0) UNRELEASED; urgency=medium
14-
15-
16-
-- [email protected] Wed, 08 Dec 2021 03:12:53 +0000
17-
18-
github-backup-utils (3.3.0) UNRELEASED; urgency=medium
1+
github-backup-utils (3.4.1) UNRELEASED; urgency=medium
192

3+
* Simplify complex redirects for ghe-rsync #881
4+
* On restore failure, restart cron on target host #883
205

21-
-- bonsohi@github.com Wed, 08 Dec 2021 03:10:21 +0000
6+
-- Donal Ellis <donal@github.com> Fri, 22 Apr 2022 04:00:00 +0000
227

23-
github-backup-utils (3.3.0) UNRELEASED; urgency=medium
24-
25-
26-
-- [email protected] Wed, 08 Dec 2021 02:56:47 +0000
27-
28-
github-backup-utils (3.3.0) UNRELEASED; urgency=medium
8+
github-backup-utils (3.3.2) UNRELEASED; urgency=medium
299

10+
* Simplify complex redirects for ghe-rsync #881
11+
* On restore failure, restart cron on target host #883
3012

31-
-- bonsohi@github.com Wed, 08 Dec 2021 02:51:06 +0000
13+
-- Donal Ellis <donal@github.com> Fri, 22 Apr 2022 00:53:45 +0000
3214

33-
github-backup-utils (3.3.0) UNRELEASED; urgency=medium
15+
github-backup-utils (3.4.0) UNRELEASED; urgency=medium
3416

17+
* Add anchor to usage doc for settings restore #865
3518

36-
-- bonsohi@github.com Wed, 08 Dec 2021 02:02:25 +0000
19+
-- Steve Culver <steveculver@github.com> Tue, 15 Feb 2022 19:25:09 +0000
3720

38-
github-backup-utils (3.3.0) UNRELEASED; urgency=medium
21+
github-backup-utils (3.3.1) UNRELEASED; urgency=medium
3922

23+
* Fix compat issue with ghe-actions-start during maintenance mode #836
4024

41-
-- [email protected] Wed, 08 Dec 2021 01:56:26 +0000
25+
-- Balwinder Sohi <[email protected]> Tue, 21 Dec 2021 23:38:01 +0000
4226

4327
github-backup-utils (3.3.0) UNRELEASED; urgency=medium
4428

45-
46-
-- [email protected] Wed, 08 Dec 2021 01:25:12 +0000
29+
-- Balwinder Sohi <[email protected]> Wed, 08 Dec 2021 03:12:53 +0000
4730

4831
github-backup-utils (3.3.0.rc1) UNRELEASED; urgency=medium
4932

50-
5133
-- Nick Iodice <[email protected]> Tue, 09 Nov 2021 19:56:08 +0000
5234

5335
github-backup-utils (3.2.0) UNRELEASED; urgency=medium
5436

55-
5637
-- Brett Westover <[email protected]> Tue, 28 Sep 2021 16:50:00 +0000
5738

5839
github-backup-utils (3.2.0.rc3) UNRELEASED; urgency=medium
@@ -86,7 +67,6 @@ github-backup-utils (3.2.0) UNRELEASED; urgency=medium
8667

8768
github-backup-utils (3.1.0) UNRELEASED; urgency=medium
8869

89-
9070
-- Zachary Mark <[email protected]> Thu, 03 Jun 2021 16:55:16 +0000
9171

9272
github-backup-utils (3.1.0~rc1) UNRELEASED; urgency=medium

share/github-backup-utils/ghe-backup-settings

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ if ghe-ssh "$host" -- ghe-config --true app.actions.enabled; then
116116
backup-secret "Actions Launch service private key" "actions-launch-app-app-private-key" "secrets.launch.azp-app-private-key"
117117
fi
118118

119+
if ghe-ssh "$host" -- ghe-config --true app.packages.enabled; then
120+
backup-secret "Packages aws access key" "packages-aws-access-key" "secrets.packages.aws-access-key"
121+
backup-secret "Packages aws secret key" "packages-aws-secret-key" "secrets.packages.aws-secret-key"
122+
backup-secret "Packages s3 bucket" "packages-s3-bucket" "secrets.packages.s3-bucket"
123+
backup-secret "Packages storage service url" "packages-service-url" "secrets.packages.service-url"
124+
backup-secret "Packages blob storage type" "packages-blob-storage-type" "secrets.packages.blob-storage-type"
125+
backup-secret "Packages azure connection string" "packages-azure-connection-string" "secrets.packages.azure-connection-string"
126+
backup-secret "Packages azure container name" "packages-azure-container-name" "secrets.packages.azure-container-name"
127+
fi
128+
119129
if ghe-ssh "$host" -- "test -f $GHE_REMOTE_DATA_USER_DIR/common/idp.crt"; then
120130
echo "* Transferring SAML keys ..." 1>&3
121131
ghe-ssh $host -- sudo tar -C $GHE_REMOTE_DATA_USER_DIR/common/ -cf - "idp.crt saml-sp.p12" > saml-keys.tar
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-restore-packages <host>
3+
#/
4+
#/ Note: This script typically isn't called directly. It's invoked by the
5+
#/ ghe-restore command.
6+
set -e
7+
8+
# Bring in the backup configuration
9+
# shellcheck source=share/github-backup-utils/ghe-backup-config
10+
. "$( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config"
11+
12+
# Show usage and bail with no arguments
13+
[ -z "$*" ] && print_usage
14+
15+
bm_start "$(basename $0)"
16+
17+
# Grab host arg
18+
GHE_HOSTNAME="$1"
19+
20+
# The snapshot to restore should be set by the ghe-restore command but this lets
21+
# us run this script directly.
22+
: ${GHE_RESTORE_SNAPSHOT:=current}
23+
24+
# Path to snapshot dir we're restoring from
25+
export GHE_RESTORE_SNAPSHOT_PATH="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"
26+
27+
port=$(ssh_port_part "$GHE_HOSTNAME")
28+
export port
29+
host=$(ssh_host_part "$GHE_HOSTNAME")
30+
31+
# Perform a host-check and establish GHE_REMOTE_XXX variables.
32+
ghe_remote_version_required "$host"
33+
34+
# Restore Packages settings.
35+
ghe_verbose "Restoring Packages settings ..."
36+
37+
restore-secret "Packages aws access key" "packages-aws-access-key" "secrets.packages.aws-access-key"
38+
restore-secret "Packages aws secret key" "packages-aws-secret-key" "secrets.packages.aws-secret-key"
39+
restore-secret "Packages s3 bucket" "packages-s3-bucket" "secrets.packages.s3-bucket"
40+
restore-secret "Packages storage service url" "packages-service-url" "secrets.packages.service-url"
41+
restore-secret "Packages blob storage type" "packages-blob-storage-type" "secrets.packages.blob-storage-type"
42+
restore-secret "Packages azure connection string" "packages-azure-connection-string" "secrets.packages.azure-connection-string"
43+
restore-secret "Packages azure container name" "packages-azure-container-name" "secrets.packages.azure-container-name"
44+
45+
bm_end "$(basename $0)"

share/github-backup-utils/ghe-restore-settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ echo "Restoring settings and applying configuration ..."
3333
# Restore external MySQL password if running external MySQL DB.
3434
restore-secret "external MySQL password" "external-mysql-password" "secrets.external.mysql"
3535

36+
echo "Restoring packages settings ..."
37+
ghe-restore-packages "$GHE_HOSTNAME" 1>&3
38+
3639
# work around issue importing settings with bad storage mode values
3740
( cat "$GHE_RESTORE_SNAPSHOT_PATH/settings.json" && echo ) |
3841
sed 's/"storage_mode": "device"/"storage_mode": "rootfs"/' |

share/github-backup-utils/ghe-rsync

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ set -o pipefail
1111
# shellcheck source=share/github-backup-utils/ghe-backup-config
1212
. "$( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config"
1313

14-
# Filter vanished file warnings from both stdout (rsync versions < 3.x) and
15-
# stderr (rsync versions >= 3.x). The complex redirections are necessary to
16-
# filter stderr while also keeping stdout and stderr separated.
17-
ignoreout='^(file has vanished: |rsync warning: some files vanished before they could be transferred)'
18-
1914
# Check for --ignore-missing-args parameter support and remove if unavailable.
2015
if rsync -h | grep '\-\-ignore-missing-args' >/dev/null 2>&1; then
2116
parameters=("$@")
@@ -25,9 +20,15 @@ else
2520
done
2621
fi
2722

28-
(rsync "${parameters[@]}" $GHE_EXTRA_RSYNC_OPTS 3>&1 1>&2 2>&3 3>&- |
29-
(egrep -v "$ignoreout" || true)) 3>&1 1>&2 2>&3 3>&- |
30-
(egrep -v "$ignoreout" || true)
23+
ignoreout='^(file has vanished: |rsync warning: some files vanished before they could be transferred)'
24+
rsync_version_check=`rsync --version | egrep "version 3.[0-9]*.[0-9]*"`
25+
if [ ! -z "$rsync_version_check" ]; then
26+
# rsync >= 3.x sends errors to stderr. so, we need to redirect to stdout before the pipe
27+
rsync "${parameters[@]}" $GHE_EXTRA_RSYNC_OPTS 2>&1 | (egrep -v "$ignoreout" || true)
28+
else
29+
# rsync <3.x sends errors to stdout.
30+
rsync "${parameters[@]}" $GHE_EXTRA_RSYNC_OPTS | (egrep -v "$ignoreout" || true)
31+
fi
3132
res=$?
3233

3334
# Suppress exits with 24.

share/github-backup-utils/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.4.0
1+
3.4.1

0 commit comments

Comments
 (0)