create-user: Run domtool-adduser
[clinton/scripts.git] / hcoop-backup
1 #!/bin/bash -e
2
3 #
4 # run this script as root, on deleuze, in a directory that WILL NOT be
5 # part of the backup (/tmp is a good choice).
6 #
7
8 # FIXME:
9 # postgres dumps
10 # mysql dumps
11
12
13 #KEYFILE=$1
14 KEYFILE=/etc/backup-encryption-key
15 BACKUPDIR=/afs/megacz.com/hcoop-backup/
16
17 cd $BACKUPDIR
18 find * -prune -ctime +5 -exec rm -rf {} \;
19
20 SUBDIR=`date +%Y.%m.%d`
21 rm -rf $SUBDIR
22 mkdir -p $SUBDIR
23 cd $SUBDIR
24
25 echo 'I am in:'
26 pwd
27 echo
28
29 echo building package lists...
30 dpkg-query -W -f='${Package}\n' > packages
31 (cd /; sudo find / /usr/ /usr/local/ /var/ -xdev) | sort | uniq > allfiles
32 dpkg-query -W -f='${Package}\n' | xargs dpkg -L | sort | uniq > debfiles
33 dpkg-query -W -f='${Conffiles}\n' | grep / | cut -b2- | sed 's_ .*__' | sort | uniq > conffiles
34
35 diff allfiles debfiles | grep '^<' | cut -b 3- | \
36 grep -v ^/var/cache | \
37 grep -v ^/var/tmp | \
38 grep -v ^/var/lib/dpkg | \
39 grep -v ^/var/backups | \
40 grep -v ^/var/lib/changetrack | \
41 grep -v ^/var/run | \
42 grep -v ^/var/lock | \
43 grep -v ^/var/lib/ucf | \
44 grep -v ^/vicepa | \
45 grep -v ^/home | \
46 grep -v ^/tmp | \
47 grep -v '^/afs$' | \
48 grep -v '^/$' | \
49 grep -v '^/usr/$' | \
50 grep -v ^/usr/src | \
51 grep -v '^/usr/.*pyc' | \
52 grep -v '^/usr/.*elc' | \
53 grep -v '^/usr/share/info/dir$' | \
54 grep -v '^/usr/share/info/dir.old$' | \
55 grep -v '^/usr/share/emacs21/site-lisp/' | \
56 grep -v '^/usr/share/emacs22/site-lisp/' | \
57 cat > backupfiles
58
59 cat conffiles >> backupfiles
60
61 cat backupfiles | \
62 grep -v ^/home | \
63 grep -v ^/usr/local | \
64 grep -v ^/var/spool | \
65 grep -v ^/var/log | \
66 grep -v ^/usr/lib/python2.4/ | \
67 grep -v ^/var/lib/python-support | \
68 grep -v ^/usr/share/man | \
69 grep -v ^/media | \
70 grep -v ^/usr/lib/locale/locale-archive | \
71 grep -v ^/vmlinuz | \
72 grep -v ^/vmlinuz.old | \
73 grep -v '^/sbin/[a-z\-]*.modutils$' | \
74 cat > annoyingfiles-
75
76 for A in `cat annoyingfiles-`
77 do \
78 test -L "$A" || echo "$A"
79 done > annoyingfiles
80
81 cat annoyingfiles | \
82 grep -v ^/opt/dell/srvadmin/ | \
83 grep -v ^/boot/ | \
84 grep -v ^/dev/ | \
85 grep -v ^/etc/ | \
86 grep -v ^/root/ | \
87 grep -v ^/var/ | \
88 grep -v ^/lib/modules/ | \
89 grep -v ^/var/domtool/ | \
90 grep -v ^/var/lib/mysql/ | \
91 grep -v ^/var/lib/postgres/ | \
92 grep -v ^/var/lib/postgresql/ | \
93 cat > complain
94
95 grep '[a-z/]' complain && \
96 mail -a 'From: Adam Megacz <megacz@hcoop.net>' \
97 -s "automated message: annoying files found on deleuze (please do something about them)" admins@hcoop.net \
98 < complain
99
100 cp backupfiles /tmp/backupfiles
101 (cd /; sudo tar cvlpjf - --ignore-failed-read --no-recursion -C / -T /tmp/backupfiles) | \
102 gzip | \
103 ccrypt -k $KEYFILE -e \
104 > hcoop.backup.tar.gz.aescrypt
105 du -chs hcoop.backup.tar.gz.aescrypt
106
107 vos listvol deleuze | \
108 grep -v common.debian | \
109 tail -n +2 | \
110 head -n -3 | \
111 cut -b1-34 | \
112 grep -v "\.backup .*$" | \
113 grep -v "\.readonly .*$" \
114 > volumes
115
116 for A in mysql postgres; do \
117 echo backing up $A
118 tar -C /var/backups/databases/$A -cf - | \
119 gzip | \
120 ccrypt -k $KEYFILE -e \
121 > database-$A.backup.tar.gz.aescrypt
122 done
123
124 for A in `cat volumes`
125 do \
126 echo "dumping afs volume $A..."
127 time (cd /; sudo vos dump -id $A -localauth -clone) | gzip | ccrypt -k $KEYFILE -e > $A.dump.gz.aescrypt
128 done