apache-sync-logs: copy to a temp dir, set perms, and then copy over to AFS
[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
24b2faa6 12
6d52e269 13#KEYFILE=$1
14KEYFILE=/etc/backup-encryption-key
24b2faa6 15BACKUPDIR=/afs/megacz.com/hcoop-backup/
16
17cd $BACKUPDIR
18find * -prune -ctime +5 -exec rm -rf {} \;
19
20SUBDIR=`date +%Y.%m.%d`
21rm -rf $SUBDIR
22mkdir -p $SUBDIR
23cd $SUBDIR
24
25echo 'I am in:'
26pwd
27echo
6d52e269 28
29echo building package lists...
24b2faa6 30dpkg-query -W -f='${Package}\n' > packages
31(cd /; sudo find / /usr/ /usr/local/ /var/ -xdev) | sort | uniq > allfiles
32dpkg-query -W -f='${Package}\n' | xargs dpkg -L | sort | uniq > debfiles
33dpkg-query -W -f='${Conffiles}\n' | grep / | cut -b2- | sed 's_ .*__' | sort | uniq > conffiles
6d52e269 34
35diff 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 | \
24b2faa6 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/' | \
6d52e269 57 cat > backupfiles
58
24b2faa6 59cat conffiles >> backupfiles
60
6d52e269 61cat 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 | \
24b2faa6 70 grep -v ^/usr/lib/locale/locale-archive | \
6d52e269 71 grep -v ^/vmlinuz | \
72 grep -v ^/vmlinuz.old | \
73 grep -v '^/sbin/[a-z\-]*.modutils$' | \
74 cat > annoyingfiles-
75
76for A in `cat annoyingfiles-`
77do \
78 test -L "$A" || echo "$A"
79done > annoyingfiles
80
81cat annoyingfiles | \
82 grep -v ^/opt/dell/srvadmin/ | \
83 grep -v ^/boot/ | \
24b2faa6 84 grep -v ^/dev/ | \
6d52e269 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
24b2faa6 95grep '[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
100cp 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
105du -chs hcoop.backup.tar.gz.aescrypt
6d52e269 106
24b2faa6 107vos 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
116for A in mysql postgres; do \
117echo backing up $A
118tar -C /var/backups/databases/$A -cf - | \
119 gzip | \
120 ccrypt -k $KEYFILE -e \
121 > database-$A.backup.tar.gz.aescrypt
122done
6d52e269 123
6d52e269 124for A in `cat volumes`
125do \
126 echo "dumping afs volume $A..."
24b2faa6 127 time (cd /; sudo vos dump -id $A -localauth -clone) | gzip | ccrypt -k $KEYFILE -e > $A.dump.gz.aescrypt
6d52e269 128done