Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request github#238 from github/snh/benchmark-backups
Browse files Browse the repository at this point in the history
Benchmark backups
  • Loading branch information
rubiojr authored Jul 26, 2016
2 parents 405ad4b + cb51a79 commit ef4c5ef
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/ghe-backup
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,23 @@ ghe-backup-settings ||
failures="$failures settings"

echo "Backing up SSH authorized keys ..."
bm_start "ghe-export-authorized-keys"
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-authorized-keys' > authorized-keys.json ||
failures="$failures authorized-keys"
bm_end "ghe-export-authorized-keys"

echo "Backing up SSH host keys ..."
bm_start "ghe-export-ssh-host-keys"
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-ssh-host-keys' > ssh-host-keys.tar ||
failures="$failures ssh-host-keys"
bm_end "ghe-export-ssh-host-keys"

echo "Backing up MySQL database ..."
bm_start "ghe-export-mysql"
echo 'set -o pipefail; ghe-export-mysql | gzip' |
ghe-ssh "$GHE_HOSTNAME" -- /bin/bash > mysql.sql.gz ||
failures="$failures mysql"
bm_end "ghe-export-mysql"

echo "Backing up Redis database ..."
if $cluster; then
Expand Down
6 changes: 6 additions & 0 deletions share/github-backup-utils/ghe-backup-alambic-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Set up remote host and root backup snapshot directory based on config
host="$GHE_HOSTNAME"
backup_dir="$GHE_SNAPSHOT_DIR/storage"
Expand Down Expand Up @@ -67,6 +69,7 @@ if [ -d "$GHE_DATA_DIR/current/storage" ] && [ "$(ls -A $GHE_DATA_DIR/current/st
fi

for hostname in $hostnames; do
bm_start "$(basename $0) - $hostname"
echo 1>&3
echo "* Starting backup for host: $hostname"
# Sync all auxiliary repository data. This includes files and directories like
Expand All @@ -82,4 +85,7 @@ for hostname in $hostnames; do
$link_dest \
"$hostname:$GHE_REMOTE_DATA_USER_DIR/storage/" \
"$GHE_SNAPSHOT_DIR/storage" 1>&3
bm_end "$(basename $0) - $hostname"
done

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-es-audit-log
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Set up remote host and root elastic backup directory based on config
host="$GHE_HOSTNAME"

Expand Down Expand Up @@ -39,3 +41,5 @@ for index in $indices; do
ghe-ssh "$host" "/usr/local/share/enterprise/ghe-es-dump-json \"http://localhost:$es_port/$index\"" | gzip > $GHE_SNAPSHOT_DIR/audit-log/$index.gz
fi
done

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-es-hookshot
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Set up remote host and root elastic backup directory based on config
host="$GHE_HOSTNAME"

Expand All @@ -29,3 +31,5 @@ for index in $indices; do
ghe-ssh "$host" "/usr/local/share/enterprise/ghe-es-dump-json 'http://localhost:9201/$index'" | gzip > $GHE_SNAPSHOT_DIR/hookshot/$index.gz
fi
done

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-es-rsync
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Set up remote host and root elastic backup directory based on config
host="$GHE_HOSTNAME"

Expand Down Expand Up @@ -93,3 +95,5 @@ ghe-rsync -avz \
--exclude='elasticsearch.yml' \
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch/" \
"$GHE_SNAPSHOT_DIR/elasticsearch" 1>&3

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-es-tarball
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Snapshot all Elasticsearch data or fake it when no /data/elasticsearch
# directory exists.
echo "
Expand All @@ -18,3 +20,5 @@ echo "
tar cvf - --files-from /dev/null
fi
" | ghe-ssh "$GHE_HOSTNAME" /bin/sh > "$GHE_SNAPSHOT_DIR"/elasticsearch.tar

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-fsck
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

echo "Running git fsck on repos..."

# Verify git is available.
Expand Down Expand Up @@ -83,3 +85,5 @@ done
echo "* Repos verified: $repos, Errors: $errors, Took: $(($(date +%s) - $t_start))s"

rm -f $log

bm_end "$(basename $0)"
2 changes: 2 additions & 0 deletions share/github-backup-utils/ghe-backup-git-hooks-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Verify rsync is available.
if ! rsync --version 1>/dev/null 2>&1; then
echo "Error: rsync not found." 1>&2
Expand Down
6 changes: 6 additions & 0 deletions share/github-backup-utils/ghe-backup-pages-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Set up remote host and root backup snapshot directory based on config
host="$GHE_HOSTNAME"
backup_dir="$GHE_SNAPSHOT_DIR/pages"
Expand Down Expand Up @@ -67,6 +69,7 @@ if [ -d "$GHE_DATA_DIR/current/pages" ] && [ "$(ls -A $GHE_DATA_DIR/current/page
fi

for hostname in $hostnames; do
bm_start "$(basename $0) - $hostname"
echo 1>&3
echo "* Starting backup for host: $hostname"
# Sync all auxiliary repository data. This includes files and directories like
Expand All @@ -82,4 +85,7 @@ for hostname in $hostnames; do
$link_dest \
"$hostname:$GHE_REMOTE_DATA_USER_DIR/pages/" \
"$GHE_SNAPSHOT_DIR/pages" 1>&3
bm_end "$(basename $0) - $hostname"
done

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-pages-rsync
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Make sure root backup dir exists if this is the first run
mkdir -p "$GHE_SNAPSHOT_DIR/pages"

# Use the common user data rsync backup utility.
ghe-backup-userdata pages

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-pages-tarball
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Snapshot all Pages data or fake it when no /data/pages directory exists.
echo '
if [ -d /data/pages ]; then
Expand All @@ -17,3 +19,5 @@ echo '
tar cvf - --files-from /dev/null
fi
' | ghe-ssh "$GHE_HOSTNAME" /bin/sh > "$GHE_SNAPSHOT_DIR"/pages.tar

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-redis
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Perform a host-check and establish GHE_REMOTE_XXX variables.
ghe_remote_version_required "$GHE_HOSTNAME"

Expand All @@ -26,3 +28,5 @@ ghe-ssh "$GHE_HOSTNAME" /bin/sh <<EOF
done
$sudo cat '$GHE_REMOTE_DATA_USER_DIR/redis/dump.rdb'
EOF

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-redis-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Perform a host-check and establish GHE_REMOTE_XXX variables.
ghe_remote_version_required "$GHE_HOSTNAME"

Expand All @@ -34,3 +36,5 @@ ghe-ssh "$GHE_HOSTNAME" /bin/sh <<EOF
$sudo cat '$GHE_REMOTE_DATA_USER_DIR/redis/dump.rdb'
fi
EOF

bm_end "$(basename $0)"
6 changes: 6 additions & 0 deletions share/github-backup-utils/ghe-backup-repositories-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Split host:port into parts
port=$(ssh_port_part "$GHE_HOSTNAME")
host=$(ssh_host_part "$GHE_HOSTNAME")
Expand Down Expand Up @@ -129,6 +131,7 @@ rsync_repository_data () {


for hostname in $hostnames; do
bm_start "$(basename $0) - $hostname"
echo 1>&3
echo "* Starting backup for host: $hostname"
# Sync all auxiliary repository data. This includes files and directories like
Expand Down Expand Up @@ -286,4 +289,7 @@ RULES
+ /info/*
RULES
echo 1>&3
bm_end "$(basename $0) - $hostname"
done

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-repositories-rsync
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Set up remote host and root backup snapshot directory based on config
host="$GHE_HOSTNAME"
backup_dir="$GHE_SNAPSHOT_DIR/repositories"
Expand Down Expand Up @@ -240,3 +242,5 @@ rsync_repository_data <<RULES
+ /info/*
RULES
echo 1>&3

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-repositories-tarball
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

# Snapshot all Git repository data
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-repositories' > "$GHE_SNAPSHOT_DIR"/repositories.tar

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-settings
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -e
# Perform a host-check and establish GHE_REMOTE_XXX variables.
ghe_remote_version_required "$host"

bm_start "$(basename $0)"

# Grab the host
host="$GHE_HOSTNAME"

Expand Down Expand Up @@ -50,3 +52,5 @@ if [ "$GHE_BACKUP_STRATEGY" = "cluster" ]; then
exit 1
fi
fi

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-store-version
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0)"

if [ -d $GHE_BACKUP_ROOT/.git ]; then
version_info="$BACKUP_UTILS_VERSION"
ref=$(git --git-dir=$GHE_BACKUP_ROOT/.git rev-parse HEAD || true)
Expand All @@ -15,3 +17,5 @@ if [ -d $GHE_BACKUP_ROOT/.git ]; then
echo "$version_info" |
ghe-ssh "$GHE_HOSTNAME" -- "sudo dd of=$GHE_REMOTE_DATA_USER_DIR/common/backup-utils-version >/dev/null 2>&1"
fi

bm_end "$(basename $0)"
4 changes: 4 additions & 0 deletions share/github-backup-utils/ghe-backup-userdata
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set -e
# Bring in the backup configuration
. $( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config

bm_start "$(basename $0) - $1"

# Verify rsync is available.
if ! rsync --version 1>/dev/null 2>&1; then
echo "Error: rsync not found." 1>&2
Expand Down Expand Up @@ -57,3 +59,5 @@ ghe-rsync -avz \
$link_dest \
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/$dirname/" \
"$GHE_SNAPSHOT_DIR/$dirname" 1>&3

bm_end "$(basename $0) - $1"
15 changes: 15 additions & 0 deletions test/test-ghe-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ begin_test "ghe-backup subsequent snapshot"
)
end_test

begin_test "ghe-backup logs the benchmark"
(
set -e

# wait a second for snapshot timestamp
sleep 1

export BM_TIMESTAMP=foo

ghe-backup

[ $(grep took $GHE_DATA_DIR/current/benchmarks/benchmark.foo.log | wc -l) -gt 1 ]
)
end_test

begin_test "ghe-backup with relative data dir path"
(
set -e
Expand Down

0 comments on commit ef4c5ef

Please sign in to comment.