Add more directories
[backups/.git] / scripts / drive.sh
1 #!/bin/bash
2
3 scriptsdir=$(dirname $0)
4
5 export PATH=$scriptsdir:$PATH
6
7 # file locations and other values
8 today=$(date +%Y%m%d%H%M%S)
9 datadir="/var/lib/backups"
10 backupdirs="/home /etc /var/backups /var/lib/debfoster /var/lib/mailman /var/lib/iptables /var/lib/dpkg"
11 tmpdir="/dev/shm/backups"
12 currentfiles="$tmpdir/files.db"
13 backupdb="$datadir/backups.db"
14 backups="$tmpdir/backup-list.db"
15 statusfile="$tmpdir/backup-status.txt"
16 isomountdir="/backup/iso-mount"
17 isoimage="/backup/ISOs/$today.iso"
18 restorescript="$scriptsdir/restore.sh"
19
20 echo "Creating the iso image in $isoimage"
21 touch $isoimage
22 # chmod 600 $isoimage
23
24 # Create filesystem on iso image here
25 dd if=/dev/null of=$isoimage bs=1M count=0 seek=4440
26 mke2fs -b 2048 -F $isoimage
27
28 echo "Mounting the iso image"
29 # Mount iso image here
30 mount -t ext2 -o loop $isoimage $isomountdir
31
32 mkdir -p $tmpdir
33 chmod 700 $tmpdir
34
35 touch $currentfiles
36 chmod 600 $currentfiles
37 echo "Running find to get the status of files"
38 {
39   for type in d f l; do
40     findformat="$type %#m %u %g %s %CY%Cm%Cd%CH%CM%CS 0 %p\0"
41     find $backupdirs -type $type -printf "$findformat"
42   done
43 } > $currentfiles
44
45 echo "Determining list of files to backup with lsbackups"
46 {
47   # lsbackups expects the current date followed by a null before the list of files
48   printf "$today\0"
49   cat $currentfiles
50 } | lsbackups > $backups 2>$statusfile
51
52 echo "Running rsync to pack the image"
53 rsyncopts="-l -p -t -g -o -0 --files-from=- --stats --progress"
54 cat $backups | rsync $rsyncopts / $isomountdir
55
56 echo "Copying over database and status file"
57 cp $statusfile $backupdb $restorescript $isomountdir
58
59 mount -o remount -o ro $isomountdir
60 # Should be
61 # umount $isomountdir
62
63 md5sum $isoimage > $isoimage.md5sum
64
65 # Burn the iso image
66 # dvdrecord [-dummy] [-overburn] -dao speed=8 dev=[ATAPI:]?,?,? iso-image.iso
67
68 # Email me
69 cat $statusfile | mailx -s "DVD Image available on ball, burn it!" carl@ecbaldwin.net