README.md aktualisiert

This commit is contained in:
2025-07-18 09:14:58 +00:00
parent 486865dae6
commit c872ecd9a3

173
README.md
View File

@@ -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 # tar-multibackup
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
### 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 - konfigurierbaren Pre-/Post-Commands,
* `backup_destination` = Directory which is used to store the archives/backups - definierbaren Ausschlüssen (`--exclude`),
* `folders_to_backup` = Array of folders to backup - automatischem Aufräumen alter Backups (Retention),
* `backup_retention` = Retention time how long we should keep the backups - nutzerdefinierter Konfiguration via Datei.
* `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
### Environment configurations ---
* `DEBUG` = if set to "true", `set -x` will be set ## 🚀 Features
* `CONFIG` = if you want to use a different configuration file than the
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 ## ⚙️ Konfiguration
timestamp=$(date +%Y%m%d)
# Destination where you want to store your backups Die Konfigurationsdatei (Standard: `~/.multibackup.conf`) definiert das Backup-Verhalten.
backup_destination="/var/backups"
# Folders to backup Beispiel:
folders_to_backup=(
```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" "/etc"
"/var/mail"
"/var/www" "/var/www"
"/var/lib/mysql" "/var/lib/mysql"
"/var/spool/cron" )
"/var/lib/liveconfig"
)
# Files and folders that are excluded in the tar command # Pfade, die vom Backup ausgeschlossen werden sollen
tar_excludes=( tar_excludes=(
"tmp"
"nginx-php-fcgi.sock" "nginx-php-fcgi.sock"
) )
# Additional tar Options # Zusätzliche Optionen für tar
tar_options=() tar_options=""
# How long to you want to keep your backups (in days) # Wie lange Backups behalten werden (z.B. +7 für älter als 7 Tage)
backup_retention="+7" backup_retention="+7"
# Commands that are executed before the backup started # Vor dem Backup auszuführende Befehle
# (We have to make sure the liveconfig process is not running) pre_commands=(
# (otherwise the databases changes while we try to save it) "systemctl stop mysql"
pre_commands=( )
"service liveconfig stop"
)
# Commands that are executed after the backup is completed # Nach dem Backup auszuführende Befehle
# (To restart the liveconfig process again, once the backup is completed) post_commands=(
post_commands=( "systemctl start mysql"
"service liveconfig start" )
) ```
#### Cronjob setup ---
To make sure the backup is executed automatically and recurring, we're going to add a simple cronjob: ## 🧪 Nutzung
`vi /etc/cron.d/backup-liveconfig` ```bash
multibackup
```
# Mit alternativer Konfigurationsdatei und aktiviertem Debug-Modus:
# cronjob to backup LiveConfig, daily at 5:00 am
#
0 5 * * * root /usr/local/bin/multibackup &>/dev/null ```bash
CONFIG=/pfad/zur/konfig.conf DEBUG=true multibackup
```
#### CREDITS ---
This Backup Script is a fork of https://github.com/frdmn/tar-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.