Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Source for Simple WordPress backups Blog
#! /bin/sh
BLOG=blog_backup
BASE_DIR=/home/<username>/webapps/wp
USER=remote_username
PASS=database_password
DBUSER=database_user
DATABASE=database_name
DEST_DIR=destination_dir
IP_ADDRESS=blog_ip_address
#! /bin/sh
. backup_config.sh
NOW=$(date +"%m%d%Y")
FILENAME="${BLOG}_${NOW}.tar.gz"
DATABASE_BAK="Database_${BLOG}_${NOW}.gz"
echo "Running remote tar backup of blog directory"
ssh $USER@$IP_ADDRESS "cd $BASE_DIR && tar -zcf ~/$FILENAME ."
echo "Begin remote copy"; scp $USER@$IP_ADDRESS:~/$FILENAME $DEST_DIR \
&& echo "Remote copy successful, removing backup on server"; ssh $USER@$IP_ADDRESS "rm ~/$FILENAME"
echo "Starting Mysql dump"
ssh $USER@$IP_ADDRESS "mysqldump -u$DBUSER -p$PASS $DATABASE | gzip -c" > $DEST_DIR/$DATABASE_BAK
echo "Mysql dump completed"
echo "Created backup files:"
ls -la $DEST_DIR | grep $NOW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.