Try not backing up spamd data, in case that pushes us over the edge.
[clinton/scripts.git] / hcoop-backup
CommitLineData
6d52e269 1#!/bin/bash -e
2
3#
4b645870 4# it is dangerous to remove the "-e" above; please don't do that.
6d52e269 5#
6
4b645870 7#
8# run this script as root, on deleuze
9#
6d52e269 10
4b645870 11exec >& /var/log/backup-to-megacz.com-log
44b7f284 12
4b645870 13PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin
44b7f284 14#COMPRESS_EXT=.bz2
15#COMPRESS_PROG=bzip2
16COMPRESS_EXT=.gz
17COMPRESS_PROG=gzip
24b2faa6 18
4b645870 19IFS=$'\n'
20
6d52e269 21KEYFILE=/etc/backup-encryption-key
4b645870 22BACKUPDIR=/afs/megacz.com/private/hcoop-backup/
24b2faa6 23
24cd $BACKUPDIR
81daff63 25find * -prune -ctime +2 -exec rm -rf {} \; || true
24b2faa6 26
27SUBDIR=`date +%Y.%m.%d`
28rm -rf $SUBDIR
29mkdir -p $SUBDIR
30cd $SUBDIR
31
4b645870 32groups
24b2faa6 33echo 'I am in:'
34pwd
35echo
6d52e269 36
37echo building package lists...
24b2faa6 38dpkg-query -W -f='${Package}\n' > packages
4b645870 39(cd /; find / /usr/ /usr/local/ /var/ -xdev) | sort | uniq > allfiles
24b2faa6 40dpkg-query -W -f='${Package}\n' | xargs dpkg -L | sort | uniq > debfiles
41dpkg-query -W -f='${Conffiles}\n' | grep / | cut -b2- | sed 's_ .*__' | sort | uniq > conffiles
6d52e269 42
43diff allfiles debfiles | grep '^<' | cut -b 3- | \
44 grep -v ^/var/cache | \
45 grep -v ^/var/tmp | \
46 grep -v ^/var/lib/dpkg | \
47 grep -v ^/var/backups | \
48 grep -v ^/var/lib/changetrack | \
12e40abc 49 grep -v ^/var/local/lib/spamd | \
6d52e269 50 grep -v ^/var/run | \
51 grep -v ^/var/lock | \
52 grep -v ^/var/lib/ucf | \
53 grep -v ^/vicepa | \
54 grep -v ^/home | \
55 grep -v ^/tmp | \
56 grep -v '^/afs$' | \
57 grep -v '^/$' | \
58 grep -v '^/usr/$' | \
59 grep -v ^/usr/src | \
92a7af97 60 grep -v '^/usr/.*\.pyc' | \
61 grep -v '^/usr/.*\.elc' | \
62 grep -v '^/usr/bin/perldoc\.stub$' | \
5b84f395 63 grep -v '^/usr/bin/.*\.notslocate$' | \
d327aed8 64 grep -v '^/usr/lib/courier/.*\.rand$' | \
50f51a78 65 grep -v '^/usr/lib/gconv/gconv-modules\.cache$' | \
4df0bc18 66 grep -v '^/usr/lib/graphviz/config$' | \
50f51a78 67 grep -v '^/usr/lib/locale/locale-archive$' | \
24b2faa6 68 grep -v '^/usr/share/info/dir$' | \
50f51a78 69 grep -v '^/usr/share/info/dir\.old$' | \
24b2faa6 70 grep -v '^/usr/share/emacs21/site-lisp/' | \
71 grep -v '^/usr/share/emacs22/site-lisp/' | \
50f51a78 72 grep -v '^/usr/share/vim/addons/doc/tags$' | \
6d52e269 73 cat > backupfiles
74
24b2faa6 75cat conffiles >> backupfiles
76
6d52e269 77cat backupfiles | \
78 grep -v ^/home | \
79 grep -v ^/usr/local | \
80 grep -v ^/var/spool | \
81 grep -v ^/var/log | \
82 grep -v ^/usr/lib/python2.4/ | \
83 grep -v ^/var/lib/python-support | \
84 grep -v ^/usr/share/man | \
4df0bc18 85 grep -v ^/usr/share/perl5/IkiWiki/Plugin | \
6d52e269 86 grep -v ^/media | \
87 grep -v ^/vmlinuz | \
88 grep -v ^/vmlinuz.old | \
92a7af97 89 grep -v '^/sbin/[a-z\-]*\.modutils$' | \
6d52e269 90 grep -v ^/opt/dell/srvadmin/ | \
91 grep -v ^/boot/ | \
24b2faa6 92 grep -v ^/dev/ | \
6d52e269 93 grep -v ^/etc/ | \
94 grep -v ^/root/ | \
95 grep -v ^/var/ | \
96 grep -v ^/lib/modules/ | \
97 grep -v ^/var/domtool/ | \
98 grep -v ^/var/lib/mysql/ | \
99 grep -v ^/var/lib/postgres/ | \
100 grep -v ^/var/lib/postgresql/ | \
4b645870 101 xargs -I{} -d\\n -- bash -c "test -L '{}' || echo '{}'" | \
6d52e269 102 cat > complain
103
4b645870 104tar clpf - --ignore-failed-read --no-recursion -C / -T backupfiles | \
eede979f 105 $COMPRESS_PROG | \
106 ccrypt -k $KEYFILE -e | \
107 catsync hcoop.backup.tar$COMPRESS_EXT.aescrypt
6d52e269 108
24b2faa6 109vos listvol deleuze | \
24b2faa6 110 tail -n +2 | \
111 head -n -3 | \
112 cut -b1-34 | \
113 grep -v "\.backup .*$" | \
eede979f 114 grep -v "\.readonly .*$" | \
4b645870 115 sed 's_^ .*__' | \
116 sed 's_ .*$__' | \
117 grep '[A-Za-z]' | \
eede979f 118 cat > volumes
24b2faa6 119
4b645870 120cat volumes | \
121 grep -v not-backed-up | \
122 xargs -I{} -d\\n -- \
123 bash -c \
124 "vos dump -id {} -localauth -clone | $COMPRESS_PROG | ccrypt -k $KEYFILE -e | catsync {}.dump$COMPRESS_EXT.aescrypt"
125
126echo backing up databases
127tar -C /var/backups/databases/ -cf - . | \
128 $COMPRESS_PROG | \
129 ccrypt -k $KEYFILE -e \
130 | catsync databases.tar$COMPRESS_EXT.aescrypt
131
132grep '[a-z/]' complain && \
133 mail -a 'From: Adam Megacz <megacz@hcoop.net>' \
134 -s "automated message: annoying files found on deleuze (please do something about them)" admins@hcoop.net \
135 < complain \
136 || true
44b7f284 137
138echo done
139