-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #413 from github/lildude/optimise-mysql-es-restores
Optimise hookshot and audit log backups and restores and MySQL restores
- Loading branch information
Showing
6 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bash | ||
#/ Usage: ghe-restore-mysql <host> | ||
#/ Restore MySQL backup to a GitHub instance. | ||
#/ | ||
#/ Note: This script typically isn't called directly. It's invoked by the | ||
#/ ghe-restore command when the rsync strategy is used. | ||
set -e | ||
|
||
# Bring in the backup configuration | ||
# shellcheck source=share/github-backup-utils/ghe-backup-config | ||
. "$( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config" | ||
|
||
# Show usage and bail with no arguments | ||
[ -z "$*" ] && print_usage | ||
|
||
bm_start "$(basename $0)" | ||
|
||
# Grab host arg | ||
GHE_HOSTNAME="$1" | ||
|
||
# Perform a host-check and establish the remote version in GHE_REMOTE_VERSION. | ||
ghe_remote_version_required "$GHE_HOSTNAME" | ||
|
||
# The snapshot to restore should be set by the ghe-restore command but this lets | ||
# us run this script directly. | ||
: ${GHE_RESTORE_SNAPSHOT:=current} | ||
|
||
# The directory holding the snapshot to restore | ||
snapshot_dir="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT" | ||
|
||
cleanup() { | ||
ghe-ssh "$GHE_HOSTNAME" -- "sudo rm -rf $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz" | ||
} | ||
trap 'cleanup' INT TERM EXIT | ||
|
||
ghe-ssh "$GHE_HOSTNAME" -- "sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR/tmp'" 1>&3 | ||
|
||
# Transfer MySQL data from the snapshot to the GitHub instance. | ||
cat $snapshot_dir/mysql.sql.gz | ghe-ssh "$GHE_HOSTNAME" -- "sudo dd of=$GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz >/dev/null 2>&1" | ||
|
||
# Import the database | ||
echo "gunzip -cd $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz | ghe-import-mysql" | ghe-ssh "$GHE_HOSTNAME" -- /bin/bash 1>&3 | ||
|
||
|
||
bm_end "$(basename $0)" |