From c872ecd9a302897ca1782c8cfe7bf9942690b16d Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Fri, 18 Jul 2025 09:14:58 +0000 Subject: [PATCH] README.md aktualisiert --- README.md | 181 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 115 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 745345c..bc3084a 100644 --- a/README.md +++ b/README.md @@ -1,90 +1,139 @@ -tar-multibackup -=============== -Bash script to backup multiple folders and to clean up old backups based on a retention time. Features configurable post/pre-commands, tar excludes as well as backup retentions. -### Installation - 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 multibackup - cp /usr/local/src/tar-multibackup/multibackup.conf ~/.multibackup.conf +# tar-multibackup -### Configuration and usage +Ein einfaches, aber flexibles Bash-Skript zur Sicherung mehrerer Verzeichnisse mit `tar`, inklusive: -* `timestamp` = Format of the timestamp, used in the backup target filename -* `backup_destination` = Directory which is used to store the archives/backups -* `folders_to_backup` = Array of folders to backup -* `backup_retention` = Retention time how long we should keep the backups -* `pre_commands` = Array of commands that are executed before the backup starts (stop specific service) -* `post_commands` = Array of commands that are executed after the backup finished (start specific service) -* `tar_options` = Additional tar Options +- konfigurierbaren Pre-/Post-Commands, +- definierbaren Ausschlüssen (`--exclude`), +- automatischem Aufräumen alter Backups (Retention), +- nutzerdefinierter Konfiguration via Datei. -### Environment configurations +--- -* `DEBUG` = if set to "true", `set -x` will be set -* `CONFIG` = if you want to use a different configuration file than the +## 🚀 Features -Example: +- 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` - CONFIG=/tmp/testbackup.conf DEBUG=true multibackup +--- -#### Example configuration +## 🛠️ Installation -In the example below you can find a `multibackup` configuration file to backup a productional [LiveConfig](http://www.liveconfig.com/) instance. +```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 +``` -`vi ~/.multibackup.conf` +--- - # Timestamp format, used in the backup target filename - timestamp=$(date +%Y%m%d) +## ⚙️ Konfiguration - # Destination where you want to store your backups - backup_destination="/var/backups" +Die Konfigurationsdatei (Standard: `~/.multibackup.conf`) definiert das Backup-Verhalten. - # Folders to backup - folders_to_backup=( - "/etc" - "/var/mail" - "/var/www" - "/var/lib/mysql" - "/var/spool/cron" - "/var/lib/liveconfig" - ) +Beispiel: - # Files and folders that are excluded in the tar command - tar_excludes=( - "nginx-php-fcgi.sock" - ) +```bash +# Zeitstempel im Dateinamen +timestamp=$(date +%Y%m%d) - # Additional tar Options - tar_options=() +# Zielverzeichnis für Backups +backup_destination="/var/backups" - # How long to you want to keep your backups (in days) - backup_retention="+7" +# Verzeichnisse, die gesichert werden sollen +folders_to_backup=( + "/etc" + "/var/www" + "/var/lib/mysql" +) - # Commands that are executed before the backup started - # (We have to make sure the liveconfig process is not running) - # (otherwise the databases changes while we try to save it) - pre_commands=( - "service liveconfig stop" - ) +# Pfade, die vom Backup ausgeschlossen werden sollen +tar_excludes=( + "tmp" + "nginx-php-fcgi.sock" +) - # Commands that are executed after the backup is completed - # (To restart the liveconfig process again, once the backup is completed) - post_commands=( - "service liveconfig start" - ) +# Zusätzliche Optionen für tar +tar_options="" -#### Cronjob setup +# Wie lange Backups behalten werden (z. B. +7 für älter als 7 Tage) +backup_retention="+7" -To make sure the backup is executed automatically and recurring, we're going to add a simple cronjob: +# Vor dem Backup auszuführende Befehle +pre_commands=( + "systemctl stop mysql" +) -`vi /etc/cron.d/backup-liveconfig` +# Nach dem Backup auszuführende Befehle +post_commands=( + "systemctl start mysql" +) +``` - # - # cronjob to backup LiveConfig, daily at 5:00 am - # +--- - 0 5 * * * root /usr/local/bin/multibackup &>/dev/null +## 🧪 Nutzung -#### CREDITS -This Backup Script is a fork of https://github.com/frdmn/tar-multibackup \ No newline at end of file +```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.