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 # process command line arguments
18 # file locations and other values
19 today=$(date +%Y%m%d%H%M%S)
20 isoimage="$imagedir/$today.iso"
21 isomountdir="$isoimage.mnt"
22 restorescript="$scriptsdir/restore.sh"
24 echo "-> Creating directories"
25 mkdir --mode=700 -p $datadir $imagedir $isomountdir $tmpdir
28 if test -d $isomountdir
32 err "Unable to create the following directories:
33 $datadir $imagedir $isomountdir $tmpdir"
36 echo "-> Creating the iso image in $isoimage"
37 dd of=$isoimage bs=1M count=0 seek=$imagesizemb
39 [ $? != 0 ] && err "dd failed to create $isoimage"
41 mke2fs -b $blocksize -F $isoimage
45 rm -rf $isomountdir $isoimage
46 err "Unable to create the iso image: $isoimage"
49 e2label $isoimage $today
53 rm -rf $isomountdir $isoimage
54 err "Unable to label the iso image: $isoimage"
57 echo "-> Mounting the iso image"
58 mount -t ext2 -o loop $isoimage $isomountdir
61 rm -rf $isomountdir $isoimage
62 err "Unable to mount the iso image: $isoimage -> $isomountdir"
65 echo "-> Directories being backedup and excluded:"
66 echo "backupdirs: $backupdirs"
67 echo "excludedirs: $excludedirs"
69 echo "-> Running find to get the status of files"
72 findformat="$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0"
73 if [ -z "$excludedirs" ]
75 find $backupdirs -type $type -printf "$findformat"
77 echo $excludedirs | sed -e 's/ /\n/g' > $tmpdir/excluded
78 find $backupdirs -type $type -printf "$findformat" | grep -z -v -f $tmpdir/excluded
85 backupdbin=$backupdbout
88 echo "-> Determining list of files to backup with lsbackups"
90 # lsbackups expects the current date followed by a null before the list of files
93 } | lsbackups > $backups 2>$statusfile
98 rm -rf $isomountdir $isoimage
100 echo "-> Simulated backup complete! Backup database: $backupdbout"
104 echo "-> Running rsync to pack the image"
105 rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress"
106 cat $backups | rsync $rsyncopts / $isomountdir
110 rm -rf $isomountdir $isoimage $backupdbout
111 err "Unable to rsync to pack the image"
114 echo "-> Copying over database and status file"
115 cp $backupdbout $isomountdir/$(basename $backupdbin)
116 [ $? != 0 ] && err "Unable to copy the database to $isomountdir"
118 cp $statusfile $restorescript $isomountdir
119 [ $? != 0 ] && err "Unable to copy the status file to $isomountdir"
121 echo "-> Unmounting image"
124 [ $? != 0 ] && err "Unable to unmount the iso dir: $isomountdir"
126 echo "-> Calculating md5sum for image"
127 md5sum $isoimage | awk '{print$1}' > $isoimage.md5sum
129 [ $? != 0 ] && err "Unable to calculate the md5sum for this image: $isoimage"
131 cat $statusfile | mailx -s "DVD image available to burn - $today" $mailto
133 echo $today > $lastbackupfile
135 echo "-> Moving new database to $backupdbin"
136 mv $backupdbout $backupdbin
137 [ $? != 0 ] && err "Unable to move backupdb: $backupdbout to $backupdbin"