Software > Linux

backup script -->korrektur lesen + event verbessern

(1/4) > >>

mad1120:
hi leute,
ich derzeit mal weider dabei an meinem Vserver rum zu basteln und ihn vor mir selber absichern
(gegen datenverlust durch unwissen)
weshalb ich mir nun nen kleines backup script zulegen will,
welches automatisch ein tägliches und ein wöchentliches backup anlegt.
dazu gabe ich nen nettes kleines script im web gefunden was dies fast sio macht wie ich es will.
http://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap29sec306.html

aber eben nur fast, weshalb ich es nun versucht habe um zu bauen.

--- Code: ---
#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@freebsd.org>
# and modified by Gerhard Mourani <gmourani@videotron.ca>

#Change the 4 variables below to fit your computer/backup

COMPUTER=Vserver                            # name of this computer
DIRdaily="/var/www /home"                # directoris daily to backup
DIRweekly="/"                            # directoris monthly to backup
BACKUPDIR=/var/ftp/backups               # where to store the backups


#You should not have to change anything below here

PATH=/usr/local/bin:/usr/bin:/bin
DOW=`date +%a`              # Day of the week e.g. Mon
DOM=`date +%d`              # Date of the Month e.g. 27
DM=`date +%d%b`              # Date and Month e.g. 27Sep

# On the 1st of the month a permanet full backup is made
# Every Sunday a full backup is made - overwriting last Sundays backup
# The rest of the time an incremental backup is made. Each incremental
# backup overwrites last weeks incremental backup of the same name.
#
# if NEWER = "", then tar backs up all files in the directories
# otherwise it backs up files newer than the NEWER date. NEWER
# gets it date from the file written every Monday.


# weekly full backup
if [ $DOW = "Mon" ]; then
NEWER=""
# tar $NEWER -czf $BACKUPDIR/$COMPUTER-full-$DM.tar -x /var/ftp/backups $DIRweekly

else

# daily /var/www backup
NEWER=""
        NOW=`date +%d-%b`
cd $BACKUPDIR
        tar $NEWER -czf $BACKUPDIR/$COMPUTER-$DM.tar $DIRdaily

fi

--- Ende Code ---

aber bevor ich es auf meinen Vserver los lasse würde ich mich freuen, wenn es der eine oder andere mal Korrektur lesen könnte.
und gegeben falls  Verbesserungsvorschläge machen kann.

des weiteren bräuchte ich noch ne ergänzung damit sich nicht die backup daten von jahren auf server sammeln,
sprich das alle backups die älter sind als 1 Monat gelöscht werden.


PS:
noch nen frage ist es überhaupt sinnvoll das komplett system per "/" zu sichern?
weil es sind ja doch sehr viele Dateien im system vorhanden die sich so nicht sichern lassen...
wenn nein welche ordner sind sinnvoll?

maxigs:
welche ordner sinnvoll sind hängt sehr stark von deinen anwendungen ab ;)

bei typischen webserver ist das wohl hauptsächlich die datenbank und das webverzeichniss.
system voll backups sind wohl deutlich overkill - einmal nach dem aufsetzen des system und ggf nach größeren umbauten/updates manuell.

was genau die beste stategie ist hängt wirklich vom einsatz ab und wo sich daten wieoft ändern

mad1120:
hi,
also der server ist hauptsächlich fürs teamspeak gedacht wobei ich ihn aber nach und nach als webspace missbrauchen werde,
direkte datenbanken usw. gibt es weniger (bis auf die für die TS user daten).
was die Datenmengen angeht, das sind derzeit inkl allem drum und dran ~500mb. weshalb ich darum keine sorgen mache.
vielmehr geht es mir darum das ich für den fall das ich mir wiedermal was verschiesse selbiges wieder schnell richten kann,
weil gestern hab ich mir zv. den ftp Zugang lahm gelegt da ich beim update nen bissel zu voreilig war.....
was mich dann ca 2h gekostet hat um es wieder zu richten :aua:

und da eh gerade nen script zwecks backup brauche wollte ich mich damit gegen sowas mit schützen  :think:

aber der Hauptaugenmerk liegt halt auf meinem webspace ( /var/www/ )
wobei ich aber da auch noch am grübeln bin ob täglich oder doch nur wöchentlich
aber das lässt sich ja dann auch noch schnell ändern wenn das skript fertig ist.

