3 scriptsdir=$(dirname $0)
5 export PATH=$scriptsdir:/bin:/usr/bin:/sbin:/usr/sbin
7 # source the default configuration
10 # source the system specific configuration
11 [ -f /etc/lsbackups.conf ] && . /etc/lsbackups.conf
13 # file locations and other values
14 today=$(date +%Y%m%d%H%M%S)
15 isoimage="$imagedir/$today.img"
16 isomountdir="$isoimage.mnt"
17 restorescript="$scriptsdir/restore.sh"
19 echo "-> Creating directories"
20 mkdir --mode=700 -p $datadir $imagedir $isomountdir $tmpdir
23 if test -d $isomountdir
27 err "Unable to create the following directories:
28 $datadir $imagedir $isomountdir $tmpdir"
31 echo "-> Creating the iso image in $isoimage"
32 dd of=$isoimage bs=1M count=0 seek=4440
34 [ $? != 0 ] && err "dd failed to create $isoimage"
36 mke2fs -b 2048 -F $isoimage
40 rm -rf $isomountdir $isoimage
41 err "Unable to create the iso image: $isoimage"
44 echo "-> Mounting the iso image"
45 mount -t ext2 -o loop $isoimage $isomountdir
48 rm -rf $isomountdir $isoimage
49 err "Unable to mount the iso image: $isoimage -> $isomountdir"
52 echo "-> Directories being backedup and excluded:"
53 echo "backupdirs: $backupdirs"
54 echo "excludedirs: $excludedirs"
56 echo "-> Running find to get the status of files"
59 findformat="$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0"
60 if [ -z $excludedirs ]
62 find $backupdirs -type $type -printf "$findformat"
64 echo $excludedirs | sed -e 's/ /\n/g' > $tmpdir/excluded
65 find $backupdirs -type $type -printf "$findformat" | grep -z -v -f $tmpdir/excluded
70 echo "-> Determining list of files to backup with lsbackups"
72 # lsbackups expects the current date followed by a null before the list of files
75 } | lsbackups > $backups 2>$statusfile
77 echo "-> Running rsync to pack the image"
78 rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress"
79 cat $backups | rsync $rsyncopts / $isomountdir
83 rm -rf $isomountdir $isoimage $backupdb.tmp
84 err "Unable to rsync to pack the image"
87 echo "-> Copying over database and status file"
88 mv $backupdb.tmp $backupdb
89 cp $statusfile $backupdb $restorescript $isomountdir
91 [ $? != 0 ] && err "Unable to copy the database and status file"
93 echo "-> Unmounting image"
96 [ $? != 0 ] && err "Unable to unmount the iso dir: $isomountdir"
98 echo "-> Calculating md5sum for image"
99 md5sum $isoimage | awk '{print$1}' > $isoimage.md5sum
101 [ $? != 0 ] && err "Unable to calculate the md5sum for this image: $isoimage"
103 cat $statusfile | mailx -s "DVD image available to burn - $today" $mailto
105 echo $today > $lastbackupfile