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.

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

Development and Configuration of Order Email Co...

January 9, 2019
    E-commerce businesses always needs dynamic rules of marketing to attract and lure their customers. The more the customers visits the ...
Read more

The Development Steps for Conventional Admin Fo...

December 17, 2018
    The learning curve for Magento 2, with all of the updates, has become even steeper. In this blog, I plan to showcase you how to devel...
Read more

Magento Update Order Data Using Observer

December 3, 2018
    Sometimes we may need to update/change order information like custom_field after an order is placed. We can easily do this on the fly...
Read more