Initial infra setup: Terraform, Ansible, backup roles

This commit is contained in:
Ryan Moon
2026-03-31 08:11:12 -05:00
commit d6ff4746d0
31 changed files with 792 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
#!/bin/bash
set -euo pipefail
DATE=$(date +%Y-%m-%d)
MONTH=$(date +%Y-%m)
DAY_OF_MONTH=$(date +%d)
echo "[$(date)] Starting backup"
{% for item in backup_dirs %}
echo "[$(date)] Backing up {{ item.src }}"
# Daily backup — kept for 30 days
rclone sync {{ item.src }} spaces://{{ backup_bucket }}/{{ item.dest }}/daily/${DATE} \
--s3-acl private
# Monthly backup on the 1st — kept for 12 months
if [ "${DAY_OF_MONTH}" = "01" ]; then
rclone sync {{ item.src }} spaces://{{ backup_bucket }}/{{ item.dest }}/monthly/${MONTH} \
--s3-acl private
echo "[$(date)] Monthly backup complete for {{ item.src }}"
fi
# Prune daily backups older than 30 days
rclone delete spaces://{{ backup_bucket }}/{{ item.dest }}/daily \
--min-age 30d --s3-acl private
# Prune monthly backups older than 12 months
rclone delete spaces://{{ backup_bucket }}/{{ item.dest }}/monthly \
--min-age 365d --s3-acl private
{% endfor %}
echo "[$(date)] Backup complete"