]> git.wh0rd.org - dump.git/blob - examples/remote_backup_ssh/backitup
Prepare for release 0.4b37
[dump.git] / examples / remote_backup_ssh / backitup
1 #!/bin/sh
2
3 #
4 # This script will backup local drives to a remote tape drive over ssh.
5 # written by David B. Peterson <dave@toppledwagon.com>
6 #
7 # Follow these steps before using it the first time:
8 # 1. Configure the env variables below, especially OPERATOR, TAPEHOST
9 # TAPEDEV, and FILESYSTEMS
10 # 2. run the following commands as root (on the machine to be backed up):
11 # ssh-keygen -t dsa
12 # cat ~/.ssh/id_dsa.pub | ssh OPERATOR@TAPEHOST 'cat - >> ~/.ssh/authorized_keys2'
13 #
14 # where OPERATOR and TAPEHOST are as you have defined below.
15
16 # We will run under screen so you can come back to the backup, if you need to.
17 if [ ! "$WINDOW" ]; then
18 exec screen $0
19 exit
20 fi
21
22 # ssh-agent allows us to backup securely without entering the passphrase so
23 # many times. This version uses openssh v2.9
24 if [ ! $SSH_AGENT_PID ]; then
25 echo Starting ssh-agent...
26 exec ssh-agent -- /bin/sh $0
27 exit
28 fi
29
30 OPERATOR=backup
31 TAPEHOST=tapehost.example.com
32 TAPEDEV=/dev/nst0
33 RMT=/sbin/rmt
34 RSH='/usr/bin/ssh'
35 DATE=`date +%Y%m%d`
36 DUMP='/sbin/dump 0auf'
37 LOGDIR=/var/log/backup
38 FILESYSTEMS='hda1 hda7 hda6 hda5 hda10'
39
40 #### config above ####
41 # backup FILESYSTEMS to the TAPEDEV on TAPEHOST with DUMP as OPERATOR using RSH
42
43 export RMT RSH
44 mkdir -p $LOGDIR &> /dev/null
45 ssh-add ~/.ssh/id_dsa
46
47 echo "Rewinding tape..."
48 REWIND="mt -f $TAPEDEV rewind"
49 $RSH $OPERATOR@$TAPEHOST $REWIND
50
51 for FS in $FILESYSTEMS
52 do
53 $DUMP $OPERATOR@$TAPEHOST:$TAPEDEV /dev/$FS 2>&1 | tee $LOGDIR/$FS.$DATE
54 done
55
56 echo "Rewinding and ejecting tape..."
57 OFFLINE="mt -f $TAPEDEV offline"
58 $RSH $OPERATOR@$TAPEHOST $OFFLINE
59