backup skirpt

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# ------------------ ranko skoric ------------------- #  
# ------------------  24.09.2021 -------------------- #
 
configfile="/root/usb.conf"
 
usbuuid=`/usr/sbin/blkid | grep usb | awk '{print $2}' | sed 's/"//g'`
usb1="UUID=273a5f2f-f009-4c88-b22c-34ebe09e5155"
usb2="UUID=58d0bbc6-7ab8-47ef-8182-4ecdef89bfb1"
 
echo "usb is on $usbuuid"
echo "$usb1"
echo "$usb2"
 
# ---------------------------------------------------- # 
if [ "$usbuuid" == "$usb1" ]
then
tempfile="/root/usb1.temp.sh"
else
tempfile="/root/usb2.temp.sh"
fi
# ---------------------------------------------------- # 
 
rconf=`grep -Ev '^(#|$)' $configfile | grep retain |  awk '{print $2" "$3}' | sed 'N;N;s/\n/ /g'`
line1=($rconf);
# prüft ob temp file existiert
 
if [ ! -f $tempfile ] 
then
echo ${line1[*]} | tee -a  $tempfile
echo ${line1[*]} | tee -a  $tempfile
# echo "3" | tee -a  $tempfile
fi 
# erste zeile im temp file überschreiben 
sed -i -e 1c"${line1[*]}" $tempfile;
# zweite zeile aus temp file auslesen
line2=(`awk 'NR==2' $tempfile`);
# i zuweisen alpha, beta, gamma
i=${line2[0]}
 
a=${line2[1]}
let a=$a-1
line2[1]=$a
echo ${line2[1]}
 
if  [ $a -lt 0 ]
then
	line2[1]=${line1[1]}
	# i ist beta
	i=${line2[2]}
	b=${line2[3]}
	let b=$b-1
	line2[3]=$b
 
		if [ $b -lt 0 ]
		then
		line2[3]=${line1[3]}		
		# i ist gamma
		i=${line2[4]}
		c=${line2[5]}
		let c=$c-1
		line2[5]=$c	
			if [ $c -lt 0 ] 
			then
			line2[5]=${line1[5]}
			fi
		fi
fi
 
sed -i -e 2c"${line2[*]}" $tempfile;
#----------------- welche Festpatte angeschlossen ist  -------------------#"
 
hdfile="/root/hd.file.log"
# source /root/usb.backup.sh
 
if [ ! -f $hdfile ]
then
echo "day 1 usb 0 0" | tee -a  $hdfile
fi
 
a=`awk 'NR==1' $hdfile`;
text=($a)
# ------------------------------------ #
if [ "$usbuuid" == "$usb1" ]
then 
	text[3]=0
	if [ ! ${text[3]} == ${text[4]} ]
	then 
    		text[1]=0
    		text[4]=${text[3]}
    	fi
else
	text[3]=1
 
	 if [ ! ${text[3]} == ${text[4]} ]
	 then 
 
    		text[1]=0
    		text[4]=${text[3]}
    	 fi 
fi
# -------------------------------------- #
	day=${text[1]}
	let day++
	text[1]=$day
	echo ${text[*]} > $hdfile
	cat $hdfile
# ---------------------------------------# 
# 
if [ "$usbuuid" == "$usb1" ]
then
echo "usb1"
 
mount $usb1 /mnt/usb
 	if [ -d /mnt/usb/lost+found ]
 	then
  	rsnapshot -c $configfile $i
	rsync -av --delete /mnt/nas/backup/vm/ /mnt/usb/vm/
	/bin/bash /root/me.backup.sh
 	fi
 
sleep 4
umount /mnt/usb
 
echo "exit"
 
else
echo "usb2"
 
mount $usb2 /mnt/usb
 	if [ -d /mnt/usb/lost+found ]
 	then
	rsnapshot -c $configfile $i
 	rsync -av --delete /mnt/nas/backup/vm/ /mnt/usb/vm/
 	/bin/bash /root/me.backup.sh
 	fi
 
sleep 4
umount /mnt/usb
fi
 
# ---------------------config.conf------------------------------ # 
 
config_version	1.2
snapshot_root	/backup/cloud
cmd_cp		/bin/cp
cmd_rm		/bin/rm
cmd_rsync	/usr/bin/rsync
cmd_logger	/usr/bin/logger
retain	alpha	15
retain	beta	7
retain	gamma	4
verbose		2
loglevel	3
logfile	/var/log/rsnapshot.log
lockfile	/var/run/rsnapshotcloud.pid
 
backup	/mnt/cloud/var/www/	www/	+rsync_long_args=--no-relative
backup	/mnt/cloud/etc/	etc/	+rsync_long_args=--no-relative
backup	/mnt/cloud/var/lib/mysql/	mysql/	+rsync_long_args=--no-relative
backup	/mnt/cloud/opt/	opt/	+rsync_long_args=--no-relative