traviscline (owner)

Fork Of

Revisions

gist: 75158 Download_button fork
public
Public Clone URL: git://gist.github.com/75158.git
Embed All Files: show embed
Bash #
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
#!/bin/sh
num=21 # 3 weeks
 
for h in albert; do
date=`date +%Y%m%d-%H%M%S`
  dir=/home/backup/$h.d
  manifest=$dir/manifest
 
  # Find the most recent backup
  touch $manifest
  newest=`tail -n 1 $manifest`
  if [ -z "$newest" ]; then
linkarg=""
  else
linkarg="--link-dest=$dir/$newest"
  fi
 
  # Perform the backup
  rsync $linkarg -a --filter=". $dir/rsync.inc" --filter="- *" $h:/ $dir/$date
 
  # If we have too many backups, delete the oldest
  lines=`wc -l < $manifest`
  if [ $lines -gt $num ]; then
oldest=`sed 1q $manifest`
    rm -rf $dir/$oldest
    sed 1d $manifest > $manifest.new
    mv $manifest.new $manifest
  fi
 
echo $date >> $manifest
  rm /home/backup/$h && ln -s $h.d/$date /home/backup/$h
done