Datensicherung mit rsnapshot

Installation von rsnapshot

apt install rsnapshot

Rsnaphot über die Datei /etc/rsnapshot.conf konfigurieren. In diesem Beispiel 7 Tage, 4 Wochen ein Monat

#########################################
#     BACKUP LEVELS / INTERVALS         #
# Must be unique and in ascending order #
# e.g. alpha, beta, gamma, etc.         #
#########################################

retain  daily   7
retain  weekly  4
retain  monthly 1

Das Backup Verzeichnis angeben.

snapshot_root   /var/backups/homepages/

Unerwünschte Daten ausklammern

exclude /var/www/vhosts/*/httpdocs/moodledata
exclude /var/www/vhosts/system/*/statistics
exclude /var/www/vhosts/system/*/logs
Die Daten die gesichert werden sollen angeben.
backup          /home/          localhost/
backup          /etc/           localhost/
backup          /usr/local/     localhost/
backup          /var/www/       localhost/
backup          /root/          localhost/
backup          /opt/lms/       localhost/
backup  /opt/psa/admin/conf/    localhost/ #/opt/psa/ bei ausreichend Platz ca. 800MB

Mysql Datenbanken sichen

Vor den ausführen der Backups kann ein script ausgeführt werden welches z.B. alle Datenbanken sichert.

cmd_preexec     /usr/bin/lms_backupMySQL.sh
#!/bin/bash

cd /var/www/vhosts/databaseDumps/
mysql -N -e 'show databases' | while read dbname; do 
        mysqldump --single-transaction -C -Q -e --create-options "$dbname" > "$dbname".sql; 
        [[ $? -eq 0 ]] && gzip -f "$dbname".sql; 
done

Testen der Konfiguration

Mit dem Befehl rsnapshot und dem ersten „retain“ kann ein Backup getestet werden.

rsnapshot daily
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/bin/rsnapshot daily 
----------------------------------------------------------------------------
ERROR: /etc/rsnapshot.conf on line 73:
ERROR: cmd_preexec /usr/bin/lms_backupMySQL.sh - missing tabs to separate \
         words - change spaces to tabs. 
ERROR: /etc/rsnapshot.conf on line 167:
ERROR: exclude /var/www/vhosts/*/httpdocs/moodledata - missing tabs to \
         separate words - change spaces to tabs. 

An vielen stellen der Konfiguration muss ein Tab anstelle von Leerzeichen eingefügt werden.

Backup automatisch starten

rsnapshot hat bereits eine Datei /etc/cron.d/rsnapshot erstellt die angepasst werden muss. Oder man erstellt scripte in /etc/cron.daly weekly …

25 5    * * *   root    /usr/bin/rsnapshot daily
47 5    * * 7   root    /usr/bin/rsnapshot weekly 
52 5    1 * *   root    /usr/bin/rsnapshot monthly

Linux: Ubuntu 18.04.4
Plesk: Obsidian 18.0.25

Eine Antwort auf „Datensicherung mit rsnapshot“

Kommentare sind geschlossen.