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