-
-
Save jsoningram/9791a24b7abed495ed90 to your computer and use it in GitHub Desktop.
Shell script to backup WordPress site files and database with option to transfer to remote site
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 | |
# backup WP db and site files, takes one argument (name of document root) | |
# name of directory to backup (public_html, httpdocs etc) | |
dir=$1 | |
cd /path/to/$dir | |
# get the db details | |
echo "Enter the db username:" | |
read dbusername | |
echo "Enter the db password:" | |
read -s dbpassword | |
echo "Enter the db name:" | |
read dbname | |
dumpfile=$dbusername`date +%H%M%j`.sql | |
tarball=$dbusername`date +%H%M%j`.tar | |
# run the dump | |
mysqldump --add-drop-table -u $dbusername -p$dbpassword $dbname > $dumpfile | |
# create the archive, but exclude backupbuddy directories | |
tar -vcf $tarball --exclude='backupbuddy' --exclude='backupbuddy_backups' . | |
# clean up | |
rm $dumpfile | |
echo "Do you want to transfer the backup to the remote?" | |
read a | |
case $a in | |
yes|y) scp $tarball CHANGETOYOURUSER@CHANGETOYOURDOMAIN:~/PATH/TO/DESTINATION;; | |
no|n) echo "Ok, we won't transfer the backup";; | |
*) echo "Please answer yes or no";; | |
esac | |
echo "all done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment