source: titan/oealliance/sbin/backup.sh @ 42276

Last change on this file since 42276 was 40393, checked in by obi, 7 years ago

add oealliance start scripts

  • Property svn:executable set to *
File size: 5.1 KB
Line 
1#!/bin/sh
2# backup by obi
3
4rm /tmp/.backup_ok
5touch /tmp/.backup_start
6
7boxtype=`cat /etc/model`
8source=$1
9noinfo=$2
10
11echo "[backup] source: $source"
12name=`echo $source | tr 'a-z' 'A-Z'`
13echo "[backup] name: $name"
14
15echo "[backup] noinfo=$noinfo"
16
17if [ -e /usr/local/bin/neutrino ]; then
18        swtype="neutrino"
19elif [ -e /usr/local/bin/enigma2 ]; then
20        swtype="enigma2"
21elif [ -e /usr/local/bin/vdr ]; then
22        swtype="vdr"
23elif [ -e /usr/local/bin/titan ]; then
24        swtype="titan"
25fi
26
27if [ "$boxtype" = "dm900" ] && [ "$source" != "full" ]; then
28        echo "Use backup.sh: <full>"
29        rm /tmp/.backup_start
30        exit 1
31fi
32
33if [ "$source" != "kernel" ] && [ "$source" != "var" ] && [ "$source" != "root" ] && [ "$source" != "full" ]; then
34        echo "Use backup.sh: <kernel|var|root|full>"
35        rm /tmp/.backup_start
36        exit 1
37fi
38
39error()
40{
41        killall infobox
42        infobox 10010 "Sicherungsfehler" "$1" "" "Neustart in 10 sekunden" &
43        echo "[backup.sh] $1"
44        for i in 9 8 7 6 5 4 3 2 1 0; do
45                echo "$2 ($i)" > /dev/vfd
46                sleep 1
47        done
48        #do not start restore if update fail
49        echo "Neustart" > /dev/vfd
50        echo "[backup.sh] reboot"
51#       init 6
52        echo "backup.sh reboot"
53        rm /tmp/.backup_start
54        reboot -f
55        exit
56}
57
58got_mtd_part()
59{       
60        mtd=`cat /proc/mtd | grep -i "$source" | cut -d":" -f1`
61        echo "[backup.sh] Part $source: mtd=$mtd"
62        ### check mtd part ###
63        if [ -z "$mtd" ] || [ `echo -e "$mtd" | wc -l` -ne 1 ] || [ "${mtd:0:3}" != "mtd" ] || [ "$mtd" == "mtd0" ]; then
64                error "Uncorrect MTD Partition: $mtd" "MTD err"
65        else
66                mtdok=`cat /proc/mtd | grep -i "$source" | cut -d":" -f1 | sed s/mtd//g`
67        fi
68}
69### functions ###
70
71if [ "$boxtype" = "dm900" ]; then
72
73        backupdir="/tmp"
74       
75        if [ $noinfo != "1" ]; then
76                echo "infobox1"
77                infobox 60 "SICHERUNG" "Sicherung gestartet... bitte warten" &
78        fi
79        rm /tmp/"$boxtype"_full_backup_no_settings.zip
80        if [ -e "/tmp/$boxtype" ]; then
81                rm -r $boxtype
82        fi
83        mkdir /tmp/$boxtype
84       
85        if [ ! -e "/tmp/backuphelp" ]; then
86                mkdir /tmp/backuphelp
87        else
88                umount -l /tmp/backuphelp
89        fi
90        mount /dev/root /tmp/backuphelp
91       
92        cd /tmp/backuphelp
93        tar -cjf /tmp/$boxtype/rootfs.tar.bz2 ./
94        cd /tmp
95        umount -l /tmp/backuphelp
96        zip -r /tmp/"$boxtype"_full_backup_no_settings.zip ./$boxtype
97        rm -r $boxtype
98        rm /tmp/.backup_start
99        if [ $noinfo != "1" ]; then
100                echo "infobox2"
101                killall infobox
102                infobox GUI#5 "SICHERUNG" "Ihre Sicherung wurde erfolgreich angelegt !" " " "Speicherort: $backupdir/"$boxtype"_full_backup_no_settings.zip" " " "EXIT = Fertig"
103                killall infobox
104        fi
105        exit 0
106fi     
107               
108       
109umount -fl /tmp/mnt
110rm -rf /tmp/*
111
112if [ $noinfo != "1" ]; then
113        echo "infobox1"
114        infobox 30 "SICHERUNG" "$name Sicherung gestartet" &
115fi
116echo "Sicherung gestartet" > /dev/vfd
117sleep 1
118
119backupdir="/tmp"
120
121got_mtd_part
122
123if [ -e "/tmp/.backupdev" ] && [ -e "/var/backup" ];then
124        backupdir="/var/backup"
125else
126        echo "[backup.sh] kein backup device gefunden"
127        if [ $noinfo != "1" ]; then
128                echo "infobox2"
129                infobox 20 "SICHERUNG" "$name Sicherung abgebrochen !" " " "Schliessen Sie Bitte ein Flash/Usb Datenträger mit einem backup ordner an." "Und versuchen Sie es erneut"
130        fi
131        echo "[backup.sh] done"
132        rm /tmp/.backup_start
133        exit
134fi
135
136checkrw=`readlink /var/backup | sed 's!/backup!!'`
137if [ `mount | grep "$checkrw" | grep "(rw," | tail -n1 | wc -l` -eq 1 ];then
138        echo "[backup.sh] rw check ok"
139else
140        echo "[backup.sh] zuwenig platz: filesize ($filesize) freespace ($freespace)"
141        if [ $noinfo != "1" ]; then
142                echo "infobox3"
143                infobox 20 "SICHERUNG" "$name Sicherung abgebrochen !" " " "Flash/Usb Datenträger ist nicht beschreibbar !"
144        fi
145        echo "[backup.sh] done"
146        rm /tmp/.backup_start
147        exit
148fi
149
150freespace=`getfreespace $backupdir`
151mtdblock=`echo $mtd | sed 's!mtd!mtdblock!'`
152filesize=`cat /proc/partitions | grep $mtdblock | awk {'print $3'}`
153
154echo freespace $freespace
155echo filesize $filesize
156
157if [ "$freespace" -lt "$filesize" ]; then
158        echo "[backup.sh] zuwenig platz: filesize ($filesize) freespace ($freespace)"
159        if [ $noinfo != "1" ]; then
160                echo "infobox4"
161                infobox 20 "SICHERUNG" "$name Sicherung abgebrochen !" " " "Zu wenig Freierspeicher auf dem Flash/Usb Datenträger !"
162        fi
163        echo "[backup.sh] done"
164        rm /tmp/.backup_start
165        exit
166fi
167
168echo "[backup.sh] freespace ok: filesize ($filesize) freespace ($freespace)"
169
170time=`date +"%Y.%m.%d_%H.%M.%S"`
171version=`cat /etc/version`
172
173killall infobox
174fullname="$time"_"$version"_"$name"BACKUP
175if [ $noinfo != "1" ]; then
176        echo "infobox5"
177        infobox 10020 "SICHERUNG" " " "Von: /dev/mtd$mtdok" "Nach: $backupdir/$fullname.img" " " &
178fi
179dd if="/dev/mtd$mtdok" of="$backupdir/$fullname.img"
180
181sleep 1
182
183echo "[backup.sh] Create MD5 File $fullname"
184/sbin/md5sum "$backupdir/$fullname.img" | cut -d "/" -f1 > "$backupdir/$fullname.md5"
185
186sleep 2
187if [ $noinfo != "1" ]; then
188        killall infobox
189        echo "infobox6"
190        infobox 20 "SICHERUNG" "$name Sicherung abgeschlossen" &
191fi
192echo "Sicherung abgeschlossen" > /dev/vfd
193sleep 3
194
195if [ $noinfo != "1" ]; then
196        echo "infobox7"
197        killall infobox
198        infobox 9999 "SICHERUNG" "Ihre $name Sicherung wurde erfolgreich angelegt !" " " "Speicherort: $backupdir/$fullname.img" " " "EXIT = Fertig" &
199        echo "Fertig ?" > /dev/vfd
200        abfrage /dev/input/event0; ret=$?
201        killall infobox
202fi
203
204echo " " > /dev/vfd
205
206echo "[backup.sh] sync"
207sync
208
209touch /tmp/.backup_ok
210rm /tmp/.backup_start
211
212echo "[backup.sh] done"
Note: See TracBrowser for help on using the repository browser.