A Quick Guide to Move Database Backups to s3 Cloud via Cron

A Quick Guide to Move Database Backups to s3 Cloud via Cron

This blog walks you through a step by step guide to move your database backups to your Amazon AWS s3 cloud. Provided your website is hosted on an AWS instance, you can follow the undermentioned steps to keep your backups safe just-in-case your instance crashes, gets hacked or cleaned by mistake.

Don’t forget to use Netsuite amazon integration connector for a smooth transition of NetSuite and amazon store.

This guide is the continuation of my last blog, where you learned steps on scheduling MySql database backup using cron. Keeping backups on the same server is not always the best choice, it can only work if your database alone crashes and not the whole instance. Additionally, these backups occupy space on your live server, adding hard disk to a live server for keeping backups alone leads to high costs.

Amazon’s AWS cloud services, which span 54 availability zones to date within 18 geographic regions and 1 local region around the world, provide you this amazing feature called “s3 bucket” that helps in keeping your backup’s load off the live server. To avail this feature, you need to set up a s3 bucket first. Let’s have a look at how you can do it:

Step 1: Set up a s3 Bucket

You can find the updated method of creating a s3 bucket on AWS’ own website, click here to see their recent guide. The other steps linked to this guide also gives you information on how to add, download and delete files in the s3 bucket other than the hosting server.

Let’s assume your s3 bucket’s name to be “my-db-backups”

Step 2: Configure s3 Bucket in your Unix Instance (ubuntu in our case)

Now to enable your server to upload files to this bucket, execute the following commands on your AWS instance server:


You will be asked to provide details like, access_key and secret_key. Fill in the required information, you can always modify it by using the aforementioned command or by editing the following file:


To verify whether or not you have configured s3 cloud correctly on your server, execute the following command and check the file in the s3 bucket online:


Step 3: Add Command to Move your Backup to s3 Cloud via Cron Job

Now, modify your database backup script and enable it to upload these backups to the bucket instead of storing them on the server:


The last two lines are the additional commands in the script, the first one is same as the test command you executed at the end of step 2, whereas the other command in the script removes backup files that have been present for more than 7 days, assuming that they were moved to the bucket at the time of creation and are not required to be kept on the server. You can modify the +7 parameter as per your requirement.

Additional Information: s3 cloud can be used to store all types of content and not just database backups. You can even configure them on servers other than AWS but that requires installation and configuration of s3cmd and its pre-requisites, which shall be covered in my next blog.

That’s it! I am certain that this blog will help you in moving database backup to s3 cloud via cron efficiently.

Please feel free to comment or reach out if you have any questions. In case you need any help with server management, cron setup, installation, upgradation and customization of your Magento2 or Magento 1.9 web store, please get in touch with us.


USA408 365 4638


1301 Shoreway Road, Suite 160,

Belmont, CA 94002

Latest From Our Blog

Why the Daily Scrum is NOT a Status Meeting?

February 3, 2020
I am here today to debunk, The Myth “The Daily Scrum is the Status Meeting”. This is a key misconception in the industry and often resu...
Read more

A Complete Guide to Custom Caching in Magento 2...

November 29, 2019
In this blog, I will explain how to create your own cache in Magento 2, and how to read and write data from that custom cache. I hope after reading...
Read more

React Hooks

September 3, 2019
React is a javascript framework for building interactive client side interfaces along with the integration with back-end server. React considers th...
Read more