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
14 # process command line arguments
19 # file locations and other values
20 today=$(date +%Y%m%d%H%M%S)
21 isoimage="$imagedir/$today.iso"
22 isomountdir="$isoimage.mnt"
23 restorescript="$scriptsdir/restore.sh"
25 echo "-> Creating directories"
26 mkdir --mode=700 -p $datadir $imagedir $isomountdir $tmpdir
28 test -d $isomountdir && rm -rf $isomountdir
29 err "Unable to create the following directories:
30 $datadir $imagedir $isomountdir $tmpdir"
33 echo "-> Creating the iso image in $isoimage"
34 dd of=$isoimage bs=1M count=0 seek=$imagesizemb
36 [ $? != 0 ] && err "dd failed to create $isoimage"
38 mke2fs -b $blocksize -F $isoimage
40 rm -rf $isomountdir $isoimage
41 err "Unable to create the iso image: $isoimage"
44 e2label $isoimage $today
46 rm -rf $isomountdir $isoimage
47 err "Unable to label the iso image: $isoimage"
50 echo "-> Mounting the iso image"
51 mount -t ext2 -o loop $isoimage $isomountdir
53 rm -rf $isomountdir $isoimage
54 err "Unable to mount the iso image: $isoimage -> $isomountdir"
57 echo "-> Directories being backedup and excluded:"
58 echo "backupdirs: $backupdirs"
59 echo "excludedirs: $excludedirs"
61 echo "-> Running find to get the status of files"
64 findformat="$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0"
65 if [ -z "$excludedirs" ]; then
66 find $backupdirs -type $type -printf "$findformat"
68 echo $excludedirs | sed -e 's/ /\n/g' > $tmpdir/excluded
69 find $backupdirs -type $type -printf "$findformat" | grep -z -v -f $tmpdir/excluded
74 if [ -n $simulate ]; then
75 backupdbin=$backupdbout
78 echo "-> Determining list of files to backup with lsbackups"
80 # lsbackups expects the current date followed by a null before the list of files
83 } | lsbackups > $backups 2>$statusfile
85 if [ -n $simulate ]; then
87 rm -rf $isomountdir $isoimage
89 echo "-> Simulated backup complete! Backup database: $backupdbout"
93 echo "-> Running rsync to pack the image"
94 rsyncopts="-W -H -S -l -p -t -g -o -0 --files-from=- --stats --progress"
95 cat $backups | rsync $rsyncopts / $isomountdir
98 rm -rf $isomountdir $isoimage $backupdbout
99 err "Unable to rsync to pack the image"
102 echo "-> Copying over database and status file"
103 cp $backupdbout $isomountdir/$(basename $backupdbin)
104 [ $? != 0 ] && err "Unable to copy the database to $isomountdir"
106 cp $statusfile $restorescript $isomountdir
107 [ $? != 0 ] && err "Unable to copy the status file to $isomountdir"
109 echo "-> Unmounting image"
112 [ $? != 0 ] && err "Unable to unmount the iso dir: $isomountdir"
114 echo "-> Calculating md5sum for image"
115 md5sum $isoimage | awk '{print$1}' > $isoimage.md5sum
117 [ $? != 0 ] && err "Unable to calculate the md5sum for this image: $isoimage"
119 cat $statusfile | mailx -s "DVD image available to burn - $today" $mailto
121 echo $today > $lastbackupfile
123 echo "-> Moving new database to $backupdbin"
124 mv $backupdbout $backupdbin
125 [ $? != 0 ] && err "Unable to move backupdb: $backupdbout to $backupdbin"