Hallo, vlt kann sich das ja jemand ansehen.
Hier nun mein letztes script "backup" welches ich starte mit ./backup daily/monthly/yearly und jeweils mit entsprchenden zeitangaben im crontab eingetragen. Der übersicht halber habe ich alles bis auf die Ordnersynchronisation herausgenommen da sich sonst zu viel code wiederholt. Mir ist bewusst dass ein paar variablen ziemlich unsinnig wurden, es ist mein erstes bash script also bitte habt erbarmen.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | #!/bin/bash
# Setting up some Variables:
SRC="/var/www/owncloud/"
# for the daily function:
DAY=`date -I`
DAYB=`date -I -d "1 day ago"`
DTRG="/mnt/backup/owncloud/daily/$DAY"
DLNK="/mnt/backup/owncloud/daily/$DAYB"
DOPT="-Aax --delete --link-dest=$DLNK"
# for the monthly function:
MON=`date "+%Y-%m"`
MONB=`date "+%Y-%m" -d "1 month ago"`
MTRG="/mnt/backup/owncloud/monthly/$MON"
MLNK="/mnt/backup/owncloud/monthly/$MONB"
# for the yearly function:
YR=`date "+%Y"`
YTRG="/mnt/backup/owncloud/yearly/$YR"
# the function part:
usage (){
echo "Usage: backup ( daily | monthly | yearly )"
}
#this rsyncs the folder to backupdir everyday with hardlinks set from the previous backup
daily (){
rsync $DOPT $SRC $DTRG
}
#after a month this copies the yesterdays daily (to ensure it exists) as a monthly backup with hardlinks
monthly (){
cp -al $DLNK $MTRG
}
#the monthly backup will be hardlinked to a yearly backup
yearly (){
cp -al $MLNK $YTRG
}
# now go for it:
case $1 in
daily|monthly|yearly)
$1
;;
*)
usage
exit 1
;;
esac
|
Was ich erreichen wollte:
Jeden Tag ein Backup des Ordners. Der darauffolgende Tag wird gesynced und hardlinks aus dem letzen erstellt um platz zu sparen. Die monatlichen und jährlichen backups sind wiederum jeweils hardlinks aus den letzten dailys bzw monthlys.
Vlt kann sich das ja jemand ansehen und mir sagen ob das script das auch tut oder ob es problematisch ist für eine backupgeschichte mit history.
Was noch zu tun ist: Löschroutinen, es sollen behalten werden 30 daylies, 12 monthlys. Die jährlichen spare ich mir mal da ich nixht glaube dass dies ins gewicht fällt xD
Lieben Gruß und vielen Dank schonmal für jeden der sich so ein neulingsscript durchlesen mag um zu helfen.
Edit: Script läuft und tut was es soll, habe es auf andere ordner angewendet, leicht verändert und komplettiert und mithilfe von
find /path/to/backupdir -mindepth 1 -maxdepth 1 -type d -ctime +13 -exec rm -rf {} \;
lösche ich nun alle Ordner welche älter als 13 tage sind (14 Ordner bleiben erhalten)
Ich backuppe damit nun die Daten von einer Owncloud, Wordpress und einem zusätzlichen baikalserver mit den dazugehörigen Mysql datenbanken.
Ausserdem wird immer Sonntags ein rsync mit der checksum option ausgeführt, da diese sehr lange dauert und ich finde einmal pro woche reicht hierfür aus. So oft finden keine kleinen dateiänderungen statt.
wenn jemand noch interesse an dem script hat, oder sich auch fragt wie man am besten ein eigenes backupscript erstellt mit BackupHistory kann sich bei mir melden! Ich helfe auch gerne.