Verschlüsseltes Backup-Script mit rsync

F

ford

Grünschnabel
Hey,

ich habe 3 CentOS VPS, die ich backupen möchte. Jedoch möchte ich mir hierzu einen 4. VPS mieten, damit die 3 VPS keinen Zugang zu dem Daten-Server haben.

Ich habe noch nie wirklich was unter bash gescripted und weiß nicht, ob das gut ist was ich gemacht habe.

Könnt ihr euch bitte das Script anschauen und konstruktive Kritik geben, bevor ich es einsetze?


Vielen Dank
LG ford




Code:
#!/bin/bash

# Zielverzeichnis
DSTDIR="/BACKUP"

#Verschlüsselung
sshfs -o reconnect,port=$portToFileServer $ziel_user@$backup_ziel /pfad/zu/backupziel.encrypted
encfs --extpass='cat /path/to/password.txt'  /pfad/zu/backupziel.encrypted $DSTDIR


#dann rsync oder rsnapshot

# Optionen fuer rsync
OPTIONS="--archive --delete --delete-excluded --compress --numeric-ids -e "ssh -p $portNumber""

# Excludeliste
EXCLUDE="--exclude=/tmp/ --exclude=/proc/ --exclude=/dev/ --exclude=/sys/ --exclude=/run/ --exclude=/home/ford/.cache/ --exclude=/root/.cache/"

# Rechner, die gesichert werden sollen
CLIENTS="server1 server2 server3"

# Schleife zum Durchlaufen der Hostliste
for host in $CLIENTS ; do
        # Loeschen bzw. Rotieren der alten Sicherungen
        rm -rf $DSTDIR/$host/daily.04 $DSTDIR/$host/monthly.01

        for i in $(sec 1 4)
        do
                mv $DSTDIR/$host/monthly.0$(( $i-1 )) $DSTDIR/$host/monthly.0$i
        done

        mv $DSTDIR/$host/daily.13 $DSTDIR/$host/monthly.00

        for i in $(seq 1 13)
        do
                if [ $i -lt 10 ]
                then
                        if [ $i -ne 9 ]
                        then
                                mv $DSTDIR/$host/daily.0$(( $i-1 )) $DSTDIR/$host/daily.0$i
                        else
                                mv $DSTDIR/$host/daily.0$(( $i-1 )) $DSTDIR/$host/daily.$i
                        fi
                else
                        mv $DSTDIR/$host/daily.$(( $i-1 )) $DSTDIR/$host/daily.$i
                fi
        done
        mkdir $DSTDIR/$host/daily.00

        # rsync-Aufruf
        rsync $OPTIONS $EXCLUDE root@$host:/ $DSTDIR/$host/daily.00 --link-dest $DSTDIR/$host/daily.01
        ssh root@$host -p $portNumber"find / ! -path '/tmp/*' ! -path '/proc/*' ! -path '/dev/*' ! -path '/sys/*' ! -path '/run/*' ! -path '/home/ford/.cache/*' ! -path '/root/cache/*' |parallel 'stat -c %U\ %G\ %a\ %n {}'" > $DSTDIR/$host/daily.00/Owner-Informationen.txt
        # cat textfile |ssh $production parallel 'u="$(echo {}|cut -d" " -f1)";g="$(echo {}|cut -d" " -f2)";m="$(echo {}|cut -d" " -f3)";n="$(echo {}|cut -d" " -f4-)";chown $u:$g "$n";chmod "$m" "$n"'
done
 
Zuletzt bearbeitet:

Ähnliche Themen

Switche abfragen über Script

script sshpass

Port generieren, wenn nicht dann

verzeichniss suche funktioniert nicht

Prblem mit zeilenweises auslesen von Datei und schreiben nach mysql

Zurück
Oben