edit:
hab gerade mal durch gerechnet wenn ich wie geplannt mit meiner .net domian mit rauf ziehe,
wird es mit dem täglichen backup in bezug auf die daten doch verdammt eng..

also wird es doch nen wöchentliches backup der /var/www und /home daten und nen monatliches komplett backup

EDIT:
hab gerade selber ne mögliche lösung für das umlagern und löschen der alten backups gefunden...

--- Code: ---#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@freebsd.org>
# and modified by Gerhard Mourani <gmourani@videotron.ca>

#Change the 5 variables below to fit your computer/backup

COMPUTER1=Vserver                         # name of this computer
COMPUTER2=wwwData                         # name of this computer
DIR1="/var/www /home"          # directoris daily to backup
DIR2="/"                     # directoris monthly to backup
BACKUPDIR=/var/ftp/backups                # where to store the backups
OLDBACKUP=/var/ftp/backups/old            # where old backups stored


#You should not have to change anything below here

PATH=/usr/local/bin:/usr/bin:/bin
DOW=`date +%a`              # Day of the week e.g. Mon
DOM=`date +%d`              # Date of the Month e.g. 27
DM=`date +%d%b`             # Date and Month e.g. 27Sep

# On the 1st of the month a permanet full backup is made
# Every Sunday a full backup is made - overwriting last Sundays backup
# The rest of the time an incremental backup is made. Each incremental
# backup overwrites last weeks incremental backup of the same name.
#
# if NEWER = "", then tar backs up all files in the directories
# otherwise it backs up files newer than the NEWER date. NEWER
# gets it date from the file written every Sunday.


