README.md aktualisiert
This commit is contained in:
151
README.md
151
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
|
# 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
|
cd /usr/local/src
|
||||||
git clone https://gitea.gnilebein.de/gnilebein/tar-multibackup.git
|
git clone https://gitea.gnilebein.de/gnilebein/tar-multibackup.git
|
||||||
ln -sf /usr/local/src/tar-multibackup/multibackup /usr/local/bin/multibackup
|
ln -sf /usr/local/src/tar-multibackup/multibackup /usr/local/bin/multibackup
|
||||||
chmod +x multibackup
|
chmod +x /usr/local/src/tar-multibackup/multibackup
|
||||||
cp /usr/local/src/tar-multibackup/multibackup.conf ~/.multibackup.conf
|
cp /usr/local/src/tar-multibackup/multibackup.conf ~/.multibackup.conf
|
||||||
|
```
|
||||||
|
|
||||||
### Configuration and usage
|
---
|
||||||
|
|
||||||
* `timestamp` = Format of the timestamp, used in the backup target filename
|
## ⚙️ Konfiguration
|
||||||
* `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
|
|
||||||
|
|
||||||
### Environment configurations
|
Die Konfigurationsdatei (Standard: `~/.multibackup.conf`) definiert das Backup-Verhalten.
|
||||||
|
|
||||||
* `DEBUG` = if set to "true", `set -x` will be set
|
Beispiel:
|
||||||
* `CONFIG` = if you want to use a different configuration file than the
|
|
||||||
|
|
||||||
Example:
|
```bash
|
||||||
|
# Zeitstempel im Dateinamen
|
||||||
CONFIG=/tmp/testbackup.conf DEBUG=true multibackup
|
|
||||||
|
|
||||||
#### Example configuration
|
|
||||||
|
|
||||||
In the example below you can find a `multibackup` configuration file to backup a productional [LiveConfig](http://www.liveconfig.com/) instance.
|
|
||||||
|
|
||||||
`vi ~/.multibackup.conf`
|
|
||||||
|
|
||||||
# Timestamp format, used in the backup target filename
|
|
||||||
timestamp=$(date +%Y%m%d)
|
timestamp=$(date +%Y%m%d)
|
||||||
|
|
||||||
# Destination where you want to store your backups
|
# Zielverzeichnis für Backups
|
||||||
backup_destination="/var/backups"
|
backup_destination="/var/backups"
|
||||||
|
|
||||||
# Folders to backup
|
# Verzeichnisse, die gesichert werden sollen
|
||||||
folders_to_backup=(
|
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)
|
|
||||||
# (otherwise the databases changes while we try to save it)
|
|
||||||
pre_commands=(
|
pre_commands=(
|
||||||
"service liveconfig stop"
|
"systemctl stop mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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=(
|
||||||
"service liveconfig start"
|
"systemctl start mysql"
|
||||||
)
|
)
|
||||||
|
```
|
||||||
|
|
||||||
#### 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
|
|
||||||
#
|
|
||||||
|
|
||||||
|
```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
|
0 5 * * * root /usr/local/bin/multibackup &>/dev/null
|
||||||
|
```
|
||||||
|
|
||||||
#### CREDITS
|
---
|
||||||
This Backup Script is a fork of https://github.com/frdmn/tar-multibackup
|
|
||||||
|
## 🌐 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.
|
||||||
|
|||||||
Reference in New Issue
Block a user