When copying files remotely (It also acts as my Off-site Backup Mirror), I use rsync and ssh to accomplish the task...
1. Add ssh keys to automate login without password prompt (there are lots of tutorial out there... google)
2. In my bash script, rsync command is:
Pull syntax:
rsync -avz -e "$SSH" --delete $USER@$HOST:/SRC/ /DEST/
Push syntax:
rsync -avz -e "$SSH" --delete /SRC/ $USER@$HOST:/DEST/
3. Make a script
# vi sync.sh
my script goes like this (you can copy & paste):
Code:
#!/bin/sh
#
RSYNC=$(which rsync)
SSH=$(which ssh)
RUSER=root
HOST=192.168.0.10
SRC=/shares/PUBLIC/
DEST=/shares/BACKUP/
PID=/var/run/sync.pid
start() {
if [ ! -e "$PID" ];then
touch $PID
echo "Synchronizing files"
$RSYNC -avz -e "$SSH" --delete $RUSER@$HOST:$SRC $DEST
rm -f $PID
fi
}
stop() {
if [ -e "$PID" ];then
killall rsync
echo "Stopping filesynching"
rm -f $PID
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
4. Dont forget to make your script executable and test it.
# chmod +x sync.sh
# ./sync.sh start
5. If you want to create cron, su as root and:
# crontab -e
and insert the ff:
# m h dom mon dow command
30 17 * * 1-5 /root/scripts/sync.sh start
30 7 * * 1-5 /root/scripts/sync.sh stop
Thats it! Hope that helps...