Created
March 28, 2019 02:32
-
-
Save Arvoreen/ecbc08760fcdade38359f1fa4381d861 to your computer and use it in GitHub Desktop.
Backup script that runs on remote site. Assumes already configured aliases for wp-cli
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
#!/bin/bash | |
# Current backup variables | |
DAY=`date +%d` | |
MONTH=`date +%m` | |
YEAR=`date +%Y` | |
# old backup vairables | |
OLDDAY=`date -d"400 days ago" +%d` | |
OLDMONTH=`date -d"400 days ago" +%m` | |
OLDYEAR=`date -d"400 days ago" +%Y` | |
PATH=$PATH:/usr/local/bin | |
# clean up anything older than 400 days | |
#find $HOME/backups -type f -mtime +400 | xargs rm -f | |
#enable this if you want to be extra sure you are cleanup up older files | |
# Loop through all sites, | |
echo "Starting backups @$(date)" | |
for site in $(cat $HOME/etc/sites); do | |
cd $HOME/backups | |
BKDIR="$HOME/backups/$site/$YEAR/$MONTH/$DAY" | |
OLDBKDIR="$HOME/backups/$site/$OLDYEAR/$OLDMONTH/$OLDDAY" | |
if [ ! -d "$BKDIR" ]; then | |
#make sure new directory exists | |
mkdir -p $BKDIR | |
fi | |
if [ -d "$OLDBKDIR" ]; then | |
#clean up old directory | |
rm -rf $OLDBKDIR | |
fi | |
echo "Starting backup for $site" | |
cd $BKDIR | |
scp prod:~/backups/$site/database.sql.gz . | |
scp prod:~/backups/$site/wordpress.tgz . | |
echo "Finished copying backukp for $site" | |
echo "Updating local copy of $site" | |
tar xzf wordpress.tgz -C /var/www/localhost/htdocs | |
gunzip -c database.sql.gz | wp @$site db import - | |
$HOME/bin/$site-backup | |
echo "Finished updating local copy of $site" | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment