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 echo "-E- Unable to create the following directories: "
28 echo " $datadir $imagedir $isomountdir $tmpdir"
32 echo "-> Creating the iso image in $isoimage"
33 dd if=/dev/null of=$isoimage bs=1M count=0 seek=4440
34 mke2fs -b 2048 -F $isoimage
37 rm -rf $isomountdir $isoimage
38 echo "-E- Unable to create the iso image: $isoimage"
42 echo "-> Mounting the iso image"
43 mount -t ext2 -o loop $isoimage $isomountdir
46 rm -rf $isomountdir $isoimage
47 echo "-E- Unable to mount the iso image: $isoimage -> $isomountdir"
51 echo "-> Directories being backedup and excluded:"
52 echo "backupdirs: $backupdirs"
53 echo "excludedirs: $excludedirs"
55 echo "-> Running find to get the status of files"
58 findformat="$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0"
59 if [ -z $excludeddirs ]
61 find $backupdirs -type $type -printf "$findformat"
63 regex=`echo $excludedirs | sed -e 's/ /.*\\\\|/g'`
64 regex=`echo "'\($regex.*\)'"`
65 find $backupdirs -type $type -o -regex $regex -prune -o -printf "$findformat"
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
84 echo "-E- Unable to rsync to pack the image"
88 echo "-> Copying over database and status file"
89 cp $statusfile $backupdb $restorescript $isomountdir
92 echo "-E- Unable to copy the database and status file"
96 echo "-> Unmounting image"
100 echo "-E- Unable to unmount the iso dir: $isomountdir"
104 echo "-> Calculating md5sum for image"
105 md5sum $isoimage | awk '{print$1}' > $isoimage.md5sum
108 echo "-E- Unable to calculatethe md5sum for this image: $isoimage"
112 cat $statusfile | mailx -s "DVD image available to burn - $today" $mailto
114 echo $today > $lastbackupfile