Merge branch 'master' of home:dvl/backup
[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 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=2048k count=0 seek=2220
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 /home -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 # umount $isomountdir
60
61 # Burn the iso image
62 # dvdrecord [-dummy] [-overburn] -dao speed=8 dev=[ATAPI:]?,?,? iso-image.iso
63 cat $statusfile | mailx -s "DVD Image available on ball, burn it!" carl@ecbaldwin.net