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 if [ -f /etc/lsbackups.conf ]
16 # file locations and other values
17 today=$(date +%Y%m%d%H%M%S)
18 isoimage="$imagedir/$today.img"
19 isomountdir="$isoimage.mnt"
20 restorescript="$scriptsdir/restore.sh"
22 echo "-> Creating directories"
23 mkdir --mode=700 -p $datadir $imagedir $isomountdir $tmpdir
26 if test -d $isomountdir
30 echo "-E- Unable to create the following directories: "
31 echo " $datadir $imagedir $isomountdir $tmpdir"
35 echo "-> Creating the iso image in $isoimage"
36 dd if=/dev/null of=$isoimage bs=1M count=0 seek=4440
37 mke2fs -b 2048 -F $isoimage
40 rm -rf $isomountdir $isoimage
41 echo "-E- Unable to create the iso image: $isoimage"
45 echo "-> Mounting the iso image"
46 mount -t ext2 -o loop $isoimage $isomountdir
49 rm -rf $isomountdir $isoimage
50 echo "-E- Unable to mount the iso image: $isoimage -> $isomountdir"
54 echo "-> Directories being backedup and excluded:"
55 echo "backupdirs: $backupdirs"
56 echo "excludedirs: $excludedirs"
58 echo "-> Running find to get the status of files"
61 findformat="$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0"
62 if [ -z $excludeddirs ]
64 find $backupdirs -type $type -printf "$findformat"
66 regex=`echo $excludedirs | sed -e 's/ /.*\\\\|/g'`
67 regex=`echo "'\($regex.*\)'"`
68 find $backupdirs -type $type -o -regex $regex -prune -o -printf "$findformat"
73 echo "-> Determining list of files to backup with lsbackups"
75 # lsbackups expects the current date followed by a null before the list of files
78 } | lsbackups > $backups 2>$statusfile
80 echo "-> Running rsync to pack the image"
81 rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress"
82 cat $backups | rsync $rsyncopts / $isomountdir
86 rm -rf $isomountdir $isoimage
87 echo "-E- Unable to rsync to pack the image"
91 echo "-> Copying over database and status file"
92 cp $statusfile $backupdb $restorescript $isomountdir
95 echo "-E- Unable to copy the database and status file"
99 echo "-> Unmounting image"
103 echo "-E- Unable to unmount the iso dir: $isomountdir"
107 echo "-> Calculating md5sum for image"
108 md5sum $isoimage | awk '{print$1}' > $isoimage.md5sum
111 echo "-E- Unable to calculatethe md5sum for this image: $isoimage"
115 cat $statusfile | mailx -s "DVD image available to burn - $today" $mailto
117 echo $today > $lastbackupfile