week=$(date +%u)
day=$(date +%d)
month=$(date +%m)
year=$(date +%Y)
if [ "$day" -eq "1" ]; then
target_dir="monthly-backup"
elif [ "$week" -eq "1" ]; then
target_dir="weekly-backup"
else
target_dir="daily-backup"
fi
pg_backupcluster 12 tanmer basebackup && \
us3cli sync /var/backups/postgresql/12-tanmer/ us3://tanmer-backup/${target_dir}/pg-12-tanmer --storageclass "ARCHIVE" --config tanmer && \
pg_backupcluster 12 tanmer expirebasebackups 0
通过上面脚本,可以按天、周、月备份到 UCloud 的 S3 上面,然后在 UCloud 后台分别设置目录下文件的生存周期,即可实现自动删除过期的备份文件