42 lines
1.5 KiB
Bash
Executable File
42 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Erstellt Backups der UniFi Network Application.
|
|
#
|
|
# ./backup.sh Kopiert die UniFi-Autobackups (.unf) nach ./backups/
|
|
# ./backup.sh --full Komplett-Backup: stoppt die Container und packt das
|
|
# gesamte ./data-Verzeichnis als tar.gz nach ./backups/
|
|
#
|
|
# .unf-Dateien lassen sich über die UniFi-Weboberfläche wiederherstellen,
|
|
# das Komplett-Backup über ./restore.sh
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")"
|
|
|
|
BACKUP_DIR="./backups"
|
|
AUTOBACKUP_DIR="./data/unifi/data/backup/autobackup"
|
|
STAMP="$(date +%Y-%m-%d_%H-%M-%S)"
|
|
mkdir -p "$BACKUP_DIR"
|
|
|
|
if [[ "${1:-}" == "--full" ]]; then
|
|
echo "==> Komplett-Backup: Container werden kurz gestoppt..."
|
|
docker-compose stop
|
|
tar czf "$BACKUP_DIR/unifi-full-backup_${STAMP}.tar.gz" data
|
|
docker-compose start
|
|
echo "==> Fertig: $BACKUP_DIR/unifi-full-backup_${STAMP}.tar.gz"
|
|
else
|
|
if [[ -d "$AUTOBACKUP_DIR" ]] && compgen -G "$AUTOBACKUP_DIR/*.unf" > /dev/null; then
|
|
DEST="$BACKUP_DIR/autobackup_${STAMP}"
|
|
mkdir -p "$DEST"
|
|
cp "$AUTOBACKUP_DIR"/*.unf "$DEST/"
|
|
echo "==> UniFi-Autobackups kopiert nach: $DEST"
|
|
ls -lh "$DEST"
|
|
else
|
|
echo "Noch keine Autobackups vorhanden ($AUTOBACKUP_DIR)."
|
|
echo "Autobackups in der UniFi-Weboberfläche aktivieren:"
|
|
echo " Einstellungen -> System -> Backups -> Automatische Sicherung"
|
|
echo "Alternativ Komplett-Backup erstellen mit: ./backup.sh --full"
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "Vorhandene Backups in $BACKUP_DIR:"
|
|
ls -lh "$BACKUP_DIR" | tail -n +2 || true
|