4 # it is dangerous to remove the "-e" above; please don't do that.
8 # run this script as root, on deleuze
11 exec >& /var
/log
/backup-to-s3-log
13 PATH
=$PATH:/bin
:/usr
/bin
:/sbin
:/usr
/sbin
18 # units for BWLIMIT are KB/s
20 # units for CHUNKSIZE are MB
25 SCRIPTDIR
=$
(dirname $0)
26 KEYFILE
=/etc
/backup-encryption-key
27 BUCKET
=hcoop.net-backups
29 BACKUPTMP
=/var
/backups
/hcoop-backup-testing
30 SUBDIR
=$
(date +%Y.
%m.
%d
)
32 export S3_ACCESS_KEY_ID
=$
(cat ~mwolson_admin
/.amazon
/access.key
)
33 export S3_SECRET_ACCESS_KEY
=~mwolson_admin
/.amazon
/secret.key
36 # $1: command (get|put|ls|rm)
42 if test "$cmd" = "put"; then
47 $SCRIPTDIR/s3
$cmd $BUCKET "$1" "$2" $bwarg
50 function copy_over
() {
51 # Move file to its offsite destination
52 # $1: file, $2: relative directory (optional)
53 if test -z "$1" ||
test -n "$3"; then
54 echo "Bad programming"
58 local DEST
=$BACKUPDIR/$SUBDIR
62 split -d -b ${CHUNKSIZE}m
$FILE ${FILE}.
63 for i
in ${FILE}.
*; do
64 s3_cmd put
$DEST/$i $i
70 function prune_old_backups
() {
73 find .
-mindepth 1 -maxdepth 1 -type d
-ctime +7 \
74 -execdir rm -fr '{}' \
; || true
90 echo building package lists...
91 dpkg-query
-W -f='${Package}\n' > packages
92 (cd /; find / /usr
/ /usr
/local
/ /var
/ -xdev) |
sort |
uniq > allfiles
93 dpkg-query
-W -f='${Package}\n' |
xargs dpkg
-L |
sort |
uniq > debfiles
94 dpkg-query
-W -f='${Conffiles}\n' |
grep / | cut
-b2- | \
95 sed 's_ .*__' |
sort |
uniq > conffiles
97 diff allfiles debfiles |
grep '^<' | cut
-b 3- | \
98 grep -v ^
/var
/cache | \
100 grep -v ^
/var
/lib
/dpkg | \
101 grep -v ^
/var
/backups | \
102 grep -v ^
/var
/lib
/changetrack | \
103 grep -v ^
/var
/local
/lib
/spamd | \
104 grep -v ^
/var
/run | \
105 grep -v ^
/var
/lock | \
106 grep -v ^
/var
/lib
/ucf | \
112 grep -v '^/usr/$' | \
113 grep -v ^
/usr
/src | \
114 grep -v '^/usr/.*\.pyc' | \
115 grep -v '^/usr/.*\.elc' | \
116 grep -v '^/usr/bin/perldoc\.stub$' | \
117 grep -v '^/usr/bin/.*\.notslocate$' | \
118 grep -v '^/usr/lib/courier/.*\.rand$' | \
119 grep -v '^/usr/lib/gconv/gconv-modules\.cache$' | \
120 grep -v '^/usr/lib/graphviz/config$' | \
121 grep -v '^/usr/lib/locale/locale-archive$' | \
122 grep -v '^/usr/share/info/dir$' | \
123 grep -v '^/usr/share/info/dir\.old$' | \
124 grep -v '^/usr/share/emacs21/site-lisp/' | \
125 grep -v '^/usr/share/emacs22/site-lisp/' | \
126 grep -v '^/usr/share/snmp/mibs/\.index$' | \
127 grep -v '^/usr/share/vim/addons/doc/tags$' \
130 cat conffiles
>> backupfiles
134 grep -v ^
/usr
/local | \
135 grep -v ^
/var
/spool | \
136 grep -v ^
/var
/log | \
137 grep -v ^
/usr
/lib
/python2.4
/ | \
138 grep -v ^
/var
/lib
/python-support | \
139 grep -v ^
/usr
/share
/jed
/lib | \
140 grep -v ^
/usr
/share
/man | \
141 grep -v ^
/usr
/share
/perl
5/IkiWiki
/Plugin | \
143 grep -v ^
/vmlinuz | \
144 grep -v ^
/vmlinuz.old | \
145 grep -v '^/sbin/[a-z\-]*\.modutils$' | \
146 grep -v ^
/opt
/dell
/srvadmin
/ | \
152 grep -v ^
/lib
/modules
/ | \
153 grep -v ^
/var
/domtool
/ | \
154 grep -v ^
/var
/lib
/mysql
/ | \
155 grep -v ^
/var
/lib
/postgres
/ | \
156 grep -v ^
/var
/lib
/postgresql
/ | \
157 xargs -I{} -d\\n
-- bash
-c "test -L '{}' || echo '{}'" > complain
159 F
=hcoop.backup.
tar$COMPRESS_EXT.aescrypt
160 tar clpf
- --ignore-failed-read --no-recursion -C / -T backupfiles | \
162 ccrypt
-k $KEYFILE -e > $F
165 # Acquire lock before messing with spamd
167 LOCK
=/var
/local
/lib
/spamd
/.lock
168 while test -f $LOCK; do
170 COUNT
=$
(expr $COUNT + 1)
171 if test $COUNT -eq 10; then
172 # Enough waiting. Kill the process.
174 test -n "$P" && kill $P ||
:
181 F
=common.spamd.
tar$COMPRESS_EXT.aescrypt
182 tar clpf
- --ignore-failed-read -C / /var
/local
/lib
/spamd | \
184 ccrypt
-k $KEYFILE -e > $F.new
188 test -s $BACKUPDIR/$F.new
&& \
189 mv $BACKUPDIR/$F.new
$BACKUPDIR/$F
191 vos listvol deleuze | \
195 grep -v "\.backup .*$" | \
196 grep -v "\.readonly .*$" | \
203 grep -v not-backed-up | \
204 xargs -I{} -d\\n
-- \
206 "F={}.dump$COMPRESS_EXT.aescrypt ;
207 vos dump -id {} -localauth -clone |
208 $COMPRESS_PROG | ccrypt -k $KEYFILE -e > \$F ;
209 < \$F catsync -b $BWLIMIT $BACKUPDIR/$SUBDIR/\$F ;
212 echo backing up databases
213 F
=databases.
tar$COMPRESS_EXT.aescrypt
214 tar -C /var
/backups
/databases
/ -cf - . | \
216 ccrypt
-k $KEYFILE -e > $F
219 grep '[a-z/]' complain
&& \
220 mail -a 'From: The Backup Program <backups@deleuze.hcoop.net>' \
221 -s "automated message: annoying files found on deleuze (please do something about them)" admins@hcoop.net \