View difference between Paste ID: ApZs19GR and b1MkZVVP
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
3
# expects that password-less SSH key based authentication has already
4
# been configured on the client and server sides of the operation
5
# otherwise expect to enter user's SSH password/passphrase several times
6
# for commands passed to the server
7
# Date examples imply that "today's" backup is being done 2011-10-29
8
9
# config
10
## host name of ssh/rsync server
11
SYNCSERVER=torrents
12
## what to sync
13
SYNCWHAT=/home/`whoami`  #'my' home directory
14
## where to sync it, as the server filestructure would recognize it
15
BASEDIR=/mnt/torrent-pool/home-backups/`whoami`@`hostname`
16
## can be changed to taste if backups need to happen more often than daily, or whatever
17
NOW=`date +%F`
18
# end of config
19
20
WORKDIR=$BASEDIR/$NOW
21
NOWDIR=$BASEDIR/now
22
YESTERDIR=$BASEDIR/last
23
# assumes that /backup-path/last was left pointing to /backup-path/2011-10-28
24
25
#setup
26
ssh $SYNCSERVER mkdir -p $WORKDIR
27
# ex. /backup-path/2011-10-29
28
# may work without pre-creation, but why tempt fate?
29
ssh $SYNCSERVER rm -fv $NOWDIR
30
# ex. /backup-path/now
31
ssh $SYNCSERVER ln -s $WORKDIR $NOWDIR
32
# ex. /backup-path/2011-10-29 -> /backup-path/now
33
34
# act
35-
rsync -aHP $SYNCWHAT $SYNCSERVER:$NOWDIR --link-dest=$YESTERDIR
35+
rsync -aHP $SYNCWHAT/ $SYNCSERVER:$NOWDIR/ --link-dest=$YESTERDIR/
36
37
# cleanup
38
ssh $SYNCSERVER rm -fv $YESTERDIR
39
# ex. /backup-path/last
40
ssh $SYNCSERVER ln -s $WORKDIR $YESTERDIR
41
# ex. /backup-path/2011-10-29 -> /backup-path/last
42
# so that tomorrow (2011-10-30), 'today sync' will be 'yesterday sync'