|
| 1 | +#!/bin/sh |
| 2 | +#/ Usage: ghe-restore-settings <host> |
| 3 | +#/ Restore settings from a snapshot to the given <host>. |
| 4 | +set -e |
| 5 | + |
| 6 | +# Bring in the backup configuration |
| 7 | +cd $(dirname "$0")/.. |
| 8 | +. libexec/ghe-backup-config |
| 9 | + |
| 10 | +# Show usage and bail with no arguments |
| 11 | +[ -z "$*" ] && print_usage |
| 12 | + |
| 13 | +# Grab host arg |
| 14 | +host="$1" |
| 15 | + |
| 16 | +# Perform a host-check and establish GHE_REMOTE_XXX variables. |
| 17 | +ghe_remote_version_required "$host" |
| 18 | + |
| 19 | +# The snapshot to restore should be set by the ghe-restore command but this lets |
| 20 | +# us run this script directly. |
| 21 | +: ${GHE_RESTORE_SNAPSHOT:=current} |
| 22 | + |
| 23 | +# Path to snapshot dir we're restoring from |
| 24 | +GHE_RESTORE_SNAPSHOT_PATH="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT" |
| 25 | + |
| 26 | +echo "Restoring settings ..." |
| 27 | +ghe-ssh "$host" -- 'ghe-import-settings' < "$GHE_RESTORE_SNAPSHOT_PATH/settings.json" 1>&3 |
| 28 | + |
| 29 | +# Bail out if we're restoring against a pre-2.x appliance. Everything below is |
| 30 | +# supported by v2.0 appliances only. |
| 31 | +if [ "$GHE_VERSION_MAJOR" -lt 2 ]; then |
| 32 | + exit 0 |
| 33 | +fi |
| 34 | + |
| 35 | +echo "Restoring license ..." |
| 36 | +ghe-ssh "$host" -- 'ghe-import-license' < "$GHE_RESTORE_SNAPSHOT_PATH/enterprise.ghl" 1>&3 |
| 37 | + |
| 38 | +# Restore management console password hash if present. |
| 39 | +if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/manage-password" ]; then |
| 40 | + echo "Restoring management console password ..." |
| 41 | + cat "$GHE_RESTORE_SNAPSHOT_PATH/manage-password" | |
| 42 | + ghe-ssh "$host" -- \ |
| 43 | + "sudo -u git dd of='$GHE_REMOTE_DATA_USER_DIR/common/manage-password' 2>&1" |
| 44 | + ghe-ssh "$host" -- \ |
| 45 | + "sudo -u git chmod 0600 '$GHE_REMOTE_DATA_USER_DIR/common/manage-password'" |
| 46 | +fi |
0 commit comments