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.
#!/bin/bash
SQLDUMP="$(date +'%Y%m%d%H%M').sql.gz"
echo "Creating backup of database to $SQLDUMP"
mysqldump --host 'myhost.com' -u 'root' -p 'password' --databases 'test' | gzip -9 > $SQLDUMP
echo "Dump Zipped up"
echo "Uploading zipped dump to the Amazon S3 bucket…"
s3cmd put $BACKUPNAME s3://example.com/dbbackup/$BACKUPNAME
echo "Removing the backup file $SQLDUMP"
rm $BACKUPNAME
echo "Done"
But database backup not storage on S3.
File Path : var/app/current/app/sqlbackup.sh
Set for 5 hrs in Crontab : * 5 * * * /bin/sh /var/app/current/app/sqlbackup.sh
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 http://s3tools.org/repo/SLE_11/s3tools.repo
# zypper install s3cmd
Setup :- 2
Install Latest s3cmd using Source
$ wget http://ufpr.dl.sourceforge.net/project/s3tools/s3cmd/1.6.1/s3cmd-1.6.1.tar.gz
$ tar xzf s3cmd-1.6.1.tar.gz
Now install it using below command with source files.
$ cd s3cmd-1.6.1
$ sudo python setup.py 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 :- https://tecadmin.net/install-s3cmd-manage-amazon-s3-buckets/#
Batch file check :- File name sqlbackup.sh
#!/bin/bash
SQLDUMP="$(date +'%Y%m%d%H%M').sql.gz"
SQLDUMPPATH="/backupdb/$SQLDUMP"
mysqldump -pPASSWORD -u root -h HOST.amazonaws.com database_name | gzip -9 > $SQLDUMPPATH
s3cmd put $SQLDUMPPATH s3://S3NAME/dbbackup/$SQLDUMP
echo "Removing the backup file $SQLDUMP"
rm $SQLDUMPPATH
echo "WooHoo! All done"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.