Better dd command
[backups/.git] / scripts / drive.sh
1 #!/bin/bash
2
3 scriptsdir=$(dirname $0)
4 bindir="$scriptsdir/../build"
5
6 export PATH=$scriptsdir:$bindir:$PATH
7
8 # file locations and other values
9 today=$(date +%Y%m%d%H%M%S)
10 datadir="/var/lib/backups"
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/iso-mount.iso"
18
19 echo "Creating the iso image in $isoimage"
20 touch $isoimage
21 # chmod 600 $isoimage
22
23 # Create filesystem on iso image here
24 dd if=/dev/null of=$isoimage bs=2048k count=0 seek=2220
25 mke2fs -b 2048 -F $isoimage
26
27 echo "Mounting the iso image"
28 # Mount iso image here
29 mount -t ext2 -o loop $isoimage $isomountdir
30
31 mkdir -p $tmpdir
32 chmod 700 $tmpdir
33
34 touch $currentfiles
35 chmod 600 $currentfiles
36 echo "Running find to get the status of files"
37 find-cmd.sh /home > $currentfiles
38
39 echo "Determining list of files to backup with lsbackups"
40 {
41   # lsbackups expects the current date followed by a null before the list of files
42   printf "$today\0"
43   cat $currentfiles
44 } | lsbackups > $backups 2>$statusfile
45
46 echo "Running rsync to pack the image"
47 cat $backups | rsync-cmd.sh $isomountdir
48
49 echo "Copying over database and status file"
50 cp $statusfile $backupdb $isomountdir
51
52 # umount $isomountdir
53
54 # Burn the iso image
55 # dvdrecord [-dummy] [-overburn] -dao speed=8 dev=[ATAPI:]?,?,? iso-image.iso
56 cat $statusfile | mailx -s "DVD Image available on ball, burn it!" carl@ecbaldwin.net