因此,我正在计划一个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')
RDS.Client.describe_db_cluster_snapshots()
每30秒轮询一次,直到达到成功状态。60次检查失败后返回错误。