我想每周制作一张快照并删除超过 7 天的快照,但同时我想保存一个月的快照。
有人知道如何编辑这些行来制作这个吗?
我每天都使用玉米来执行 ebs-snapshot.sh,我需要保存例如每月第一天制作的快照。
# How many days do you wish to retain backups for? Default: 7 days
retention_days="7"
retention_date_in_seconds=`date +%s --date "$retention_days days ago"`
[...]
# Purge all instance volume snapshots created by this script that are older than 7 days
for snapshot_id in $(cat /tmp/snapshot_info.txt)
do
echo "Checking $snapshot_id..."
snapshot_date=$(aws ec2 describe-snapshots --output=text --snapshot-ids $snapshot_id --query Snapshots[].StartTime | awk -F "T" '{printf "%s\n", $1}')
snapshot_date_in_seconds=`date "--date=$snapshot_date" +%s`
if (( $snapshot_date_in_seconds <= $retention_date_in_seconds )); then
echo "Deleting snapshot $snapshot_id ..." >> $logfile
aws ec2 delete-snapshot --snapshot-id $snapshot_id
else
echo "Not deleting snapshot $snapshot_id ..." >> $logfile
fi
done