Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Backing Up MySQL Databases using Amazon S3

Backing Up MySQL Databases using Amazon S3

6

Now you know how to back up your files and code to Amazon S3, but what about databases? Luckily, help is at hand. The Linux s3cmd script can easily be used to back up your MySQL databases. To make things easier, I’ve created a script that you can use to back up all your databases into a folder, which is then synched with your S3 bucket.

The below script can be used via command line with a bit of configuration. All you need to do is set the MyUSER, MyPASS, MyHOST and S3Bucket variables at the top of the script and you can start backing up your databases.

You can use the above script in a cron too, so your server is backed up regularly. The below cronjob will run the MySQL database backup script everyday at 2am:

Once the script has completed, you’ll see a folder on your S3 Bucket with the date of the backup. If you run the script multiple times in a day, the latest version of your database will be synched to the same folder.

Amazon S3 Database Backup

Amazon Web Services, Backup, Linux, MySQL, Security

6 comments on “Backing Up MySQL Databases using Amazon S3”

  1. William Castro says:
    March 12, 2014 at 7:33 PM

    Excellent script! Works like a charm, thanks very much for sharing!

    Reply
  2. gbot says:
    July 29, 2014 at 1:01 AM

    Hi, thanks for this script, it looks like just what I need. Can you tell me where is the correct / safe place to store the script on the server?

    Reply
    • Niraj Shah says:
      July 29, 2014 at 11:16 AM

      I usually put the script in the home directory, e.g. ~/ or /root. The script works best with root access, so it can access all the databases to back them up. But in general, anywhere other than your web root folder should be safe.

      Reply
  3. EG says:
    August 28, 2014 at 6:04 AM

    Thank you! Best guide out of 10 I came across online on backing up MySql to S3.

    Reply
  4. Sunni Kumar says:
    August 18, 2015 at 2:27 PM

    Nice one please tell me how to take dump of rds database without using any linux machine directly on s3

    Reply
    • Niraj Shah says:
      September 4, 2015 at 7:17 PM

      You need a server to take a dump of a database. You cannot run code on S3, only static content.

      Reply

Leave a Reply to gbotCancel reply

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

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

Support Me

Buy Me a Coffee

PSN Profile

Tags

ACL Amazon Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache Backup Bug Command Line Cordova cPanel / WHM Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Firewall Flash Gadget Geolocation Google Nexus 5 Hacking HTML5 iOS JavaScript jQuery Laravel 5 Linux NodeJS Parse PDF PHP Plugin Portfolio PS4 Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2025 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy