Skip to content

Commit 413d25d

Browse files
authored
Merge branch 'master' into packages-settings
2 parents ea3a50e + 245aeed commit 413d25d

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

bin/ghe-restore

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,28 @@ if $instance_configured; then
279279
fi
280280
fi
281281

282+
# Get GHES release version in major.minor format
283+
RELEASE_VERSION=$(ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --get core.package-version' | cut -d '.' -f 1,2)
284+
282285
# Make sure the GitHub appliance has Actions enabled if the snapshot contains Actions data.
286+
# If above is true, also check if ac is present in appliance then snapshot should also contains ac databases
283287
if [ -d "$GHE_RESTORE_SNAPSHOT_PATH/mssql" ] || [ -d "$GHE_RESTORE_SNAPSHOT_PATH/actions" ]; then
284-
if ! ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
285-
# Get GHES release version in major.minor format
286-
RELEASE_VERSION=$(ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --get core.package-version' | cut -d '.' -f 1,2)
287-
288+
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
289+
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)
290+
ac_db_snapshot=$(find "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/mssql/" -maxdepth 1 -name 'ArtifactCache*.bak' | wc -l | tr -d " ")
291+
if [[ $ac_db_ghe -gt 0 && $ac_db_snapshot -eq 0 ]]; then
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
301+
exit 1
302+
fi
303+
else
288304
echo "Error: $GHE_HOSTNAME must have GitHub Actions enabled before restoring since the snapshot contains Actions data. Aborting." 1>&2
289305
echo "Setup details for enabling Actions can be found here: https://docs.github.com/en/enterprise-server@$RELEASE_VERSION/admin/github-actions/advanced-configuration-and-troubleshooting/backing-up-and-restoring-github-enterprise-server-with-github-actions-enabled" 1>&2
290306
exit 1
@@ -464,6 +480,14 @@ echo "Restarting memcached ..." 1>&3
464480
echo "sudo restart -q memcached 2>/dev/null || true" |
465481
ghe-ssh "$GHE_HOSTNAME" -- /bin/sh
466482

483+
# Prevent GitHub Connect jobs running before we've had a chance to reset
484+
# the configuration by setting the last run date to now.
485+
if ! $RESTORE_SETTINGS; then
486+
echo "Setting last run date for GitHub Connect jobs ..." 1>&3
487+
echo "now=$(date +%s.0000000); ghe-redis-cli mset timer:UpdateConnectInstallationInfo \$now timer:UploadEnterpriseServerUserAccountsJob \$now timer:UploadConnectMetricsJob \$now timer:GitHubConnectPushNewContributionsJob \$now" |
488+
ghe-ssh "$GHE_HOSTNAME" -- /bin/sh 1>&3
489+
fi
490+
467491
# When restoring to a host that has already been configured, kick off a
468492
# config run to perform data migrations.
469493
if $CLUSTER; then

share/github-backup-utils/ghe-backup-repositories

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ cleanup() {
9090

9191
# Enable remote GC operations
9292
for hostname in $hostnames; do
93-
ghe-gc-enable $ssh_config_file_opt $hostname:$port || true
93+
ghe-gc-enable $ssh_config_file_opt $hostname:$port || {
94+
echo "Re-enable gc on $hostname failed, please manually delete $SYNC_IN_PROGRESS_FILE" 1>&2
95+
}
9496
done
9597

9698
ghe-ssh "$GHE_HOSTNAME" -- rm -rf $remote_tempdir
9799
rm -rf $tempdir
98100
}
99-
trap 'cleanup' EXIT
100-
trap 'exit $?' INT # ^C always terminate
101+
trap 'cleanup' EXIT INT
101102

102103
# Disable remote GC operations
103104
for hostname in $hostnames; do

share/github-backup-utils/ghe-backup-storage

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ mkdir -p "$backup_dir"
5959
cleanup() {
6060
# Enable remote maintenance operations
6161
for hostname in $hostnames; do
62-
ghe-gc-enable $ssh_config_file_opt $hostname:$port || true
62+
ghe-gc-enable $ssh_config_file_opt $hostname:$port || {
63+
echo "Re-enable gc on $hostname failed, please manually delete $SYNC_IN_PROGRESS_FILE" 1>&2
64+
}
6365
done
6466

6567
ghe-ssh "$GHE_HOSTNAME" -- rm -rf $remote_tempdir

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,10 @@ ghe-ssh -p "$port" "$host" -- ghe-actions-console -s mps -c "Repair-DatabaseLogi
9393
ghe-ssh -p "$port" "$host" -- ghe-actions-console -s token -c "Repair-DatabaseLogins"
9494
ghe-ssh -p "$port" "$host" -- ghe-actions-console -s actions -c "Repair-DatabaseLogins"
9595

96+
if [ ! -z "$(find "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/mssql/" -maxdepth 1 -name 'ArtifactCache_Configuration*.bak')" ]; then
97+
ghe-ssh -p "$port" "$host" -- ghe-actions-console -s artifactcache -c "Repair-DatabaseLogins"
98+
else
99+
echo "ArtifactCache is not present in mssql backup. Skipping Repair-DatabaseLogins for it."
100+
fi
101+
96102
bm_end "$(basename $0)"

test/bin/ghe-redis-cli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ while true; do
1818
echo "fake redis data" > "$GHE_REMOTE_DATA_USER_DIR/redis/dump.rdb"
1919
break
2020
;;
21+
mset)
22+
# Fake accepting of mset command
23+
shift 9
24+
break
25+
;;
2126
--remote)
2227
# Fake accepting hostname argument
2328
shift 3

0 commit comments

Comments
 (0)