Win 150$ in dogecoins every hour!

Small WordPress backup script

Simple backup script written in bash, for WordPress on Linux, that will dump MySQL database used by WordPress site and create tar.gz file consisting of WordPress site files and database dump



DBUSER=$(grep DB_USER $WEBROOT/wp-config.php | awk -F\' '{print$4}')
DBNAME=$(grep DB_NAME $WEBROOT/wp-config.php | awk -F\' '{print$4}')
DBPASSWORD=$(grep DB_PASSWORD $WEBROOT/wp-config.php | awk -F\' '{print$4}')
DBDUMP="$BKPDIR""$DBNAME"_$(date +"%Y-%m-%d-%H-%M").sql

#In case you want to rsync backups to remote server


tar -czvf "$BKPDIR"wpbackup_$(date +"%Y-%m-%d_%H-%M").tar.gz $WEBROOT $DBDUMP

rsync -az $BKPDIR -e "ssh -p $RSSHPORT" [email protected]$RHOST:$RDIR

It will create two backup files, one for database dump in format that looks like “joomla_2018-01-04-06-00.sql” and one tar.gz file that will look like “wpbackup_2018-01-04_06-00.tar.gz”.

Script can be saved as and put in crontab to run at a certain time like 6:00AM.

0 6 * * * /path/to/script/ 2>/dev/null

It can also be run manually with bash

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Win 200$ in Bitcoins every hour!