21 settembre, 2008

Incremental backup with rsync

Hi everybody, today we talk abount rsync command and how use it to create a 7 days incremental backup to folder in a linux based system. I tested this script on FC6 but rsync is available on other linux distibutions.


   1:  #!/bin/sh

   2:  

   3:  ###### Setting Script ##########

   4:  logfile=/var/log/rsync_scotty.log

   5:   

   6:  ###### Setting Date ###########

   7:  backup_date=`date +%d/%m/%Y`

   8:  backup_hour=`date +%H:%M`

   9:  week_day=`date +%w`

  10:  data=`date +%Y%m%d`

  11:   

  12:  echo "" >> $logfile

  13:  echo "" >> $logfile

  14:  echo "" >> $logfile

  15:  echo "$backup_date::$backup_hour::Start rsync server" >> $logfile

  16:   

  17:  # list of directory to backup

  18:  LIST="/home/pippo/ /home/pluto/"

  19:   

  20:  DAY=`date +%a`

  21:  BACKUP_PATH=/backup

  22:  CURRENT=current

  23:  for d in $LIST; do

  24:          OPTS="--force --ignore-errors --progress --delete --backup --backup-dir=$BACKUP_PATH$d$DAY -a"

  25:          [ -d $HOME/emptydir ] || mkdir $HOME/emptydir

  26:          echo "rsync --delete -r $HOME/emptydir/ $BACKUP_PATH$d$DAY"

  27:          rsync --delete -r $HOME/emptydir/ $BACKUP_PATH$d$DAY/ >> $logfile

  28:          rmdir $HOME/emptydir

  29:   

  30:          echo "rsync $OPTS $d $BACKUP_PATH$d$CURRENT"

  31:          rsync $OPTS $d $BACKUP_PATH$d$CURRENT >> $logfile

  32:  done

  33:   

  34:  echo "$backup_date::$backup_hour::Finish rsync server" >> $logfile



You can find other information on http://rsync.samba.org/examples.html .

By, Ciro

Nessun commento:

Posta un commento