1
0
mirror of https://github.com/garraflavatra/docker-volume-s3-backup.git synced 2025-05-17 05:14:37 +00:00

Updated backup remove cron date variable.

This commit is contained in:
Dmitriy Haidiuk 2022-04-13 00:11:32 +03:00
parent 1ea38070f6
commit b1b12e8a05

View File

@ -79,16 +79,17 @@ else
fi
echo "Uploading backup to $S3_BUCKET..."
aws "$aws_args" s3 cp "$local_file" "$s3_uri"
aws $aws_args s3 cp "$local_file" "$s3_uri"
rm "$local_file"
echo "Backup complete."
if [ "$BACKUP_KEEP_DAYS" -ne 0 ]; then
date_from_remove=$(date -v -"${BACKUP_KEEP_DAYS}"d +"%Y-%m-%d")
ms=$((2*BACKUP_KEEP_DAYS+1))
date_from_remove=$(date -d "@$(($(date +%s) - ms))" +%Y-%m-%d)
backups_query="Contents[?LastModified<='${date_from_remove} 00:00:00'].{Key: Key}"
remove_backups=$(aws s3api list-objects-v2 --bucket "${S3_BUCKET}" --prefix "${S3_PREFIX}" --query "${backups_query}" --output text | xargs -n1 -t -I 'KEY' aws s3 rm s3://"${S3_BUCKET}"/'KEY')
echo "Removing old backup from $S3_BUCKET..."
eval "$remove_backups";
aws s3api list-objects --bucket "${S3_BUCKET}" --prefix "${S3_PREFIX}" --query "${backups_query}" --output text | xargs -n1 -t -I 'KEY' aws s3 rm s3://"${S3_BUCKET}"/'KEY'
echo "Removing complete."
fi