AWS_PROFILE=example AWS_REGION=ap-northeast-1 DB_ID=db01 DB_SNAPSHOT_ID="${DB_ID}-$(date +%Y%m%d)" TAG_OWNER=user.name TAG_ISSUE=https://example.com/issues/12345 aws --profile $AWS_PROFILE --region $AWS_REGION rds create-db-snapshot --db-snapshot-identifier "$DB_SNAPSHOT_ID" --db-instance-identifier "$DB_ID" --tags "Key=Owner,Value=$TAG_OWNER" "Key=issue,Value=$TAG_ISSUE"
09:02:14 AM UTC+9 db01 Multi-AZ instance failover completed 09:01:49 AM UTC+9 db01 DB instance restarted 09:01:39 AM UTC+9 db01 Multi-AZ instance failover started
--preferred-backup-window $(LANG=C date -u -d "$MAINTENANCE_WINDOW 60 minutes ago" '+%H:%M')-$(LANG=C date -u -d "$MAINTENANCE_WINDOW 30 minutes ago" '+%H:%M') \
AWS_PROFILE=default AWS_REGION=ap-northeast-1 MAINTENANCE_WINDOW="2017-12-18 05:00 UTC" RDS_IDS="id1 id2" for id in $RDS_IDS; do \ aws rds modify-db-instance \ --db-instance-identifier $id \ --preferred-maintenance-window $(LANG=C date -u -d "$MAINTENANCE_WINDOW" '+%a:%H:%M')-$(LANG=C date -u -d "$MAINTENANCE_WINDOW 30 minutes" '+%a:%H:%M') \ --profile $AWS_PROFILE \ --region $AWS_REGION > ./${id}.json; \ done
AWS_PROFILE=default AWS_REGION=ap-northeast-1 DB_PARAMETER_GROUP_NAME=test DB_PARAMETER_GROUP_DESCRIPTION="For $DB_PARAMETER_GROUP_NAME" aws --profile $AWS_PROFILE --region $AWS_REGION rds create-db-parameter-group \ --db-parameter-group-name $DB_PARAMETER_GROUP_NAME \ --db-parameter-group-family mysql5.6 \ --description "$DB_PARAMETER_GROUP_DESCRIPTION" aws --profile $AWS_PROFILE --region $AWS_REGION rds modify-db-parameter-group \ --db-parameter-group-name $DB_PARAMETER_GROUP_NAME \ --parameters \ "ParameterName=max_connections,ParameterValue=1000,ApplyMethod=immediate" \ "ParameterName=max_connect_errors,ParameterValue=999999999,ApplyMethod=immediate" \ "ParameterName=character_set_client,ParameterValue=utf8mb4,ApplyMethod=immediate" \ "ParameterName=character_set_server,ParameterValue=utf8mb4,ApplyMethod=immediate" \ "ParameterName=collation_server,ParameterValue=utf8mb4_general_ci,ApplyMethod=immediate" \ "ParameterName=slow_query_log,ParameterValue=1,ApplyMethod=immediate" \ "ParameterName=long_query_time,ParameterValue=3,ApplyMethod=immediate" \ "ParameterName=max_heap_table_size,ParameterValue=$(expr 32 \* 1024 \* 1024),ApplyMethod=immediate" \ "ParameterName=tmp_table_size,ParameterValue=$(expr 32 \* 1024 \* 1024),ApplyMethod=immediate" \ "ParameterName=thread_cache_size,ParameterValue=32,ApplyMethod=immediate" \ "ParameterName=innodb_file_per_table,ParameterValue=1,ApplyMethod=immediate" \ "ParameterName=innodb_file_format,ParameterValue=Barracuda,ApplyMethod=immediate" \ "ParameterName=innodb_large_prefix,ParameterValue=1,ApplyMethod=immediate"
aws --profile $AWS_PROFILE --region $AWS_REGION rds reset-db-parameter-group \ --db-parameter-group-name $DB_PARAMETER_GROUP_NAME \ --no-reset-all-parameters \ --parameters "ParameterName=max_connections,ApplyMethod=immediate"
aws --profile default --region ap-northeast-1 rds describe-db-instances --query "DBInstances[].[DBInstanceIdentifier,EngineVersion,StorageType]" --output table ----------------------------------------------------- | DescribeDBInstances | +-----------------------------+----------+----------+ | example-db-01 | 5.5.40 | standard | | example-db-02 | 5.6.13 | gp2 | +-----------------------------+----------+----------+
AWS_PROFILE=default AWS_REGION=ap-northeast-1 AWS_MAINTENANCE_WINDOW=Mon:21:00-Mon:21:30 for id in $(aws --profile $AWS_PROFILE --region $AWS_REGION rds describe-db-instances --query "DBInstances[].[DBInstanceIdentifier]" --output text); do \ aws --profile $AWS_PROFILE --region $AWS_REGION rds modify-db-instance --preferred-maintenance-window $AWS_MAINTENANCE_WINDOW --db-instance-identifier $id; \ done
aws --region ap-northeast-1 rds describe-db-snapshots --snapshot-type manual
管理コンソールからは過去2日分しか見えないが、awscliならそれ以上に取得できる。
AWS_PROFILE=default AWS_REGION=ap-northeast-1 RDS_ID=db1 aws rds describe-events \ --source-identifier $RDS_ID --source-type db-instance --start-time "$(date -u +%Y-%m-%d)T00:00:00" \ --query 'Events[].[Date,Message]' \ --profile $AWS_PROFILE \ --region $AWS_REGION \ --output text 2021-01-01T00:12:11.000000+00:00 Backing up DB instance 2021-01-02T00:13:22.000000+00:00 Finished DB Instance backup
AWS_PROFILE=default for region in $(aws --profile $AWS_PROFILE ec2 describe-regions --query "Regions[].[RegionName]" --output text); do \ for i in $(aws --profile $AWS_PROFILE --region $region rds describe-db-parameter-groups --query 'DBParameterGroups[?contains(DBParameterGroupFamily, `mysql`)].[DBParameterGroupName]' --output text); do \ echo "$region, $i"; \ done \ done