Benutzer-Werkzeuge

Webseiten-Werkzeuge


know-how:backup

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
know-how:backup [2020/03/29 14:31] – [borg - hetzner storage] ccknow-how:backup [2024/02/26 10:31] (aktuell) cc
Zeile 1: Zeile 1:
 +~~ODT~~
 +====== Prinzipien ======
 +  * Generelle Punkte unabhängig von der eingesetzten Lösung
 +  * Diese Fragen sind essentiell für eine funktionierende Backup/Restore Lösung
 +
 +  * Hast du eine Backup Lösung ? 
 +  * Wurde definiert welche Daten das Backup beinhalten soll ?
 +  * Werden bestimmte Zustände deiner Daten zu bestimmten Zeitpunkten festgehalten ?
 +  * Wurde definiert wie lange bestimmte Zustände für ein Restore verfügbar sein müssen ?
 +  * Gibt es gesetzliche Verpflichtungen für die Dauer der Aufbewahrung und Qualität der Backups ?
 +  * Wo liegen die Backup Daten physikalisch ?
 +  * Wie wird der Raum in dem sich die Daten physikalisch befinden gesichert ?
 +  * Sind die Daten gegen Diebstahl / Blitzschlag / Überschwemmungen gesichert ?
 +  * Was passiert bei Ereignissen **"höherer Gewalt"** ?
 +  * Gibt es zumindest einen 2. Standort deiner Backup Daten ?
 +  * Ist es möglich die Integrität des Backups zu überprüfen ?
 +  * Wurde schon einmal ein Restore durchgeführt ? 
 +  * Kannst du selbstständig einen Restore durchführen ?
 +  * Wie lange hat der Restore gedauert ?
 +  * Welche Softwarelösungen zB: Betriebssystem / Basis werden für den Restore benötigt ?
 +  * Welche Lizenzen werden benötigt um einen Restore durchzuführen ?
 +
 +
 ====== Windows ====== ====== Windows ======
   * Windows Sicherung muss installiert sein   * Windows Sicherung muss installiert sein
   * Generiert VHDX Datein die gemountet werden können   * Generiert VHDX Datein die gemountet werden können
 +
 +
  
 ===== Externer SAMBA Server rotierend ===== ===== Externer SAMBA Server rotierend =====
Zeile 86: Zeile 111:
 exit exit
 </code> </code>
 +
  
 ===== Hyper-V Guests auf Festplatte rotierend ===== ===== Hyper-V Guests auf Festplatte rotierend =====
