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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
#!/bin/bash
# psidump - backup EPOC files
# Copyright (C) 2001 Alain Trembleau <alain@platodesigns.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# This does an incremental backup of the C:, D: and E: drives (if they exist)
# The Z: (ROM) drive can also be backed up.
# The -g option is a gnu tar specific option which will not necessarily
# work with other versions of tar.
# The tar files created may not work with other versions of tar.
#
# Note: --listed-incremental=SNAPSHOT-FILE = -g SNAPSHOT-FILE
#
# Function definitions
function usage () {
OPTIND=1
while getopts ":d" option; do
case $option in
d) # Detailed output
detail=1
;;
esac
done
echo "Version $VERSION"
echo "Usage : psidump [-fivV] [-D <disk>] [-m <mount_dir>] [-d <dump_dir>]"
if [[ $detail ]]; then
echo "Options:"
echo " d <dir> Unix dump directory"
echo " D <disk> EPOC disks to be backed up"
echo " f forces a full backup"
echo " i perform an incremental backup"
echo " m <dir> EPOC mount point"
echo " v verbose output"
echo " V display the version and exit"
fi
exit 1
}
function create_dirs () {
# If the required directories do not exist, then create them.
# Local variable declarations
local localdir
# Grab arguments
localdir=$1
if [[ ! -d "$localdir" ]] ; then
mkdir "$localdir"
fi
if [[ ! -d "$localdir"/etc ]] ; then
mkdir "$localdir"/etc
fi
if [[ ! -d "$localdir"/etc ]] ; then
mkdir "$localdir"/etc
fi
if [[ ! -d "$localdir"/backups ]] ; then
mkdir "$localdir"/backups
fi
if [[ ! -d "$localdir"/backups/tarfiles ]] ; then
mkdir "$localdir"/backups/tarfiles
fi
if [[ ! -f "$localdir"/etc/epoctab ]] ; then
cat > "$localdir"/etc/epoctab << END1
# epoctab
#
# This file is a table of the different EPOC machines which have connected
# to this machine. The first entry is the machine id, and the second
# entry is the machine name.
# Note: There MUST be a TAB between the two fields!
#
END1
fi
}
function process_drives () {
# Determine the drives on the machine, and process one by one
# Local variable declarations
local localdir
local psidir
local full_backup
local machine_name
local dump_drive_list
local re_drive_list
# Grab arguments
localdir=$1
psidir=$2
full_backup=$3
machine_name=$4
dump_drive_list=$5
# Turn "CDE" into "C|D|E"
re_drive_list=`echo $dump_drive_list | sed -e 's/./&|/g' -e 's/|$//'`
# Determine the current drives on the machine to be backed up
drives=`
plpftp devs |
sed -e '1d' |
awk '$1~/'$re_drive_list'/ { print $1 }'
`
# Dump file timestamp
now=`date +%Y%m%d.%H%M`
# Do the dump and loads
echo "Backing up Machine: $machine_name"
for drive in $drives
do
drive_name=`plpftp devs | awk '$1=="'$drive'" { print $3 }'`
echo "Backing up Drive: $drive Name: $drive_name"
if [[ -n $drive_name ]] ; then
dump_drive "$localdir" "$psidir" $full_backup "$machine_name" \
"$drive:" "$drive_name" "$now"
restore_drive "$localdir" "$machine_name" "$drive_name" "$now"
fi
echo "Drive $drive backed up."
done
}
function dump_drive () {
# Incremental backup of the specified drive
# Local variable declarations
local localdir
local psidir
local full_backup
local machine_name
local drive
local drive_name
local timestamp
# Grab arguments
localdir=$1
psidir=$2
full_backup=$3
machine_name=$4
drive=$5
drive_name=$6
timestamp=$7
# If doing a full backup, remove dumpinfo file.
if [[ $full_backup == 1 ]] ; then
rm "$localdir"/etc/dumpinfo."$machine_name"."$drive_name"
fi
tar -c -g "$localdir"/etc/dumpinfo."$machine_name"."$drive_name" -v -z \
-f "$localdir"/backups/tarfiles/epoc."$machine_name"."$drive_name".$timestamp.tgz \
-C "$psidir"/$drive \
.
# . \
# 2&>1 | tee -a "$localdir"/etc/dumplog
# When testing, add this to the above tar command to speed up dumps
# --exclude ./System \
}
function restore_drive () {
# Untar the files into the appropriate directory
# Local variable declarations
local localdir
local machine_name
local drive_name
local timestamp
# Grab arguments
localdir=$1
machine_name=$2
drive_name=$3
timestamp=$4
# Need to check whether the appropriate directories exist.
# If not, create them.
if [[ ! -d "$localdir"/backups/"$machine_name"/"$drive_name" ]] ; then
mkdir "$localdir"/backups/"$machine_name"/"$drive_name"
fi
# Now restore the files to an appropriate location.
tar -x -g $localdir/etc/dumpinfo."$machine_name"."$drive_name" -v -z \
-C $localdir/backups/"$machine_name"/"$drive_name" \
-f $localdir/backups/tarfiles/epoc."$machine_name"."$drive_name".$timestamp.tgz
# | tee -a "$localdir"/etc/dumplog
}
## Main Program
# Default settings
psidir="/mnt/epoc"
localdir="$HOME/epoc"
dump_drive_list="CDE"
full_backup=0
verbose=0
while getopts ":d:D:fim:vV" option; do
case $option in
d) # Set the local dump directory
localdir=$OPTARG
;;
D) # Specify the disks to be backed up
dump_drive_list=$OPTARG
;;
f) # Force full backup
full_backup=1
;;
i) # Perform an incremental backup
full_backup=0
;;
m) # Set the mount point where the EPOC files are to be found
psidir=$OPTARG
;;
v) # Turn on verbose logging
verbose=1
;;
V) # Display version and exit
usage
;;
?) # Invalid option
OPTIND=1
usage -d
;;
esac
done
shift $((OPTIND - 1))
# Check arguments
if [[ $# != 0 ]]; then
usage
fi
# Check whether all the appropriate directories and files exist
create_dirs "$localdir"
# Determine which EPOC device
machine_id=`
plpftp machinfo |
awk -F: '$1==" Machine UID" { print $2 }' |
sed -e 's/ //g'
`
machine_name=`
grep -v "^#" $HOME/epoc/etc/epoctab |
awk -F"\t" '$1=="'$machine_id'" {print $2}'
`
# Deal with the possibility of no name entry
if [[ -z $machine_name ]] ; then
echo "This is the first time this device has been backed up"
echo "on this machine."
echo "Please enter a machine name - eg: My Psion"
read -p "Machine name: " machine_name
# Should have a check to make sure this name hasn't already been used.
echo "#" >> $localdir/etc/epoctab
echo "$machine_id $machine_name" >> $localdir/etc/epoctab
fi
if [[ ! -d "$localdir"/backups/"$machine_name" ]] ; then
mkdir "$localdir"/backups/"$machine_name"
fi
# Create new entry in log file
#echo "==================================================" >> "$localdir"/etc/dumplog
#echo "== Starting backup ===============================" >> "$localdir"/etc/dumplog
#echo "==================================================" >> "$localdir"/etc/dumplog
# Shut down all processes running on the EPOC machine
echo killsave \"$localdir/etc/proclist.$machine_name\" |
plpftp
# plpftp >> "$localdir"/etc/dumplog
# Determine the drives on the machine, and process one by one
process_drives "$localdir" "$psidir" $full_backup "$machine_name" $dump_drive_list
# Restart all the stopped processes
echo runrestore \"$localdir/etc/proclist.$machine_name\" |
plpftp
# plpftp >> "$localdir"/etc/dumplog
# This is a hardwired hack due to Macro5 not restarting correctly
if [[ `grep -l "^Macro5" $localdir/etc/proclist."$machine_name"` ]] ; then
echo "Manually restarting Macro5"
echo run 'C:\System\Apps\Macro5\Macro5.app' |
plpftp
# plpftp >> "$localdir"/etc/dumplog
fi
|