python - 如何在同一脚本中安排 RDS 快照和还原
问题描述
所以我正在安排一个 AWS python 作业(通过 AWS Glue Python shell),它应该克隆 MySQL RDS 数据库(拍摄快照和恢复的最佳方式?)并对数据库执行 sql 查询。我在 Python Shell 上有 boto3 库和我加载的 SQL Python 库。我目前有这个代码
import boto3
client = boto3.client('rds')
# Create a snapshot of the database
snapshot_response = client.create_db_snapshot(
DBSnapshotIdentifier='snapshot-identifier',
DBInstanceIdentifier='instance-db',
)
# Restore db from snapshot
restore_response = client.restore_db_instance_from_db_snapshot(
DBInstanceIdentifier = 'restored-db',
DBSnapshotIdentifier = 'snapshot-identifier',
)
# Code that will perform sql queries on the restored-db database.
但是,client.restore_db_instance_from_db_snapshot
失败是因为它说正在创建快照。所以我明白这意味着这些调用是异步的。但我不确定如何让这个快照恢复工作(通过使它们同步 - 不是一个好主意?)或通过其他方式。我在这里先向您的帮助表示感谢 :)。
解决方案
您可以使用服务员:
waiter = client.get_waiter('db_cluster_snapshot_available')
每 30 秒轮询
RDS.Client.describe_db_cluster_snapshots()
一次,直到达到成功状态。60 次检查失败后返回错误。
推荐阅读
- azure - Azure Web 作业在访问共享位置时被拒绝访问
- python-3.x - Folium:不在 Jupyter 中显示地图
- javascript - HTML表格搜索在搜索字段没有值后获取最后一行字段内容
- svn - SVN 使用 GREP 和 REGEX 删除文件
- macos - MacOS:iterm2、zsh 取消进程与 control + c 不起作用,但它与 control + m 或 control + shift + c 一起工作
- angular - Angular5CSV格式直接在excel中使用分隔符?
- python - 根据另一列中的值创建重复递增序列
- math - 需要数学辅助:将 Arduino 模拟输入缩放为 -1 到 1
- botframework - 创建身份验证连接失败
- sharepoint-online - SharePoint Online:在新式页面的同一选项卡中打开链接的 Web 部件