-
-
Save luisj135/7fc6e9143e4a8d616850e93ce08a2760 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
# backs up wordpress database and files | |
set -e | |
###### set your variables | |
BLOGDIR="/home/username/public_html/blog" ## location of blog on server | |
BUDIR="/home/username/blogbu" ## location of backups on server | |
DBNAME='dbname' ## name of your blog's database | |
DBUSER='dbuser' ## database username | |
DBPW='dbpasswd' ## database password | |
### cron is funky about its PATH, so add paths to all commands here: | |
PATH=/bin:/usr/bin:/usr/local/mysql/bin | |
### set date & time | |
datetime=`date "+%Y%m%d-%H%M"` | |
echo $datetime | |
### Backup database in BUDIR | |
echo "Creating db backup..." | |
mysqldump --user $DBUSER --password=$DBPW $DBNAME | gzip > $BUDIR/wpdb-$datetime.sql.gz | |
echo "Done with db backup" | |
### Backup files into BUDIR | |
echo "Creating wp file backup..." | |
tar -czf $BUDIR/wpfiles-$datetime.tar.gz $BLOGDIR | |
echo "Done with wp file backup" | |
### Delete backups over three days old (adjust depending on need/space) | |
echo "Deleting backups over three days old..." | |
find $BUDIR -mtime +3 -exec rm -f {} \; | |
echo "All Done"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment