Skip to content

Commit d96eae9

Browse files
authored
Merge pull request #179 from github/ritchxu/actions-settings
Always restore Actions settings
2 parents 4c951f3 + d6dcb6a commit d96eae9

File tree

6 files changed

+39
-34
lines changed

6 files changed

+39
-34
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if [ -d "$GHE_DATA_DIR/current/actions" ] && [ "$(ls -A $GHE_DATA_DIR/current/ac
3737
fi
3838

3939
# Transfer all Actions data from the user data directory using rsync.
40-
ghe_verbose "* Transferring actions files from $host ..."
40+
ghe_verbose "* Transferring Actions files from $host ..."
4141

4242
ghe-rsync -avz \
4343
-e "ghe-ssh -p $port" \

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,13 @@ prompt_for_confirmation(){
477477

478478
echo
479479
}
480+
481+
# Function to restore a secret setting stored in a file.
482+
# restore-secret <description> <file-name> <setting-name>
483+
restore-secret() {
484+
if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/$2" ]; then
485+
echo "Restoring $1 ..."
486+
echo "ghe-config '$3' '$(cat "$GHE_RESTORE_SNAPSHOT_PATH/$2")'" |
487+
ghe-ssh "$GHE_HOSTNAME" -- /bin/bash
488+
fi
489+
}

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ GHE_HOSTNAME="$1"
2222
# us run this script directly.
2323
: ${GHE_RESTORE_SNAPSHOT:=current}
2424

25+
# Path to snapshot dir we're restoring from
26+
GHE_RESTORE_SNAPSHOT_PATH="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"
27+
2528
port=$(ssh_port_part "$GHE_HOSTNAME")
2629
host=$(ssh_host_part "$GHE_HOSTNAME")
2730

2831
# No need to restore anything, early exit
29-
if [ ! -d "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/actions" ]; then
32+
if [ ! -d "$GHE_RESTORE_SNAPSHOT_PATH/actions" ]; then
3033
echo "Warning: Actions backup missing. Skipping ..."
3134
exit 0
3235
fi
@@ -35,15 +38,35 @@ fi
3538
ghe_remote_version_required "$host"
3639

3740
# Transfer all Actions data from the snapshot to the user data directory using rsync.
38-
ghe_verbose "* Transferring actions files to $host ..."
41+
ghe_verbose "* Transferring Actions files to $host ..."
3942

4043
ghe-ssh -p "$port" "$host" -- sudo mkdir -p "$GHE_REMOTE_DATA_USER_DIR/actions"
4144
ghe-ssh -p "$port" "$host" -- sudo chown -R actions:actions "$GHE_REMOTE_DATA_USER_DIR/actions"
4245

4346
ghe-rsync -arvHR --delete \
4447
-e "ghe-ssh -p $port" \
4548
--rsync-path='sudo -u actions rsync' \
46-
"$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/actions/./" \
49+
"$GHE_RESTORE_SNAPSHOT_PATH/actions/./" \
4750
"$host:$GHE_REMOTE_DATA_USER_DIR/actions/" 1>&3
4851

52+
# Restore Actions settings.
53+
ghe_verbose "* Restoring Actions settings to $host ..."
54+
55+
restore-secret "Actions configuration database login" "actions-config-db-login" "secrets.actions.ConfigurationDatabaseSqlLogin"
56+
restore-secret "Actions configuration database password" "actions-config-db-password" "secrets.actions.ConfigurationDatabaseSqlPassword"
57+
restore-secret "Actions framework access token key secret" "actions-framework-access-token" "secrets.actions.FrameworkAccessTokenKeySecret"
58+
restore-secret "Actions Url signing HMAC key primary" "actions-url-signing-hmac-key-primary" "secrets.actions.UrlSigningHmacKeyPrimary"
59+
restore-secret "Actions Url signing HMAC key secondary" "actions-url-signing-hmac-key-secondary" "secrets.actions.UrlSigningHmacKeySecondary"
60+
restore-secret "Actions OAuth S2S signing cert" "actions-oauth-s2s-signing-cert" "secrets.actions.OAuthS2SSigningCert"
61+
restore-secret "Actions OAuth S2S signing key" "actions-oauth-s2s-signing-key" "secrets.actions.OAuthS2SSigningKey"
62+
restore-secret "Actions OAuth S2S signing cert thumbprint" "actions-oauth-s2s-signing-cert-thumbprint" "secrets.actions.OAuthS2SSigningCertThumbprint"
63+
restore-secret "Actions primary encryption cert thumbprint" "actions-primary-encryption-cert-thumbprint" "secrets.actions.PrimaryEncryptionCertificateThumbprint"
64+
restore-secret "Actions AAD cert thumbprint" "actions-aad-cert-thumbprint" "secrets.actions.AADCertThumbprint"
65+
restore-secret "Actions delegated auth cert thumbprint" "actions-delegated-auth-cert-thumbprint" "secrets.actions.DelegatedAuthCertThumbprint"
66+
restore-secret "Actions runtime service principal cert" "actions-runtime-service-principal-cert" "secrets.actions.RuntimeServicePrincipalCertificate"
67+
restore-secret "Actions S2S encryption cert" "actions-s2s-encryption-cert" "secrets.actions.S2SEncryptionCertificate"
68+
restore-secret "Actions secondary encryption cert thumbprint" "actions-secondary-encryption-cert-thumbprint" "secrets.actions.SecondaryEncryptionCertificateThumbprint"
69+
restore-secret "Actions service principal cert" "actions-service-principal-cert" "secrets.actions.ServicePrincipalCertificate"
70+
restore-secret "Actions SPS validation cert thumbprint" "actions-sps-validation-cert-thumbprint" "secrets.actions.SpsValidationCertThumbprint"
71+
4972
bm_end "$(basename $0)"

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,11 @@ GHE_RESTORE_SNAPSHOT_PATH="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"
2828
echo "Restoring license ..."
2929
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-import-license' < "$GHE_RESTORE_SNAPSHOT_PATH/enterprise.ghl" 1>&3
3030

31-
# Function to restore a secret setting stored in a file.
32-
# restore-secret <description> <file-name> <setting-name>
33-
restore-secret() {
34-
if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/$2" ]; then
35-
echo "Restoring $1 ..."
36-
echo "ghe-config '$3' '$(cat "$GHE_RESTORE_SNAPSHOT_PATH/$2")'" |
37-
ghe-ssh "$GHE_HOSTNAME" -- /bin/bash
38-
fi
39-
}
40-
4131
echo "Restoring settings ..."
4232

4333
# Restore external MySQL password if running external MySQL DB.
4434
restore-secret "external MySQL password" "external-mysql-password" "secrets.external.mysql"
4535

46-
# Restore Actions settings.
47-
restore-secret "Actions configuration database login" "actions-config-db-login" "secrets.actions.ConfigurationDatabaseSqlLogin"
48-
restore-secret "Actions configuration database password" "actions-config-db-password" "secrets.actions.ConfigurationDatabaseSqlPassword"
49-
restore-secret "Actions framework access token key secret" "actions-framework-access-token" "secrets.actions.FrameworkAccessTokenKeySecret"
50-
restore-secret "Actions Url signing HMAC key primary" "actions-url-signing-hmac-key-primary" "secrets.actions.UrlSigningHmacKeyPrimary"
51-
restore-secret "Actions Url signing HMAC key secondary" "actions-url-signing-hmac-key-secondary" "secrets.actions.UrlSigningHmacKeySecondary"
52-
restore-secret "Actions OAuth S2S signing cert" "actions-oauth-s2s-signing-cert" "secrets.actions.OAuthS2SSigningCert"
53-
restore-secret "Actions OAuth S2S signing key" "actions-oauth-s2s-signing-key" "secrets.actions.OAuthS2SSigningKey"
54-
restore-secret "Actions OAuth S2S signing cert thumbprint" "actions-oauth-s2s-signing-cert-thumbprint" "secrets.actions.OAuthS2SSigningCertThumbprint"
55-
restore-secret "Actions primary encryption cert thumbprint" "actions-primary-encryption-cert-thumbprint" "secrets.actions.PrimaryEncryptionCertificateThumbprint"
56-
restore-secret "Actions AAD cert thumbprint" "actions-aad-cert-thumbprint" "secrets.actions.AADCertThumbprint"
57-
restore-secret "Actions delegated auth cert thumbprint" "actions-delegated-auth-cert-thumbprint" "secrets.actions.DelegatedAuthCertThumbprint"
58-
restore-secret "Actions runtime service principal cert" "actions-runtime-service-principal-cert" "secrets.actions.RuntimeServicePrincipalCertificate"
59-
restore-secret "Actions S2S encryption cert" "actions-s2s-encryption-cert" "secrets.actions.S2SEncryptionCertificate"
60-
restore-secret "Actions secondary encryption cert thumbprint" "actions-secondary-encryption-cert-thumbprint" "secrets.actions.SecondaryEncryptionCertificateThumbprint"
61-
restore-secret "Actions service principal cert" "actions-service-principal-cert" "secrets.actions.ServicePrincipalCertificate"
62-
restore-secret "Actions SPS validation cert thumbprint" "actions-sps-validation-cert-thumbprint" "secrets.actions.SpsValidationCertThumbprint"
63-
6436
# work around issue importing settings with bad storage mode values
6537
( cat "$GHE_RESTORE_SNAPSHOT_PATH/settings.json" && echo ) |
6638
sed 's/"storage_mode": "device"/"storage_mode": "rootfs"/' |

test/test-ghe-backup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ begin_test "ghe-backup takes backup of Actions files"
490490
enable_actions
491491

492492
output=$(ghe-backup -v)
493-
echo $output | grep "Transferring actions files from"
493+
echo $output | grep "Transferring Actions files from"
494494

495495
diff -ru "$GHE_REMOTE_DATA_USER_DIR/actions" "$GHE_DATA_DIR/current/actions"
496496
)

test/test-ghe-restore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ begin_test "ghe-restore with Actions data"
377377

378378
output=$(ghe-restore -v -f localhost 2>&1)
379379

380-
echo "$output" | grep -q "Transferring actions files to"
380+
echo "$output" | grep -q "Transferring Actions files to"
381381

382382
diff -ru "$GHE_REMOTE_DATA_USER_DIR/actions" "$GHE_DATA_DIR/current/actions"
383383
)

0 commit comments

Comments
 (0)