Sync files and directories using Rsync, Zenity, SSH and cron

My systems as performed: Ubuntu 10.04 Localhost, Debian 6.03 Remotehost

1) Configure your systems for an SSH public/private keypair (see ref: 1 below)

2) configure local user's bash environment: (see ref: 5)

edit ~/.bashrc and add this line:

xhost local:your_localuser > /dev/null

3) create rsync script:

#!/bin/bash

# test if the ssh connection can be made
ssh -q -i /directory_to_ssh_keys/your-rsync-key your_remotehost_user@your_remotehost_ip exit
if [ $? = 0 ]      
then
((rsync -av --progress --omit-dir-times -e "ssh -i /directory_to_ssh_keys/your-rsync-key" "/your_local_directory/photos/" "your_remotehost_user@your_remotehost_ip:/your_remotehost_directory/familyphotos" | zenity --auto-kill --progress --pulsate --text="Wait while I sync the photo folder.. Don't move any photos or use Picassa ....") &

#Start a loop testing if zenity is running, and if not kill rsync (see ref: 2)
(RUNNING=0
while [ $RUNNING -eq 0 ]
do
if [ -z "$(pidof zenity)" ]
	then
	pkill -9 rsync
	RUNNING=1
fi
done
))
else
zenity --warning --text "Backup server not available";echo $?
fi

4) Create your crontab entry

using crontab -e, my example is an hourly sync:

# m h  dom mon dow   command
0 * * * * export DISPLAY=:0.0 && /directory_of _your_script/your_backup_script.sh

References:

1. Secure your SSH server with Public/Private key authentification | Debian/Ubuntu Tips & Tricks

2. Bug #220656 in zenity (Ubuntu): “zenity --progress cancel button doesn't return a value”

3. Wget and zenity --progress - Page 2 - Ubuntu Forums

4. A complete zenity dialog examples 2 » Linux by Examples

5. Linux etc. » Blog Archive » Running X apps (like zenity) from crontab (solving “cannot open display” problem)

6. HowTo make cron run GUI applications [Archive] - Ubuntu Forums

7. [all variants] Two-way synchronizing , rsync? - Ubuntu Forums

8. Do more backups - David Picard

 

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <br>
  • Lines and paragraphs break automatically.
  • You may link to Gallery2 items on this site using a special syntax.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.
James Horvath Gooey Website