b9be45dc71
Complete IaC covering: - 14 roles: common, docker, traefik, vaultwarden, monitoring, media, matrix, home_assistant, frigate, adguard, gitea, semaphore, openclaw, security, backup - Inventory for all hosts (Peggy, Bart, Yoda, NAS, Firewalla) - Stack playbooks: core-infrastructure, monitoring, media, communication, automation, smarthome, security-hardening - Maintenance playbooks: update-containers, backup, health-check - Production Docker Compose templates with Traefik labels - Security hardening (sysctl, auditd, UFW, fail2ban) - Automated backups with retention policy
43 lines
1.1 KiB
Django/Jinja
43 lines
1.1 KiB
Django/Jinja
#!/bin/bash
|
|
# Homelab Backup Script - Managed by Ansible
|
|
# Host: {{ inventory_hostname }}
|
|
|
|
set -euo pipefail
|
|
|
|
BACKUP_DIR="{{ backup_destination }}"
|
|
DATE=$(date +%Y%m%d_%H%M%S)
|
|
HOSTNAME="{{ inventory_hostname }}"
|
|
BACKUP_FILE="${BACKUP_DIR}/${HOSTNAME}_${DATE}.tar.gz"
|
|
RETENTION_DAYS="{{ backup_retention_days }}"
|
|
|
|
echo "=== Backup started at $(date) ==="
|
|
echo "Destination: ${BACKUP_FILE}"
|
|
|
|
# Pre-backup commands
|
|
{% for cmd in backup_pre_commands %}
|
|
echo "Running pre-backup: {{ cmd }}"
|
|
{{ cmd }}
|
|
{% endfor %}
|
|
|
|
# Create backup
|
|
tar czf "${BACKUP_FILE}" \
|
|
{% for source in backup_sources %}
|
|
{{ source }} \
|
|
{% endfor %}
|
|
2>/dev/null || true
|
|
|
|
BACKUP_SIZE=$(du -sh "${BACKUP_FILE}" | cut -f1)
|
|
echo "Backup created: ${BACKUP_FILE} (${BACKUP_SIZE})"
|
|
|
|
# Post-backup commands
|
|
{% for cmd in backup_post_commands %}
|
|
echo "Running post-backup: {{ cmd }}"
|
|
{{ cmd }}
|
|
{% endfor %}
|
|
|
|
# Cleanup old backups
|
|
echo "Removing backups older than ${RETENTION_DAYS} days..."
|
|
find "${BACKUP_DIR}" -name "${HOSTNAME}_*.tar.gz" -mtime +${RETENTION_DAYS} -delete
|
|
|
|
echo "=== Backup completed at $(date) ==="
|