usb.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | config_version 1.2 snapshot_root /mnt/usb no_create_root 0 cmd_cp /bin/cp cmd_rm /bin/rm cmd_rsync /usr/bin/rsync cmd_logger /usr/bin/logger retain daily 10 retain week 4 retain gamma 2 verbose 2 loglevel 3 logfile /var/log/rsnapshot.log lockfile /var/run/rsnapshotusb.pid # --------------------------------------- # backup /daten/ name/ +rsync_long_args=--no-relative # --------------------------------------- # |
usb.backup.sh
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 | #!/bin/bash # ------------------ ranko skoric ------------------- # # ------------------ 24.09.2021 -------------------- # umount /mnt/usb configfile="/root/usb.conf" usbuuid=`/usr/sbin/blkid | grep usb | awk '{print $2}' | sed 's/"//g'` usb1="UUID=b14adfcb-383f-4d2b-af90-367528de577c" usb2="UUID=d7133be1-05ac-4e45-9b8f-4c2cc562133b" 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 # ------------------ usb backup starten ---------------------# # if [ "$usbuuid" == "$usb1" ] then echo "usb1" mount $usb1 /mnt/usb if [ -d /mnt/usb/lost+found ] then rsnapshot -c $configfile $i /bin/bash /root/me.usb.backup.sh fi sleep 4 umount /mnt/usb echo "exit" fi # --------------------------------------- # if [ "$usbuuid" == "$usb2" ] then echo "usb2" mount $usb2 /mnt/usb if [ -d /mnt/usb/lost+found ] then rsnapshot -c $configfile $i /bin/bash /root/me.usb.backup.sh fi sleep 4 umount /mnt/usb fi # ----------------------------------------------------- # |
