Files
tar-multibackup/README.md

140 lines
3.0 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# tar-multibackup
Ein einfaches, aber flexibles Bash-Skript zur Sicherung mehrerer Verzeichnisse mit `tar`, inklusive:
- konfigurierbaren Pre-/Post-Commands,
- definierbaren Ausschlüssen (`--exclude`),
- automatischem Aufräumen alter Backups (Retention),
- nutzerdefinierter Konfiguration via Datei.
---
## 🚀 Features
- Sicherung beliebig vieler Verzeichnisse via `tar`
- Konfigurierbare Ausschlüsse (`--exclude`)
- Vor- und Nachbearbeitungsbefehle (z.B. Dienste stoppen/starten)
- Aufbewahrungsdauer für Backups festlegbar
- Lesbare Log-Ausgabe mit Status-Infos und Farbcodierung
- Unterstützung für eigene Konfigurationsdateien per Umgebungsvariable
- Optionales Debugging via `DEBUG=true`
---
## 🛠️ Installation
```bash
cd /usr/local/src
git clone https://gitea.gnilebein.de/gnilebein/tar-multibackup.git
ln -sf /usr/local/src/tar-multibackup/multibackup /usr/local/bin/multibackup
chmod +x /usr/local/src/tar-multibackup/multibackup
cp /usr/local/src/tar-multibackup/multibackup.conf ~/.multibackup.conf
```
---
## ⚙️ Konfiguration
Die Konfigurationsdatei (Standard: `~/.multibackup.conf`) definiert das Backup-Verhalten.
Beispiel:
```bash
# Zeitstempel im Dateinamen
timestamp=$(date +%Y%m%d)
# Zielverzeichnis für Backups
backup_destination="/var/backups"
# Verzeichnisse, die gesichert werden sollen
folders_to_backup=(
"/etc"
"/var/www"
"/var/lib/mysql"
)
# Pfade, die vom Backup ausgeschlossen werden sollen
tar_excludes=(
"tmp"
"nginx-php-fcgi.sock"
)
# Zusätzliche Optionen für tar
tar_options=""
# Wie lange Backups behalten werden (z.B. +7 für älter als 7 Tage)
backup_retention="+7"
# Vor dem Backup auszuführende Befehle
pre_commands=(
"systemctl stop mysql"
)
# Nach dem Backup auszuführende Befehle
post_commands=(
"systemctl start mysql"
)
```
---
## 🧪 Nutzung
```bash
multibackup
```
Mit alternativer Konfigurationsdatei und aktiviertem Debug-Modus:
```bash
CONFIG=/pfad/zur/konfig.conf DEBUG=true multibackup
```
---
## 📅 Cronjob-Einrichtung
Für tägliche automatische Backups z.B. um 05:00 Uhr:
```cron
# /etc/cron.d/backup-daily
0 5 * * * root /usr/local/bin/multibackup &>/dev/null
```
---
## 🌐 Umgebungsvariablen
| Variable | Beschreibung |
|----------|--------------|
| `DEBUG` | Aktiviert Bash-Debug-Ausgabe (`set -x`) |
| `CONFIG` | Pfad zu alternativer Konfigurationsdatei |
---
## ✅ Beispielausgabe
```text
[pre-command] [1/1] [INFO] Running "systemctl stop mysql":
[pre-command] [1/1] [SUCCESS] Pre command "systemctl stop mysql" successfully completed!
[backup] [1/3] [INFO] Starting backup "/var/backups/etc/20250718.tar.gz"
[backup] [1/3] [SUCCESS] Backup "/var/backups/etc/20250718.tar.gz" successfully completed!
...
[post-command] [1/1] [INFO] Running "systemctl start mysql":
[post-command] [1/1] [SUCCESS] Post command "systemctl start mysql" successfully completed!
```
---
## 🙏 Credits
Dieses Skript ist ein Fork von:
**https://github.com/frdmn/tar-multibackup**
---
## 📝 Lizenz
MIT License Frei nutzbar, aber ohne Gewähr.