# monthly full backup
if [ $DOM = "1" ]; then
NEWER=""
rm $OLDBACKUP/*.tar
       mv $BACKUPDIR/*.tar $OLDBACKUP
# tar $NEWER -czf $BACKUPDIR/$COMPUTER1-fullbackup-$DM.tar -x /var/ftp/backups $DIR2

fi

# weekly www backup
if [ $DOW = "Mon" ]; then

NEWER=""
        NOW=`date +%d-%b`
        tar $NEWER -czf $BACKUPDIR/$COMPUTER2-$DM.tar $DIR1

fi

--- Ende Code ---

ich habe mir einen "old" ordner angelegt
in dem an jedem ersten des monats zuerst alle alten backups per rm $OLDBACKUP/*.tar alle tar datein gelöscht werden
anschliessend werden die vorhandenen backups des letzten monats rein kopiert mv $BACKUPDIR/*.tar $OLDBACKUP
und danach wird das aktuelle backup erstellt.
somit sollte ich immer auf die backups des aktuellen und des vor monats zu griff haben, oder?  :kratz:

nächster EDIT:
hab gerade wieder nen fehler gefunden, der Monday wird mit Mo nicht mit Mon abgekürzt...
hab das ganze dann auch noch etwas entschlackt...

--- Code: ---#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@freebsd.org>
# and modified by Gerhard Mourani <gmourani@videotron.ca>

#Change the 6 variables below to fit your computer/backup

COMPUTER1=Vserver                         # name of this computer
DIR1="/"                     # directoris monthly to backup

COMPUTER2=webspace-backup                 # name of this computer
DIR2="/var/www /home"          # directoris daily to backup

BACKUPDIR=/var/ftp/backups                # where to store the backups
OLDBACKUP=/var/ftp/backups/old            # where old backups stored


#You should not have to change anything below here

PATH=/usr/local/bin:/usr/bin:/bin
DOW=`date +%a`              # Day of the week e.g. Mon
DOM=`date +%d`              # Date of the Month e.g. 27
DM=`date +%d%b`             # Date and Month e.g. 27Sep


# monthly full backup
if [ $DOM = "1" ]; then
rm $OLDBACKUP/*.tar
       mv $BACKUPDIR/*.tar $OLDBACKUP
# tar -cf $BACKUPDIR/$COMPUTER1-fullbackup-$DM.tar -x /var/ftp/backups $DIR1

fi

# weekly www backup
if [ $DOW = "Mo" ]; then
        NOW=`date +%d-%b`
        tar -czf $BACKUPDIR/$COMPUTER2-$DM.tar $DIR2
fi

--- Ende Code ---

CptHirni:
In der ersten IF ist das tar Kommando noch auskommentiert ;)

Falls du das "/var/ftp/backups" Verzeichnis ausklammern willst muss es "-X" (oder --exclude "/xyz/") heissen. "Klein x" ist extract.

--- Code: ---tar -cf $BACKUPDIR/$COMPUTER1-fullbackup-$DM.tar -X "/var/ftp/backups/" $DIR1
--- Ende Code ---
Beim sichern vom root Verzeichnis sollten bzw. müssen noch /dev /proc /mnt und /tmp ausgeschlossen werden!

Da du das Archiv gzippst sollte die Endung .gz sein, ansonsten kommst du vll irgendwann durcheinander ;)

--- Code: ---tar -czf $BACKUPDIR/$COMPUTER2-$DM.tar.gz $DIR2
--- Ende Code ---
Hat es einen Grund, wieso du die wöchentlichen komprimieren willst und die monatlichen nicht?

Ich weiß nicht ob die Pfade ohne ein schließendes "/" funktionieren, ich kenns nur mit:

--- Code: ---DIR2="/var/www/ /home/"
--- Ende Code ---
(genauso beim mv Befehl)

Wofür das?

--- Code: ---NOW=`date +%d-%b`
--- Ende Code ---

mad1120:
hi CptHirni,
erstmal danke für das Korrektur lesen.
hätte nicht gedacht das ich so viele fehler beim umbauen mit rein gehauen habe :redface:
hab also noch ne menge zu lernen... vor allem das mit der groß und klein Schreiberei...
wenn de nix dagegen hast missbrauche ich dich gleich weiter zum lernen  ;)

was hat es denn mit den von auf gezählten ordner auf sich, das sie sich nicht sichern lassen?
beim /tmp/ kann ich es mir ja denken aber beim rest? treiber, auslagerungsdatein,...???

das das ne ganze reihe von datein sind kann ich selbige im kopf als "variablen" angeben?

--- Code: ---EXCLUDE="/var/ftp/backups/ /dev/ /proc/ /mnt/ /tmp/"
--- Ende Code ---


--- Code: ---tar -czf $BACKUPDIR/$COMPUTER1-fullbackup-$DM.tar.gz -X $EXCLUDE $DIR1
--- Ende Code ---

das sich beim tar durch den Kommentar -z gleich die Endung ändert, war bisher nicht klar ich dachte tar wäre = tar.
so wie bei Winrar und verschiedenen Kompressionsstufen...

die Schrägstriche hab ich schlicht und einfach übersehen, genau so wie die "now" Zeile die hab ich vergessen raus zunehmen...

so nun mal in korrigierter version:

--- Code: ---#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@freebsd.org>
# and modified by Gerhard Mourani <gmourani@videotron.ca>

#Change the 7 variables below to fit your computer/backup

COMPUTER1=Vserver                                                  # name für monatliches
DIR1="/"                                                                   # verz. für monatliches Backup

COMPUTER2=webspace-backup                                    # name für wöchentliches backup
DIR2="/var/www/ /home/"                                            # verz. für wöchentliches backup

BACKUPDIR="/var/ftp/backups/"                                    # speicherort für aktuelle backups
OLDBACKUP="/var/ftp/backups/old/"                              # speicherort für backups des vor monats

EXCLUDE="/var/ftp/backups/ /dev/ /proc/ /mnt/ /tmp/"    # nicht zu sichernde verz.


#You should not have to change anything below here

PATH=/usr/local/bin:/usr/bin:/bin
DOW=`date +%a`                    # Day of the week e.g. Mon
DOM=`date +%d`                    # Date of the Month e.g. 27
DM=`date +%d%b`                    # Date and Month e.g. 27Sep


# monthly full backup
if [ $DOM = "1" ]; then
   rm $OLDBACKUP/*.tar
   mv $BACKUPDIR/*.tar $OLDBACKUP
   tar -czf $BACKUPDIR/$COMPUTER1-fullbackup-$DM.tar.gz -X $EXCLUDE $DIR1

fi

# weekly www backup
if [ $DOW = "Mo" ]; then
   tar -czf $BACKUPDIR/$COMPUTER2-$DM.tar.gz $DIR2
fi
--- Ende Code ---


ich hoffe mal ich´s nicht ver"schlimm"bessert habe  :roll:



Navigation

[0] Themen-Index

[#] Nächste Seite

Zur normalen Ansicht wechseln