Skip to content

Instantly share code, notes, and snippets.

@ghuntley
Last active October 11, 2015 12:07
Show Gist options
  • Save ghuntley/3856266 to your computer and use it in GitHub Desktop.
Save ghuntley/3856266 to your computer and use it in GitHub Desktop.
backup github appliance
#!/bin/bash
#set -xv
######################################################################
#
# Script Name : backup-github-appliance.sh
#
# Purpose : Exports core-data from github appliance
# Note :
# Called by : admin crontab
# Author : Geoffrey Huntley <ghuntley@ghuntley.com>
# Date : 22/07/2013
######################################################################
# global variables
HOSTNAME="github.example.com"
TAG=$(date '+%Y%m%d-%H%M')
DESTINATION=~/backups/$TAG
SCRIPT=$(basename $0)
RV=0
notifyAdmin(){
ls -ltr ~/backups/* | mail -s "`hostname`: Error occurred during execution of `whoami`: $SCRIPT" root
}
# backup mysql, redis and git repos as per:
# https://support.enterprise.github.com/entries/21160081-backing-up-your-installation
ssh "admin@$HOSTNAME" -- 'ghe-export-authorized-keys' | gzip > "$DESTINATION-enterprise-authorized-keys.json.gz"
((RV=RV+$?))
ssh "admin@$HOSTNAME" -- 'ghe-export-es-indices' | gzip > "$DESTINATION-enterprise-es-indices.tar.gz"
((RV=RV+$?))
ssh "admin@$HOSTNAME" -- 'ghe-export-mysql' | gzip > "$DESTINATION-enterprise-mysql-backup.sql.gz"
((RV=RV+$?))
ssh "admin@$HOSTNAME" -- 'ghe-export-pages' | gzip > "$DESTINATION-enterprise-pages.tar.gz"
((RV=RV+$?))
ssh "admin@$HOSTNAME" -- 'ghe-export-redis' > "$DESTINATION-backup-redis.rdb"
((RV=RV+$?))
ssh "admin@$HOSTNAME" -- 'ghe-export-repositories' > "$DESTINATION-enterprise-repositories-backup.tar"
((RV=RV+$?))
ssh "admin@$HOSTNAME" -- 'ghe-export-settings' | gzip > "$DESTINATION-enterprise-sessings.json.gz"
((RV=RV+$?))
ssh "admin@$HOSTNAME" -- 'ghe-export-ssh-host-keys' | gzip > "$DESTINATION-ssh-host-keys.tar.gz"
((RV=RV+$?))
# retain backups backups on disk for 3+1 days, after which remove.
find ~/backups/ -type f -ctime +4 -exec rm {} \;
((RV=RV+$?))
# The combined value of $RV should be 0 after all execution is done.
# If $RV is greater than 0 then one of the backup commands above failed
# and needs to be investigated.
if [ $RV -gt 0 ]
then
notifyAdmin
fi
crontab for admin user at 9am, 12pm, 3pm, 6pm and at midnight:
0 9 * * * /home/admin/bin/backup-github-appliance.sh 1>/dev/null 2>&1
0 12 * * * /home/admin/bin/backup-github-appliance.sh 1>/dev/null 2>&1
0 15 * * * /home/admin/bin/backup-github-appliance.sh 1>/dev/null 2>&1
0 18 * * * /home/admin/bin/backup-github-appliance.sh 1>/dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment