Created
March 8, 2019 15:45
-
-
Save nvahalik/dd17bc697485fd97473252f2dad9cc42 to your computer and use it in GitHub Desktop.
Maintains hourly backups for a given site on Pantheon...
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
# Assumes you have installed Terminus and already authenticated using a machine token. | |
# Just call this script using a cronjob: | |
# 0 * * * * /home/backups/backup-this-site.sh site.env | |
TERMINUS_BIN="/home/backups/vendor/bin/terminus" | |
if [ "$1" == "" ]; then | |
echo "You must specify which host." | |
exit | |
fi | |
BACKUP_ROOT="/home/backups/$1" | |
# Create a new DB backup which is retained only for 1 day. | |
echo -n "Creating new DB backup for <${1}>..." | |
"$TERMINUS_BIN" backup:create "$1" --element=db --keep-for=1 -q -y | |
echo "done." | |
if [ ! -d "$BACKUP_ROOT" ]; then | |
mkdir "$BACKUP_ROOT"; | |
fi; | |
echo -n "Downloading backup..."; | |
curl -s `"$TERMINUS_BIN" backup:get "$1" --element=db` > "$BACKUP_ROOT/db-`date +%Y-%m-%d_%H-%M-%S`.sql.gz" | |
echo "done." | |
echo -n "Purging backups over 24 hours."; | |
find "$BACKUP_ROOT" -mtime 1 -exec rm {} \; | |
echo "done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment