Praveen Kumar Praveen Kumar - 3 years ago 144
PHP Question

AWS Database Backup RDS to S3 By Crontab (Cron Job)

I want to create database backup on daily bases using cron job.

I have created one batch file for database backup. Below is batch file code.

SQLDUMP="$(date +'%Y%m%d%H%M').sql.gz"

echo "Creating backup of database to $SQLDUMP"
mysqldump --host '' -u 'root' -p 'password' --databases 'test' | gzip -9 > $SQLDUMP

echo "Dump Zipped up"

echo "Uploading zipped dump to the Amazon S3 bucket…"


echo "Removing the backup file $SQLDUMP"

echo "Done"

But database backup not storage on S3.

File Path : var/app/current/app/

Set for 5 hrs in Crontab : * 5 * * * /bin/sh /var/app/current/app/

Answer Source

May be you have not setup for s3cmd package in your AWS server. So please check all below setup. So I think you have helpful points:

Setup :- 1 
On CentOS/RHEL: # yum install s3cmd
On Ubuntu/Debian: $ sudo apt-get install s3cmd
On SUSE Linux Enterprise Server 11:
    # zypper addrepo
    # zypper install s3cmd

Setup :- 2
Install Latest s3cmd using Source 

$ wget
$ tar xzf s3cmd-1.6.1.tar.gz

Now install it using below command with source files.
$ cd s3cmd-1.6.1
$ sudo python install

Configure s3cmd Environment
# s3cmd --configure

Enter new values or accept defaults in brackets with Enter.Refer to user manual for detailed description of all options.

For more details Please check below link :-

Batch file check :- File name

SQLDUMP="$(date +'%Y%m%d%H%M').sql.gz"
mysqldump -pPASSWORD -u sos -h sos | gzip -9 > $SQLDUMPPATH
s3cmd put $SQLDUMPPATH s3://S3NAME/dbbackup/$SQLDUMP
echo "Removing the backup file $SQLDUMP"  
echo "WooHoo! All done"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download