如何使用 Cron 选项卡每晚进行 MySQL 数据库备份并将其放入 Amazon s3 中?
我在 Rackspace 中有一台服务器,并且我已经在每天晚上运行一个 cron 作业来处理一些东西......(一些与帐户相关的操作 - 每个午夜都会向我发送电子邮件)。我的应用程序是在 groovy on grails 中。现在我想在每个午夜备份 mysql 数据库(称为 myfleet)并将该文件放入 Amezon S3 中。我怎样才能做到这一点?我需要编写任何 java 或 groovy 文件来处理它吗?或者可以从 Linux 盒子本身完成吗?我已经在 Amezon S3 中拥有帐户(存储桶名称为fleetBucket)
I have got one server in Rackspace and i'm already running a cron job evry day night to process something...(some account related operation- that will send me email every mid night). my application is in groovy on grails. now i want to take mysql database (called myfleet) backup on every mid night and put that file in Amezon S3 . how can i do that? do i need to write any java or groovy file to process that? or is it can be done from Linux box itself? i have already got account in Amezon S3 (bucket name is fleetBucket)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
AWS CLI 工具 将 mysqldump 的输出直接通过管道传送到 S3:
您还可以使用 STDOUT 和 示例:
mysqldump 命令默认输出到 STDOUT。使用
-
作为aws s3 cp
的输入参数告诉 AWS CLI 工具使用 STDIN 作为输入。You can also use STDOUT and the AWS CLI tool to pipe the output of your mysqldump straight to S3:
For example:
The mysqldump command outputs to STDOUT by default. Using
-
as the input argument foraws s3 cp
tells the AWS CLI tool to use STDIN for the input.将直接将文件存储到s3。
will directly store file to s3.
应该非常简单:
- 使用 mysqldump 备份数据库
- 使用命令行客户端将转储文件上传到 S3(例如 http://s3tools.org/s3cmd :
s3cmd put myfleet.sql.gz s3:///myfleet.sql.gz
只需将其添加到您的 cron 作业中(您可能希望对转储文件使用某种编号方案,以防您想保留多个版本)。
Should be pretty straightforward:
- backup your database using mysqldump
- upload your dump file to S3 using a command line client (e.g. http://s3tools.org/s3cmd:
s3cmd put myfleet.sql.gz s3://<bucketname>/myfleet.sql.gz
Just add this to your cron job (you might want to use some kind of numbering scheme for the dump files, in case you want to keep several versions).
如果源数据库位于 AWS 上并且类型为 Aurora.Mysql,您可以使用类似 See
。 Integrating.SaveIntoS3.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.SaveIntoS3.html 了解详细信息。
If the source DB is on AWS and is of type Aurora.Mysql you can backup directly to S3 with a command like
See https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.SaveIntoS3.html for details.