Debian Codegraph @

etc/psidump

raw
1 #!/bin/bash
2 # psidump - backup EPOC files
3 # Copyright (C) 2001 Alain Trembleau <[email protected]>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # along with this program; if not, see <https://www.gnu.org/licenses/>.
17 #
18 # This does an incremental backup of the C:, D: and E: drives (if they exist)
19 # The Z: (ROM) drive can also be backed up.
20 # The -g option is a gnu tar specific option which will not necessarily
21 # work with other versions of tar.
22 # The tar files created may not work with other versions of tar.
23 #
24 # Note: --listed-incremental=SNAPSHOT-FILE = -g SNAPSHOT-FILE
25 #
26
27 # Function definitions
28
29 function usage () {
30
31 OPTIND=1
32 while getopts ":d" option; do
33 case $option in
34 d) # Detailed output
35 detail=1
36 ;;
37 esac
38 done
39
40 echo "Version $VERSION"
41 echo "Usage : psidump [-fivV] [-D <disk>] [-m <mount_dir>] [-d <dump_dir>]"
42 if [[ $detail ]]; then
43 echo "Options:"
44 echo " d <dir> Unix dump directory"
45 echo " D <disk> EPOC disks to be backed up"
46 echo " f forces a full backup"
47 echo " i perform an incremental backup"
48 echo " m <dir> EPOC mount point"
49 echo " v verbose output"
50 echo " V display the version and exit"
51 fi
52 exit 1
53
54 }
55
56 function create_dirs () {
57 # If the required directories do not exist, then create them.
58
59 # Local variable declarations
60 local localdir
61
62 # Grab arguments
63 localdir=$1
64
65 if [[ ! -d "$localdir" ]] ; then
66 mkdir "$localdir"
67 fi
68 if [[ ! -d "$localdir"/etc ]] ; then
69 mkdir "$localdir"/etc
70 fi
71 if [[ ! -d "$localdir"/etc ]] ; then
72 mkdir "$localdir"/etc
73 fi
74 if [[ ! -d "$localdir"/backups ]] ; then
75 mkdir "$localdir"/backups
76 fi
77 if [[ ! -d "$localdir"/backups/tarfiles ]] ; then
78 mkdir "$localdir"/backups/tarfiles
79 fi
80
81 if [[ ! -f "$localdir"/etc/epoctab ]] ; then
82 cat > "$localdir"/etc/epoctab << END1
83 # epoctab
84 #
85 # This file is a table of the different EPOC machines which have connected
86 # to this machine. The first entry is the machine id, and the second
87 # entry is the machine name.
88 # Note: There MUST be a TAB between the two fields!
89 #
90 END1
91 fi
92
93 }
94
95 function process_drives () {
96 # Determine the drives on the machine, and process one by one
97
98 # Local variable declarations
99 local localdir
100 local psidir
101 local full_backup
102 local machine_name
103 local dump_drive_list
104 local re_drive_list
105
106 # Grab arguments
107 localdir=$1
108 psidir=$2
109 full_backup=$3
110 machine_name=$4
111 dump_drive_list=$5
112
113 # Turn "CDE" into "C|D|E"
114 re_drive_list=`echo $dump_drive_list | sed -e 's/./&|/g' -e 's/|$//'`
115
116 # Determine the current drives on the machine to be backed up
117 drives=`
118 plpftp devs |
119 sed -e '1d' |
120 awk '$1~/'$re_drive_list'/ { print $1 }'
121
122 `
123
124 # Dump file timestamp
125 now=`date +%Y%m%d.%H%M`
126
127 # Do the dump and loads
128
129 echo "Backing up Machine: $machine_name"
130
131 for drive in $drives
132 do
133 drive_name=`plpftp devs | awk '$1=="'$drive'" { print $3 }'`
134
135 echo "Backing up Drive: $drive Name: $drive_name"
136
137 if [[ -n $drive_name ]] ; then
138 dump_drive "$localdir" "$psidir" $full_backup "$machine_name" \
139 "$drive:" "$drive_name" "$now"
140 restore_drive "$localdir" "$machine_name" "$drive_name" "$now"
141 fi
142
143 echo "Drive $drive backed up."
144 done
145
146 }
147
148 function dump_drive () {
149 # Incremental backup of the specified drive
150
151 # Local variable declarations
152 local localdir
153 local psidir
154 local full_backup
155 local machine_name
156 local drive
157 local drive_name
158 local timestamp
159
160 # Grab arguments
161 localdir=$1
162 psidir=$2
163 full_backup=$3
164 machine_name=$4
165 drive=$5
166 drive_name=$6
167 timestamp=$7
168
169 # If doing a full backup, remove dumpinfo file.
170 if [[ $full_backup == 1 ]] ; then
171 rm "$localdir"/etc/dumpinfo."$machine_name"."$drive_name"
172 fi
173
174 tar -c -g "$localdir"/etc/dumpinfo."$machine_name"."$drive_name" -v -z \
175 -f "$localdir"/backups/tarfiles/epoc."$machine_name"."$drive_name".$timestamp.tgz \
176 -C "$psidir"/$drive \
177 .
178 # . \
179 # 2>&1 | tee -a "$localdir"/etc/dumplog
180
181 # When testing, add this to the above tar command to speed up dumps
182 # --exclude ./System \
183 }
184
185 function restore_drive () {
186 # Untar the files into the appropriate directory
187
188 # Local variable declarations
189 local localdir
190 local machine_name
191 local drive_name
192 local timestamp
193
194 # Grab arguments
195 localdir=$1
196 machine_name=$2
197 drive_name=$3
198 timestamp=$4
199
200 # Need to check whether the appropriate directories exist.
201 # If not, create them.
202 if [[ ! -d "$localdir"/backups/"$machine_name"/"$drive_name" ]] ; then
203 mkdir "$localdir"/backups/"$machine_name"/"$drive_name"
204 fi
205
206 # Now restore the files to an appropriate location.
207 tar -x -g $localdir/etc/dumpinfo."$machine_name"."$drive_name" -v -z \
208 -C $localdir/backups/"$machine_name"/"$drive_name" \
209 -f $localdir/backups/tarfiles/epoc."$machine_name"."$drive_name".$timestamp.tgz
210 # | tee -a "$localdir"/etc/dumplog
211 }
212
213 ## Main Program
214
215 # Default settings
216 psidir="/mnt/epoc"
217 localdir="$HOME/epoc"
218 dump_drive_list="CDE"
219 full_backup=0
220 verbose=0
221
222 while getopts ":d:D:fim:vV" option; do
223 case $option in
224 d) # Set the local dump directory
225 localdir=$OPTARG
226 ;;
227
228 D) # Specify the disks to be backed up
229 dump_drive_list=$OPTARG
230 ;;
231
232 f) # Force full backup
233 full_backup=1
234 ;;
235
236 i) # Perform an incremental backup
237 full_backup=0
238 ;;
239
240 m) # Set the mount point where the EPOC files are to be found
241 psidir=$OPTARG
242 ;;
243
244 v) # Turn on verbose logging
245 verbose=1
246 ;;
247
248 V) # Display version and exit
249 usage
250 ;;
251
252 ?) # Invalid option
253 OPTIND=1
254 usage -d
255 ;;
256 esac
257 done
258 shift $((OPTIND - 1))
259
260 # Check arguments
261 if [[ $# != 0 ]]; then
262 usage
263 fi
264
265 # Check whether all the appropriate directories and files exist
266 create_dirs "$localdir"
267
268 # Determine which EPOC device
269 machine_id=`
270 plpftp machinfo |
271 awk -F: '$1==" Machine UID" { print $2 }' |
272 sed -e 's/ //g'
273 `
274
275 machine_name=`
276 grep -v "^#" $HOME/epoc/etc/epoctab |
277 awk -F"\t" '$1=="'$machine_id'" {print $2}'
278 `
279
280 # Deal with the possibility of no name entry
281 if [[ -z $machine_name ]] ; then
282 echo "This is the first time this device has been backed up"
283 echo "on this machine."
284 echo "Please enter a machine name - eg: My Psion"
285 read -p "Machine name: " machine_name
286
287 # Should have a check to make sure this name hasn't already been used.
288
289 echo "#" >> $localdir/etc/epoctab
290 echo "$machine_id $machine_name" >> $localdir/etc/epoctab
291 fi
292
293 if [[ ! -d "$localdir"/backups/"$machine_name" ]] ; then
294 mkdir "$localdir"/backups/"$machine_name"
295 fi
296
297 # Create new entry in log file
298 #echo "==================================================" >> "$localdir"/etc/dumplog
299 #echo "== Starting backup ===============================" >> "$localdir"/etc/dumplog
300 #echo "==================================================" >> "$localdir"/etc/dumplog
301
302 # Shut down all processes running on the EPOC machine
303 echo killsave \"$localdir/etc/proclist.$machine_name\" |
304 plpftp
305 # plpftp >> "$localdir"/etc/dumplog
306
307 # Determine the drives on the machine, and process one by one
308 process_drives "$localdir" "$psidir" $full_backup "$machine_name" $dump_drive_list
309
310 # Restart all the stopped processes
311 echo runrestore \"$localdir/etc/proclist.$machine_name\" |
312 plpftp
313 # plpftp >> "$localdir"/etc/dumplog
314
315 # This is a hardwired hack due to Macro5 not restarting correctly
316 if [[ `grep -l "^Macro5" $localdir/etc/proclist."$machine_name"` ]] ; then
317 echo "Manually restarting Macro5"
318 echo run 'C:\System\Apps\Macro5\Macro5.app' |
319 plpftp
320 # plpftp >> "$localdir"/etc/dumplog
321 fi