Swimminginthought

A place for all things technical and my mind..

Menu
  • About Me / Hire Me
Menu

Automated Backups to Amazon S3. WordPress example explained here.

Posted on March 25, 2012 by Percy Kwong

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)

  1. cd /etc/yum.repos.d
  2. wget http://s3tools.org/repo/RHEL_5/s3tools.repo  #if you’re on CENTOS_5 choose one or the other… but not both.
  3. wget http://s3tools.org/repo/RHEL_6/s3tools.repo # if you’re on CENTOS_6 choose one or the other.. but not both
  4. yum install s3cmd
  5. s3cmd –configure
  6. Fill out the information you’re asked for.
  7. mkdir -p /root/scripts
  8. 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.

If you’d like me to set this up for you, I will do it for $25.00 USD.  Should take about 15 min.  Just contact-me.

1 thought on “Automated Backups to Amazon S3. WordPress example explained here.”

  1. Free VPN says:
    May 28, 2012 at 5:20 am

    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?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs
  • Resurrection of the Blog
  • Encryption type Matters with Deep Packet Inspection – solved
  • Completely off topic.. Just a personal note.

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs

Recent Comments

  • Percy Kwong on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Nick Doelman on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Percy Kwong on International Text solutions – A solution
  • Muzahid Ul Islam on The Browser Wars; Which One is Best?
  • Muzahid Ul Islam on International Text solutions – A solution

Archives

  • September 2019
  • August 2019
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • August 2011
  • June 2011
  • March 2011
  • February 2011
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • January 2010
  • November 2009
  • October 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008

Categories

  • Activism
  • All
  • Amazon S3
  • Announcements
  • Apache
  • Apple
  • Applications
  • Automation
  • AWS
  • Azure
  • Backups
  • Blogging
  • Books
  • Bootcamp
  • CentOS – RHEL
  • Cloud Computing
  • Cloudformation
  • Consulting Advice
  • Craigslist
  • Databases
  • Deep Packet Inspection
  • Doing the right thing
  • e-Book Readers
  • E-Mail
  • EC2
  • energy-efficiency
  • environment
  • Expose
  • firewalls
  • General Observations
  • Hardware
  • Hope
  • Hosting
  • IaC
  • Important things to do in life
  • Infrastructure as Code
  • Kubernetes
  • Linux
  • Media and Encoding
  • Miscellany
  • Mobile Phones
  • MySql
  • Networking
  • Performance
  • Personal
  • pfsense
  • Politics
  • Privacy
  • Redundancy
  • Routers
  • security
  • SPAM
  • Tech that doesn't work like it should
  • Tips and Tricks
  • Tools that work
  • Tout
  • Video
  • Virtual Computing
  • VOIP-Voice Over IP
  • VPN
  • Web Browsers
  • Web Hosting
  • Websites
  • Windows
  • Wordpress

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2026 Swimminginthought | Built using WordPress and Responsive Blogily theme by Superb