AWS数据库备份RDS到S3通过Crontab(Cron作业)

时间:2017-09-19 14:07:05

标签: php bash amazon-web-services amazon-s3 cron

我想使用cron job在每日基础上创建数据库备份。

我为数据库备份创建了一个批处理文件。下面是批处理文件代码。

#!/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"    

但数据库备份不存储在S3上。

文件路径:var / app / current / app / sqlbackup.sh

在Crontab中设置5小时:* 5 * * * / bin / sh /var/app/current/app/sqlbackup.sh

1 个答案:

答案 0 :(得分:4)

您可能没有在AWS服务器中设置s3cmd软件包。所以请检查以下所有设置。所以我认为你有帮助点:

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

输入新值或接受括号中的默认值,参见用户手册,了解所有选项的详细说明。

有关详细信息,请查看以下链接: - https://tecadmin.net/install-s3cmd-manage-amazon-s3-buckets/#

批处理文件检查: - 文件名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"