rsnapshot Backup wiederherstellen
Support Wissensdatenbank
rsnapshot Backup wiederherstellen
Wenn ein rsync oder auch ein rsnapshot Backup zurück gespielt werden soll, muss es ganz schnell gehen. Dazu haben wir beiliegende Scripte erstellt, um möglichst schnell die Daten zurück zu spielen. Beide Scripts können parallel ausgeführt werden um die Web- und Emaildaten gleichzeitig zurück zu spielen. Das Script startet mehrere parallele Prozesse um die Wiederherstellung zu beschleunign. Voraussetzung dafür ist, dass der Backupserver über einen SSH Key auf den Zielserver zugreifen kann.
Voraussetzungen:
– rsnapshot Backup
– SSH Key beim Zielserver hinterlegt
– Plesk Server
Das Skript startet x festgelegte Rsync Prozesse. Das Skript kann für jeden beliebigen Pfad angepasst werden. Zb. Kann man “realpath” AUF “/var/lib/mysql” angepasst werden um jede Datenbank vom Dateibackup einzeln zurückzuspielen. Mit sshkey kann auch SSH-Backupkey ausgetauscht werden.
Webdateien wiederherstellen (webrestore.sh):
#!/bin/bash #Settings process_limit=40 # Max amount of rsync processes server="sr00" # Server according to Backup path /volume1/backup/{$server} daily="0" # Daily number according to backup path starting with 0 like daily.0 /volume1/backup/$server/daily.{$daily} remote="sr00.firestorm.ch" # URL or IP of Target Server. sshkey="/root/.ssh/backupkey" # Rsync SSH Key backuppath="/volume1/backup/$server/daily.$daily/$server" # Source backup path from rsnapshot (No tailing slashes) realpath="/var/www/vhosts" # Server Source location (No tailing slashes) #Processes Array processes=() function check_processes { #For Each Rsync Process for pid in "${processes[@]}"; do #If Process has died / ended if ! ps -p $pid > /dev/null ; then #For Each Numbered Process Array for i in "${!processes[@]}"; do #If numberes Process equals died process if [[ ${processes[i]} = $pid ]]; then #Remove Process from array unset 'processes[i]' fi done fi done } #For Each Website in Backup for folder in $backuppath$realpath/* ; do domain="$(basename $folder)" /bin/echo "##############################" #wait if more than 30 processes while [ ${#processes[@]} -gt $process_limit ] do check_processes /bin/sleep 5s done /bin/echo "/bin/rsync --stats --progress -avz --delete $folder/ root@$server.firestorm.ch:$realpath/$domain/ (${#processes[@]} / $process_limit)" /bin/rsync --stats --progress -avz --delete -e "ssh -p 22 -i $sshkey" $folder/ root@$remote:$realpath/$domain/ & processes+=($!) done
Emails wiederherstellen (mailrestore.sh):
#!/bin/bash #Settings process_limit=40 # Max amount of rsync processes server="sr00" # Server according to Backup path /volume1/backup/{$server} daily="0" # Daily number according to backup path starting with 0 like daily.0 /volume1/backup/$server/daily.{$daily} remote="sr00.firestorm.ch" # URL or IP of Target Server. sshkey="/root/.ssh/backupkey" # Rsync SSH Key backuppath="/volume1/backup/$server/daily.$daily/$server" # Source backup path (No tailing slashes) realpath="/var/qmail/mailnames" # Server Source location (No tailing slashes) #Processes Array processes=() function check_processes { #For Each Rsync Process for pid in "${processes[@]}"; do #If Process has died / ended if ! ps -p $pid > /dev/null ; then #For Each Numbered Process Array for i in "${!processes[@]}"; do #If numberes Process equals died process if [[ ${processes[i]} = $pid ]]; then #Remove Process from array unset 'processes[i]' fi done fi done } #For Each Mailname in Backup for folder in $backuppath$realpath/* ; do domain="$(basename $folder)" /bin/echo "##############################" #wait if more than 30 processes while [ ${#processes[@]} -gt $process_limit ] do check_processes /bin/sleep 5s done /bin/echo "/bin/rsync --stats --progress -avz --delete $folder/ root@$server.firestorm.ch:$realpath/$domain/ (${#processes[@]} / $process_limit)" /bin/rsync --stats --progress -avz --delete -e "ssh -p 22 -i $sshkey" $folder/ root@$remote:$realpath/$domain/ & processes+=($!) done
DB wiederherstellen:
#!/bin/bash #Settings process_limit=30 # Max amount of rsync processes server="sr00" # Server according to Backup path /volume1/backup/{$server} daily="0" # Daily number according to backup path starting with 0 like daily.0 /volume1/backup/$server/daily.{$daily} remote="sr00.firestorm.ch" # URL or IP of Target Server. sshkey="/root/.ssh/backupkey" # Rsync SSH Key backuppath="/volume1/backup/$server/daily.$daily/$server" # Source backup path (No tailing slashes) realpath="/var/lib/mysql" # Server Source location (No tailing slashes) #Processes Array processes=() function check_processes { #For Each Rsync Process for pid in "${processes[@]}"; do #If Process has died / ended if ! ps -p $pid > /dev/null ; then #For Each Numbered Process Array for i in "${!processes[@]}"; do #If numberes Process equals died process if [[ ${processes[i]} = $pid ]]; then #Remove Process from array unset 'processes[i]' fi done fi done } #For Each Mailname in Backup for folder in $backuppath$realpath/* ; do domain="$(basename $folder)" /bin/echo "##############################" #wait if more than 30 processes while [ ${#processes[@]} -gt $process_limit ] do check_processes /bin/sleep 5s done /bin/echo "/bin/rsync --stats --progress -avz --delete $folder/ root@$server.firestorm.ch:$realpath/$domain/ (${#processes[@]} / $process_limit)" /bin/rsync --stats --progress -avz --delete -e "ssh -p 22 -i $sshkey" $folder/ root@$remote:$realpath/$domain/ & processes+=($!) done
Einfaches Beispiel um von Ordner zu Ordner zu kopieren:
#!/bin/bash # Einstellungen process_limit=25 backuppath1="/destinationfolder/var/www/" realpath="/var/www/" # Prozess-Array processes=() # Funktion zum Überprüfen der laufenden Prozesse function check_processes { local temp_array=() for pid in "${processes[@]}"; do if ps -p $pid > /dev/null ; then temp_array+=($pid) else echo "Prozess $pid ist abgeschlossen, wird entfernt." fi done processes=("${temp_array[@]}") echo "Laufende Prozesse: ${#processes[@]}/$process_limit" } # Hauptloop for folder in $backuppath1/* ; do foldername=$(basename "$folder") echo "##############################" while [ "${#processes[@]}" -ge "$process_limit" ]; do check_processes sleep 5s done rsync_command="/usr/bin/rsync --stats --progress -az $realpath$foldername/ $backuppath1$foldername" echo "$rsync_command (${#processes[@]}/$process_limit)" $rsync_command & pid=$! processes+=("$pid") echo "Rsync-Prozess $pid für Ordner $foldername gestartet. (${#processes[@]}/$process_limit)" done