Rsync

Rsync usage

Posted By: pmietlicki

Published to Linux on Jun 24, 2015

Here is a rsync script to synchronize file between 2 servers (from /media/usb of the local server to the target 10.0.0.2 inside /media/Elements/ folder). Don't forget to exchange SSH keys before.

#!/bin/bash
if [ -e /root/rsyncjob.lock ]
then
  echo "Rsync job already running...exiting"
  exit
fi

touch /root/rsyncjob.lock

#your code in here
rsync -e ssh --rsync-path=/storage/.xbmc/addons/network.backup.rsync/bin/rsync -avz /media/usb/ root@10.0.0.2:/media/Elements/

#delete lock file at end of your job

rm /root/rsyncjob.lock

Note the rsync path that permits to indicate the path of rsync on the target.

Then you can use it inside your crontab :

MAILTO=pmietlicki@pascal-mietlicki.fr
0 * * * * /root/rsync.sh

Tags: Rsync

Archive