Skip to content

Commit bbfc42f

Browse files
authored
Added support for AC databases (#878)
* repair login for ac * added ac condition in restore * reverted new line * comment update * added qute * Update ghe-restore-actions * Update ghe-restore-actions * ci * revert deleted file * Update ghe-restore * Update ghe-restore-actions * Update ghe-restore * Update ghe-restore * Update ghe-restore * added doc link * added doc link
1 parent 0f898fb commit bbfc42f

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

bin/ghe-restore

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,22 @@ if $instance_configured; then
261261
fi
262262
fi
263263

264+
# Get GHES release version in major.minor format
265+
RELEASE_VERSION=$(ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --get core.package-version' | cut -d '.' -f 1,2)
266+
264267
# Make sure the GitHub appliance has Actions enabled if the snapshot contains Actions data.
268+
# If above is true, also check if ac is present in appliance then snapshot should also contains ac databases
265269
if [ -d "$GHE_RESTORE_SNAPSHOT_PATH/mssql" ] || [ -d "$GHE_RESTORE_SNAPSHOT_PATH/actions" ]; then
266-
if ! ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
267-
# Get GHES release version in major.minor format
268-
RELEASE_VERSION=$(ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --get core.package-version' | cut -d '.' -f 1,2)
269-
270+
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
271+
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)
272+
ac_db_snapshot=$(find "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/mssql/" -maxdepth 1 -name 'ArtifactCache*.bak' | wc -l | tr -d " ")
273+
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
277+
exit 1
278+
fi
279+
else
270280
echo "Error: $GHE_HOSTNAME must have GitHub Actions enabled before restoring since the snapshot contains Actions data. Aborting." 1>&2
271281
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
272282
exit 1

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)"

0 commit comments

Comments
 (0)