欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用shell和aws cli自动备份RDS并发消息到SQS

程序员文章站 2022-04-17 23:19:52
...

#!/bin/bash

 

da=`date +%y%m%d`

su - oracle <<EON

#sh /RDSBackup/scripts/asdp-backup.sh &

 

for child in `ps -ef|grep "$$"|grep -v grep|grep -v "$PPID"|awk '{print $2}'`

do

wait $child

echo "process $child exited"

done

wait

echo "All backup is finished!!!"

EON

 

echo "$da"

 

aws s3 cp /RDSBackup/asdp_full_$da.dmp.zip s3://rds-database-backup/backup-all-for3y/asdp_full_$da.dmp.zip

 

rm -f /RDSBackup/*$da.dmp.gz

echo "Uploading file to S3 is finished!!!"

##### Send finished message to SQS ########

var=`ec2-metadata -i`

echo ${var:13}

aws sqs send-message --queue-url https://sqs.cn-north-1.amazonaws.com.cn/827768676943/rds-backup-terminate --message-body ${var:13} --delay-seconds 10