hcoop-backup: Sync changes from megacz, add IFS lines
[hcoop/scripts.git] / hcoop-backup
CommitLineData
6d52e269 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
44b7f284 12#umask 0644
13
eede979f 14# for catsync
44b7f284 15#PATH=$PATH:/home/megacz_admin/
16#COMPRESS_EXT=.bz2
17#COMPRESS_PROG=bzip2
18COMPRESS_EXT=.gz
19COMPRESS_PROG=gzip
24b2faa6 20
6d52e269 21#KEYFILE=$1
22KEYFILE=/etc/backup-encryption-key
24b2faa6 23BACKUPDIR=/afs/megacz.com/hcoop-backup/
24
25cd $BACKUPDIR
44b7f284 26find * -prune -ctime +2 -exec rm -rf {} \;
24b2faa6 27
28SUBDIR=`date +%Y.%m.%d`
29rm -rf $SUBDIR
30mkdir -p $SUBDIR
31cd $SUBDIR
32
33echo 'I am in:'
34pwd
35echo
6d52e269 36
37echo building package lists...
24b2faa6 38dpkg-query -W -f='${Package}\n' > packages
39(cd /; sudo find / /usr/ /usr/local/ /var/ -xdev) | sort | uniq > allfiles
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 | \
49 grep -v ^/var/run | \
50 grep -v ^/var/lock | \
51 grep -v ^/var/lib/ucf | \
52 grep -v ^/vicepa | \
53 grep -v ^/home | \
54 grep -v ^/tmp | \
55 grep -v '^/afs$' | \
56 grep -v '^/$' | \
57 grep -v '^/usr/$' | \
58 grep -v ^/usr/src | \
92a7af97 59 grep -v '^/usr/.*\.pyc' | \
60 grep -v '^/usr/.*\.elc' | \
61 grep -v '^/usr/bin/perldoc\.stub$' | \
d327aed8 62 grep -v '^/usr/lib/courier/.*\.rand$' | \
50f51a78 63 grep -v '^/usr/lib/gconv/gconv-modules\.cache$' | \
4df0bc18 64 grep -v '^/usr/lib/graphviz/config$' | \
50f51a78 65 grep -v '^/usr/lib/locale/locale-archive$' | \
24b2faa6 66 grep -v '^/usr/share/info/dir$' | \
50f51a78 67 grep -v '^/usr/share/info/dir\.old$' | \
24b2faa6 68 grep -v '^/usr/share/emacs21/site-lisp/' | \
69 grep -v '^/usr/share/emacs22/site-lisp/' | \
50f51a78 70 grep -v '^/usr/share/vim/addons/doc/tags$' | \
6d52e269 71 cat > backupfiles
72
24b2faa6 73cat conffiles >> backupfiles
74
6d52e269 75cat backupfiles | \
76 grep -v ^/home | \
77 grep -v ^/usr/local | \
78 grep -v ^/var/spool | \
79 grep -v ^/var/log | \
80 grep -v ^/usr/lib/python2.4/ | \
81 grep -v ^/var/lib/python-support | \
82 grep -v ^/usr/share/man | \
4df0bc18 83 grep -v ^/usr/share/perl5/IkiWiki/Plugin | \
6d52e269 84 grep -v ^/media | \
85 grep -v ^/vmlinuz | \
86 grep -v ^/vmlinuz.old | \
92a7af97 87 grep -v '^/sbin/[a-z\-]*\.modutils$' | \
6d52e269 88 cat > annoyingfiles-
89
44b7f284 90OLDIFS=$IFS
91IFS="
92"
93
6d52e269 94for A in `cat annoyingfiles-`
95do \
96 test -L "$A" || echo "$A"
97done > annoyingfiles
98
44b7f284 99IFS=$OLDIFS
100
6d52e269 101cat annoyingfiles | \
102 grep -v ^/opt/dell/srvadmin/ | \
103 grep -v ^/boot/ | \
24b2faa6 104 grep -v ^/dev/ | \
6d52e269 105 grep -v ^/etc/ | \
106 grep -v ^/root/ | \
107 grep -v ^/var/ | \
108 grep -v ^/lib/modules/ | \
109 grep -v ^/var/domtool/ | \
110 grep -v ^/var/lib/mysql/ | \
111 grep -v ^/var/lib/postgres/ | \
112 grep -v ^/var/lib/postgresql/ | \
113 cat > complain
114
24b2faa6 115grep '[a-z/]' complain && \
116 mail -a 'From: Adam Megacz <megacz@hcoop.net>' \
117 -s "automated message: annoying files found on deleuze (please do something about them)" admins@hcoop.net \
118 < complain
119
120cp backupfiles /tmp/backupfiles
44b7f284 121(cd /; sudo tar cvlpf - --ignore-failed-read --no-recursion -C / -T /tmp/backupfiles) | \
eede979f 122 $COMPRESS_PROG | \
123 ccrypt -k $KEYFILE -e | \
124 catsync hcoop.backup.tar$COMPRESS_EXT.aescrypt
125du -chs hcoop.backup.tar$COMPRESS_EXT.aescrypt
6d52e269 126
24b2faa6 127vos listvol deleuze | \
24b2faa6 128 tail -n +2 | \
129 head -n -3 | \
130 cut -b1-34 | \
131 grep -v "\.backup .*$" | \
eede979f 132 grep -v "\.readonly .*$" | \
133 cat > volumes
24b2faa6 134
44b7f284 135echo volume list:
136cat volumes | grep -v not-backed-up
137
138IFS="
139"
6d52e269 140
eede979f 141for A in `cat volumes | grep -v not-backed-up`
6d52e269 142do \
143 echo "dumping afs volume $A..."
44b7f284 144 vos dump -id $A -localauth -clone | \
eede979f 145 $COMPRESS_PROG | \
146 ccrypt -k $KEYFILE -e | \
147 catsync $A.dump$COMPRESS_EXT.aescrypt
44b7f284 148 echo " finished dumping afs volume $A."
6d52e269 149done
44b7f284 150
151# for some reason this has been causing the backups to abort...
152#echo backing up databases
153#tar -C /var/backups/databases/ -cf - . | \
154# $COMPRESS_PROG | \
155# ccrypt -k $KEYFILE -e \
156# | catsync databases.tar$COMPRESS_EXT.aescrypt
157
158echo done
159