-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup
executable file
·44 lines (32 loc) · 1.02 KB
/
backup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
HOST=`hostname`
SERVER=amahi
TARGET=attic/backup/$HOST
ssh-add ~/.ssh/id_dsa
ssh $SERVER "mkdir $TARGET"
date
echo `date` | ssh $SERVER "cat - > $TARGET/backup_date"
echo "Writing package list.."
dpkg --get-selections | ssh $SERVER "cat - > $TARGET/package_list"
if [ $HOST == "hiro" ]; then
echo "Writing mysql DB.."
sudo service mysql start
FILE=$(mktemp mysql.`date +%F`.XXXXXXXXXX)
mysqldump --defaults-extra-file=~/.mysql.pw -u root \
--all-databases > $FILE
lzma $FILE
scp $FILE.lzma $SERVER:$TARGET/.
rm $FILE.lzma
sudo service mysql stop
fi
# We only save /etc/ here because it's one-way, and can be compressed
# and always shoved each time, because it's small. All userspace
# things are done w/ unison, because they're:
# 1. Bidirectional
# 2. Large (so we only want to move what changed)
echo "Writing etc.."
sudo tar -jcf - /etc | ssh $SERVER "cat - > $TARGET/etc.tar.bz2"
# FIXME - need to dump postgres stuff too
ssh $SERVER "df -h"
echo "Done!"
ssh-add -d ~/.ssh/id_dsa