There are tons of Automated backup plugins for WordPress, but the reality is you’re assuming they work unless you’ve actually restored one of them. This article will explain how to do this without using anything fancy like a backup program. In fact, I just give you a few scripts and of course the old, trusty, crontab.
You will need access to an Amazon S3 account (hopefully yours). You can modify the script to do whatever you want, but I suggest you just simply modify the script to your liking and off you go!
These backups are complete backups that actually work. The way I have mine setup is relatively simple.
I do a full backup of the wordpress directory / install once a week and database backups every day at 2am.
So here are the steps (Assuming you’re on CentOS or RHEL)
- cd /etc/yum.repos.d
- wget http://s3tools.org/repo/RHEL_5/s3tools.repo #if you’re on CENTOS_5 choose one or the other… but not both.
- wget http://s3tools.org/repo/RHEL_6/s3tools.repo # if you’re on CENTOS_6 choose one or the other.. but not both
- yum install s3cmd
- s3cmd –configure
- Fill out the information you’re asked for.
- mkdir -p /root/scripts
- cd /root/scripts
Using your favorite Editor, create a script name that will make sense to you.
Enter the following code into your script:
#!/bin/sh
NOWDATE=`date +%Y.%m.%d.` # This sets the date format as: 2012.month.day.
rm -rf /usr/src/swimminginthought.com.backup # This is a temp directory so we want to delete all the old stuff and start from scratch
mkdir -p /usr/src/website.name.backup/database #Create the new directory structure
mysqldump -u root -pYourMysqlRootPassword --add-drop-table Databasename > /usr/src/website.name.backup/database/database.backup.sql
unalias cp
chmod -R 777 /Path.to.html.files.for.the.website
tar czvf /usr/src/website.name.backup/website.name.tgz /Path.to.html.files.for.the.website
chmod -R 775 /Path.to.html.files.for.the.website
rm -rf /usr/src/backups
mkdir -p /usr/src/backups
tar czvf /usr/src/backups/$NOWDATE.website.name.tgz /usr/src/swimminginthought.com.backup/
s3cmd put /usr/src/backups/$NOWDATE.website.name.tgz s3://Amazon.s3.bucket/folder.you.want.to.put.the.backups.for.this.website.into.inside.the.bucket/
echo "Website.name backup to s3 successful" | /bin/mail -s "Website.name Backup Success" Your.email.address
Save the file. This is your full backup script. Remember to give it execute permissions.
Now here’s the code for the database backup script.
#!/bin/sh
NOWDATE=`date +%Y.%m.%d`
rm -rf /usr/src/website.name.backup
mkdir -p /usr/src/website.name.backup/database
mysqldump -u root -pYOUR.MYSQL.ROOT.PASSWORD --add-drop-table database.to.be.backed.up > /usr/src/WEBSITE.NAME.backup/database/$NOWDATE.website.name.database.backup.sql
unalias cp
rm -rf /usr/src/backups
mkdir -p /usr/src/backups
tar czvf /usr/src/backups/$NOWDATE.website.name.db.tgz /usr/src/website.name.backup/
s3cmd put /usr/src/backups/$NOWDATE.WEBSITE.NAME.db.tgz s3://amazon.bucket/folder.in.your.amazon.bucket.you.want.these.placed/
echo "Website.name DB backup to s3 successful" | /bin/mail -s "Website.name Backup Success" your.EMAIL.ADDRESS
This should do it for the two scripts.. just do a chmod +rx /root/scripts folder
Now let’s setup the schedule of the backups.
crontab -e
You should see a file that looks something like this.
* * * * 5 /root/scripts/swimminginthought.backup.s3 >> /dev/null &
* 2 * * * /root/scripts/database.dump.s3 >> /dev/null &
Modify it to your liking. The editor is vi, so I would suggest you get a vi cheat sheet or look for the how to use vi post on this blog.
There’s also a post on crontabs on this blog as well.
Be well and stop using those backup plugins. They’re buggy and always miss something. My method doesn’t.
Fantastic issues altogether, you simply gained a new reader. What could you suggest about your post that you made a few days in the past? Any positive?