rSync Server

rSync Pull From Server

This Script pulls files from an other server via TCP/IP.

  #!/bin/bash
  #
  # (c) 2011 Philipp Schellworth
  # www.schellworth.de
  #
 
  SERVER=source.url_or_ip.org
  RSYNC=/usr/bin/rsync
  SSH=/usr/bin/ssh 
  KEY=/root/.ssh/id_rsa
  RUSER=root
  RSERVER=target.url_or_ip.org
  RPATH=/target/data/.
  DATA_PATH=/source/data/*
 
  EXCLUDES=
  #EXTRAOPT="--bwlimit=256"
  EXTRAOPT=""
 
  echo "Starting rsync backup from $SERVER..."
  logger "Starting rsync backup from $SERVER..."
 
 
  $RSYNC -rlDv -e "/usr/bin/ssh -i $KEY -p 2222" --delete --rsync-path="rsync --log-file=/var/log/rsync.log" --stats -P $DATA_PATH $RUSER@$RSERVER:$RPATH                   
 
 
  # 0 = fehlerfrei,
  # 24 ist harmlos; tritt auf, wenn waehrend der Laufzeit
  # von Rsync noch (/tmp?)-Dateien verändert oder geloescht wurden.
  # Alles andere ist fatal -- siehe man (1) rsync
  if ! [ $? = 24 -o $? = 0 ] ; then
           echo "Fatal: rsync finished $SERVER with errors!"
           logger "Fatal: rsync finished $SERVER with errors!"
  fi
 
  # Fertig!
  echo "Finished rsync backup from $SERVER..."
  logger "Finished rsync backup from $SERVER..."

A working ssh connection via keyfile (no password ) is needed. The -p 2222 is for an other port, ssh is listening on.

rSync to a Volume

Mount a volume and backup some directories. This script calls an other script, to do a DB backup before it copy the files.

  #!/bin/sh
  #
  # (c) 2008 Philipp Schellworth
  # www.schellworth.de
  #  
 
  server="servername"
  bakdir="/target/backup/dir"
  bakvolume=""
  DATE="Start Task: "`eval date +%H%m%S%d%m%Y`"
  DATEEND="End Task: "`eval date +%H%m%S%d%m%Y`"
 
  if [ ! -d $bakdir ]; then
    mkdir $bakdir 
    echo "Backup directory created."
  fi
 
  echo -n "Mounting Backup-Disk to $bakdir"
  /bin/mount -t cifs -o username=admin,password=secret //target_ip/bak01a $bakdir
 
  if [ $? -eq 0 ]; then
  if [ ! -d $bakdir/$server ]; then
    mkdir $bakdir/$server
    if [ ! $? -eq 0 ]; then
      echo "FAILED!"
      echo "Could not create $server backup directory! Giving up!"
      exit -1;
    fi
  fi
 
  echo "Backup directory for $server created."
 
  echo -n "Creating SQL-Database backup..."
  cd /usr/scripts/; ./db_dump.sh 
 
  if [ $? -eq 0 ]; then
    echo "DB backup done."
 
    cd /
    for dir in `echo "/srv/www/htdocs/ /some/other/directory/"`; do
      echo "Working on: "$dir
        echo $DATE >> /var/log/rsync.log
	/usr/bin/rsync -rlptDuc --delete $dir $bakdir/$server >> /var/log/rsync.log
	echo $DATEEND >> /var/log/rsync.log
	#rsync -avuc --delete $dir $bakdir/$server
    done
  else
    echo " FAILED!"
    echo "Could not create SQL-Database backup! Giving up!"
  fi
  else
    echo " FAILED!"
    echo "Could not mount my Backup disk. Giving up!"
  fi
 
  /bin/umount /mnt/backup

Very Simple Backup

  logger "starting fileserver rsync backup"
  rsync -avz -e ssh --rsync-path="rsync --log-file=/var/log/rsync.log" 192.168.0.2
 
  if ! [ $? = 24 -o $? = 0 ] ; then
         echo "Fatal: rsync finished $SERVER with errors!"
         logger "Fatal: rsync finished $SERVER with errors!"
  fi
  logger "finished fileserver rsync backup" 
Enter your comment. Wiki syntax is allowed:
   _  __   ____   ___    ___    __  ___
  / |/ /  / __/  / _ \  / _ \  /  |/  /
 /    /  / _/   / ___/ / , _/ / /|_/ / 
/_/|_/  /_/    /_/    /_/|_| /_/  /_/