Zeile 114: Zeile 140:
 echo "----END BACKUP----" >> %LOGFILE% echo "----END BACKUP----" >> %LOGFILE%
 </code> </code>
 +
 +
 +===== Restore mit Windows Boardmitteln =====
 +  * Über zB: Windows 10 iso / reparieren / System Image wiederherstellen / Im Netzwerk suchen
 +  * Windows kann grundsätzlich vhdx Dateien als virtuelle Datenträger einbinden zB: über die "Computerverwaltung" -> "Datenträger" -> rechts anfügen vhd(x) - auch UNC Pfade auf Samba Server sind möglich (getestet mit Debian 10 / Windows 10 FIXME
 +  * **Achtung**
 +     * BIOS/UEFI beachten 
 +     * Ziel Datenträger muss mindestens gleich groß /größer sein (think thin Provisioning für restore)
 +     * Format für die Eingabe von Benutzername: IP\BENUTZERNAME (wenn Daten auf samba Share liegen)
  
 ===== Duplicati 2 - verschlüsseltes Cloud Backup ===== ===== Duplicati 2 - verschlüsseltes Cloud Backup =====
Zeile 183: Zeile 218:
 append initrd=urbackup/live/initrd.img boot=live config username=urbackup toram noswap fetch=tftp://IP_ADRESSE_TFTP_SERVER/urbackup/live/filesystem.squashfs append initrd=urbackup/live/initrd.img boot=live config username=urbackup toram noswap fetch=tftp://IP_ADRESSE_TFTP_SERVER/urbackup/live/filesystem.squashfs
 </code> </code>
 +
 +
 +  * **Migration** von Urbackup Server Installation **ohne Backupdaten** jedoch mit Einstellungen von altem System (2016 Standard) auf neues System (2019 Standard)
 +    * Installation gleiche Serverversion wie auf "altem System"
 +    * Deaktivieren und beenden von Urbackup Server Dienst auf altem und neuem System
 +    * Kopieren von C:\Programme..\urbackup Server\*.* von altem System auf neues System (damit auch die Keys für die Authentifizierung bleiben, alle Dateien überschreiben auf neuem System)
 +    * Verzeichnis / Laufwerk für Backup wie auf altem System auf neuem System erstellen
 +    * Urbackup Server Dienst wieder starten -> sobald die Clients im Web Menü sichtbar werden - vollständige Abbildsicherung auslösen / IP vom alten System muss **nicht** übernommen werden
 +===== Altaro =====
 +  * Altaro 8 - **nw.js** Screen / Windows 2019 Standard (https://help.altaro.com/support/solutions/articles/43000467363-getting-nw-js-on-startup-here-s-how-to-fix-it-)
 +    * **Ausloggen** und neu einloggen / beim Check von **%Temp%** existiert das Verzeichnis nicht mehr 
 +
 +  * Bei den Einstellungen VSS Copy beachten bei virtuellen Domain Controllern ! 
 +  * Scheduled Test Restores einrichten und die Daten des Backups regelmäßig überprüfen lassen
 +  * Notifications per E-Mail konfigurieren / für den Fall dass sie nicht funktioniert haben
 +====== HP Aruba ======
 +  * Für Cronjob siehe "HP Pro Curve"
 +  * SSH Server Keys müssen bereits "accepted" worden sein / sonst hängt er bei der Accept Key Frage
 +  * **backup-aruba.expect**
 +<code>
 +#!/usr/bin/expect -f
 +
 +set timeout 60
 +
 +log_user 0
 +
 +spawn ssh USERNAME@[lindex $argv 0]
 +
 +
 +expect "password:"
 +send "PASSWORD\r"
 +
 +#2021-02-08 cc: think wisely if you want to send password as argument to call
 +#send "[lindex $argv 1]\r" 
 +
 +expect "continue"
 +
 +send "\r"
 +
 +expect "#"
 +
 +send "terminal length 1000\r"
 +
 +expect "#"
 +
 +log_user 1
 +
 +send "show config\r"
 +
 +expect "#"
 +
 +
 +send "exit\r"
 +
 +expect ">"
 +
 +send "exit\r"
 +
 +expect "?"
 +
 +send "y\r"
 +
 +expect eof
 +
 +</code>
 +====== HPE Comware  ======
 +  * Für Cronjob siehe "HP Pro Curve"
 +  * SSH Server Keys müssen bereits "accepted" worden sein / sonst hängt er bei der Accept Key Frage
 +  * **backup-hp-comware-switches.expect**
 +
 +<code>
 +#!/usr/bin/expect -f
 +
 +set timeout 60
 +
 +spawn ssh admin@[lindex $argv 0]
 +
 +expect "password:"
 +send "PASSWORD\r"
 +#2021-02-08 cc: think wisely if you want to send password as argument to call
 +#send "[lindex $argv 1]\r" 
 +
 +expect ">"
 +
 +send "xtd-cli-mode\r" 
 +
 +expect "]:"
 +
 +send "Y\r"
 +
 +expect "Password:"
 +
 +send "foes-bent-pile-atom-ship\r" 
 +
 +expect ">"
 +
 +send "screen-length disable\r"
 +
 +expect ">"
 +
 +send "show current-configuration\r"
 +
 +expect ">"
 +
 +send "quit\r"
 +</code>
 +
 ====== HP Pro Curve  ====== ====== HP Pro Curve  ======
   * **Achtung** Sicherheitsimplikationen bei **telnet** beachten (Übertragung des passworts über plaintext)   * **Achtung** Sicherheitsimplikationen bei **telnet** beachten (Übertragung des passworts über plaintext)
Zeile 201: Zeile 343:
 set ip_address [lindex $argv 0]; set ip_address [lindex $argv 0];
 set prompt "#" set prompt "#"
-set username "USERNAME_SWITCHES\r" +set username "USERNAME\r" 
-set password "PASSWORD_SWITCHES\r"+set password "PASSWORD\r"
  
     log_user 0      log_user 0 
Zeile 211: Zeile 353:
     send $password     send $password
     expect $prompt     expect $prompt
-    # To avoid sending 'Enter' key on huge configurations +    send "terminal length 1000\r"
-    send "terminal length 0\r"+
     expect $prompt     expect $prompt
-    #set timeout 120;# Increasing timeout to 2mins, as it may take more time to get the prompt+    set timeout 120
     log_user 1     log_user 1
     send "show config\r"     send "show config\r"
     expect $prompt     expect $prompt
-    #set timeout 20; # Reverting to default timeout +    set timeout 20
-    # Sending 'exit' at global level prompt will close the connection+
     send "exit\r"     send "exit\r"
 +    expect ">"
 +    send "exit\r"
 +    expect "?"
 +    send "y\r"
     expect eof     expect eof
 +
  
 </code> </code>
Zeile 319: Zeile 464:
 </code> </code>
  
 +  * **backup-lvm-files.sh**
 +  * Um einen LVM Snapshot read only zu mounten und dann per RSYNC mit einem Verzeichnis zu syncen / kann mit rsnapshot backup_exec kombiniert werden 
 +<code>
 +#!/bin/bash
 +
 +
 +function bailout ()
 +{
 +
 + echo -e "$1"
 +
 + [ -z "$2" ] || lvremove -q -f "$2"
 +
 + exit 2
 +
 +}
 +
 +function usage ()
 +{
 + echo -e "$1"
 + exit 1
 +
 +
 +}
 +
 +RSYNC_DEFAULT_OPTIONS="--dry-run -a --delete  --numeric-ids " 
 +
 +RSYNC_DEFAULT_OPTIONS_ARRAY=($RSYNC_DEFAULT_OPTIONS)
 +
 +ARGUMENTS=$#
 +SIZE_SNAPSHOT="10G"
 +BUFFER="10M"
 +
 +TMP_MOUNT_POINT="/mnt/tmp"
 +
 +which lvcreate > /dev/null || bailout "lvcreate not found"
 +which lvremove > /dev/null || bailout "lvremove not found"
 +which rsync > /dev/null || bailout "rsync not found"
 +which kpartx > /dev/null || bailout "kpartx not found"
 +which mount > /dev/null || bailout "mount not found"
 +which mountpoint > /dev/null || bailout "mountpoint not found"
 +
 +
 +if [ $ARGUMENTS != 2 ] &&  [ $ARGUMENTS != 3 ]
 +then
 +
 + bailout "Usage: $0 PATH_TO_LVM_VOLUME BACKUP_DIRECTORY [ \""RSYNC_OPTIONS\"" ]"
 +
 +fi
 +
 +LVM_PATH="$1"
 +BACKUP_DIRECTORY="$2"
 +RSYNC_CUSTOM_OPTIONS="$3"
 +
 +[ -n "$3" ] && RSYNC_DEFAULT_OPTIONS_ARRAY+=($RSYNC_CUSTOM_OPTIONS)
 +
 +
 +[ ! -r $LVM_PATH ] && bailout "FAIL: Cannot read $LVM_PATH VOLUME"
 +
 +[ ! -d $BACKUP_DIRECTORY ] && bailout "FAIL: $BACKUP_DIRECTORY is already here aborting"
 +
 +[ ! -d $TMP_MOUNT_POINT ] && bailout "FAIL: $TMP_MOUNT_POINT directory not found"
 +
 +mountpoint -q $TMP_MOUNT_POINT && bailout "FAIL: $TMP_MOUNT_POINT is already mounted FAIL"
 +
 +LVM_NAME=$(echo ${LVM_PATH##*/})
 +
 +LVM_NAME_SNAPSHOT="$LVM_NAME""_snapshot"
 +
 +LVM_PATH_SNAPSHOT="${LVM_PATH%%$LVM_NAME}$LVM_NAME_SNAPSHOT"
 +
 +[ -r $LVM_PATH_SNAPSHOT ] && bailout "FAIL: Snapshot: $LVM_PATH_SNAPSHOT already here aborting"
 +
 +lvcreate -L $SIZE_SNAPSHOT -s -n $LVM_NAME_SNAPSHOT $LVM_PATH > /dev/null || bailout "FAIL: Could not create Snapshot: $LVM_NAME_SNAPSHOT"
 +
 +
 +[ $? == "0"  ] || bailout "FAIL: $LVM_PATH_SNAPSHOT could not be created"
 +
 +
 +MOUNT_PATH="$LVM_PATH_SNAPSHOT"
 +
 +DEVICE_MAPPER_ENTRY=$(kpartx -av $LVM_PATH_SNAPSHOT)
 +
 +RETURN_SUCCESS=$?
 +
 +[ $? != "0" ] && bailout "FAIL: Kpartx did not return 0 - error" "$LVM_PATH_SNAPSHOT"
 +
 +DEVICE_MAPPER_ENTRY=$(echo $DEVICE_MAPPER_ENTRY | cut -f 3 -d" ")
 +
 +[ -z $DEVICE_MAPPER_ENTRY ] || MOUNT_PATH="/dev/mapper/""$DEVICE_MAPPER_ENTRY"
 +
 +
 +mount -o ro "$MOUNT_PATH" "$TMP_MOUNT_POINT" || bailout "FAIL: could not mount $MOUNT_PATH to $TMP_MOUNT_POINT" "$LVM_PATH_SNAPSHOT"
 +
 +
 +rsync "${RSYNC_DEFAULT_OPTIONS_ARRAY[@]}" "$TMP_MOUNT_POINT/" "$BACKUP_DIRECTORY/"
 +
 +RETURN_RSYNC=$?
 +
 +umount $TMP_MOUNT_POINT
 +
 +kpartx -dv $LVM_PATH_SNAPSHOT > /dev/null
 +
 +lvremove -q -f $LVM_PATH_SNAPSHOT > /dev/null
 +
 +exit $RETURN_RSYNC
 +</code>
  
   * **integ.sh**   * **integ.sh**
Zeile 471: Zeile 723:
 ===== borg - generell  ===== ===== borg - generell  =====
   * Backup Tests mit borg - Achtung **unverschlüsselt** da Testgerät ohnehin **vollverschlüsselt** ist   * Backup Tests mit borg - Achtung **unverschlüsselt** da Testgerät ohnehin **vollverschlüsselt** ist
 +  * Ganze LVM Devices basierend auf Snapshot backupppen - sollte konsistent sein **backup-lvm-drive-borg.sh**
 +<code>
 +#!/bin/bash
 +
 +function bailout ()
 +{
 +
 + echo -e "$1" 1>&2
 + exit 2
 +
 +}
 +
 +function usage ()
 +{
 + echo -e "$1"
 + exit 1
 +
 +
 +}
 +
 +# LVM PATH / generate LVM snapshot name suffix snapshot / compress devices / output PATH
 +
 +ARGUMENTS=$#
 +SIZE_SNAPSHOT="50G"
 +BORG_NR_TO_KEEP="4"
 +
 +which lvcreate > /dev/null || bailout "lvcreate not found"
 +which borg > /dev/null || bailout "borg cannot be found"
 +which lvremove > /dev/null || bailout "lvremove not found"
 +
 +[ $ARGUMENTS -lt 2 ] && bailout "Usage: $0 PATH_TO_BORG_REPOSITORY PATH_TO_LVM_VOLUME1 PATH_TO_LVM_VOLUME2 "
 +
 +BACKUP_REPOSITORY=$(echo $1 | cut -d: -f 1)
 +
 +[ -r $BACKUP_REPOSITORY ] || bailout "FAIL: $BACKUP_REPOSITORY cannot be read"
 +
 +[ -w $BACKUP_REPOSITORY ] || bailout "FAIL: $BACKUP_REPOSITORY cannot be written to"
 +
 +for i in "${@:2}" ; do
 +
 + LVM_PATH="$i"
 + LVM_PATH_SNAPSHOT="$LVM_PATH""_snapshot"
 +      
 +      [ ! -r $LVM_PATH ] && bailout "FAIL: Cannot read \"$LVM_PATH\" VOLUME"
 +      [ -r  $LVM_PATH_SNAPSHOT ] && bailout "FAIL: Attention snapshot still there: $LVM_PATH_SNAPSHOT"     
 +done
 +
 +lvm_snapshots=""
 +
 +for i in "${@:2}" ; do
 +
 +        LVM_PATH="$i"
 +        LVM_PATH_SNAPSHOT="$LVM_PATH""_snapshot"
 +        
 + lvcreate -L $SIZE_SNAPSHOT -s -n $LVM_PATH_SNAPSHOT $LVM_PATH > /dev/null || bailout "FAIL: Could not create Snapshot: $LVM_NAME_SNAPSHOT"
 +        lvm_snapshots="$lvm_snapshots $LVM_PATH_SNAPSHOT"
 +done
 +
 +borg create --stats --compression=lz4 --read-special "$1" $lvm_snapshots
 +
 +RET_CODE_BORG="$?"
 +
 +for i in "${@:2}" ; do
 +
 +        LVM_PATH="$i"
 +        LVM_PATH_SNAPSHOT="$LVM_PATH""_snapshot"
 +
 + lvremove -q -f $LVM_PATH_SNAPSHOT >/dev/null
 +done
 +
 +borg prune --keep-last $BORG_NR_TO_KEEP $BACKUP_REPOSITORY
 +
 +exit $RET_CODE_BORG
 +
 +</code>
 +
   * Durchgeführt auf Kali Linux - Debian Testing   * Durchgeführt auf Kali Linux - Debian Testing
 <code> <code>
Zeile 522: Zeile 850:
  
 ===== borg - hetzner storage  ===== ===== borg - hetzner storage  =====
-  * FIXME  
- 
 <code> <code>
 1. key verteilen 1. key verteilen
Zeile 589: Zeile 915:
  
 </code> </code>
 +  * **/usr/local/bin/hetzner_borg_backup.sh**
  
 +<code>
 +
 +#!/bin/bash
 +
 +export BORG_PASSPHRASE="PASSPHRASE"
 +REPOSITORY="ssh://u12345678@u12345678.your-storagebox.de:23/./borg/"
 +
 +DIRECTORIES="/mnt/storage/"
 +
 +HOST=$(hostname --fqdn)
 +
 +START_TIME=$(date +%Y.%m.%d-%H.%M.%S)
 +
 +date1=$(date -u +"%s")
 +
 +echo -e  "Program: $0 \nstarted at: $START_TIME\nBacking Up: $DIRECTORIES\nHost: $HOST"
 +
 +#2020-04-08 cc: Achtung sonst konsumiert er den gesamten Upload und die Leitung steht daher: Rate limit ~6 Mbit upload / bei 10Mbit verfügbarem Upload
 +
 +borg create --compression lz4  --stats --remote-ratelimit 700 --exclude '*/.snapshots/*' $REPOSITORY::{now} $DIRECTORIES
 +
 +
 +[[ $? == "0" ]] && borg prune --stats --keep-last 6 $REPOSITORY
 +
 +END_TIME=$(date +%Y.%m.%d-%H.%M.%S)
 +
 +date2=$(date -u +"%s")
 +diff=$(($date2-$date1))
 +
 +echo "$(($diff / 60)) minutes and $(($diff % 60)) seconds elapsed."
 +echo "$(($diff / 86400 )) days elapsed. "
 +
 +echo -e "Program ended successfully : $0 \nended at: $END_TIME\n"
 +</code>
 ===== triggered ===== ===== triggered =====
   * Anforderungen:   * Anforderungen:
Zeile 791: Zeile 1152:
 ===== etc ===== ===== etc =====
   * rsync für blockdevices Kopieren "--copy-devices"   * rsync für blockdevices Kopieren "--copy-devices"
 +  * **Update**
 +<code>
 +rsync (3.2.0-1) unstable; urgency=low
 +
 +  This latest release changed two parameters which used to be present on the
 +  Debian packaging of rsync as upstream now integrated the patches.
 +
 +  Previous parameter:
 +  --copy-devices: write to devices as files (implies --inplace)
 +  Is now called: --write-devices
 +</code>
 +
 +
  
 <code> <code>
Zeile 816: Zeile 1190:
 sent 1,009,903 bytes  received 505,075 bytes  5,439.78 bytes/sec sent 1,009,903 bytes  received 505,075 bytes  5,439.78 bytes/sec
 </code> </code>
 +
 +
 +  * rsync - Ausgabe ob etwas geändert werden würde - dry run und count
 +  * **rsync -iaun --delete foo1/ foo2/ | wc -l**
 +<code>
 +0
 +</code>
 +
know-how/backup.1585485101.txt.gz · Zuletzt geändert: 2020/03/29 14:31 von cc