How to use rsync over SSH with resume support

We all like backups don’t we? You know, in case your machine gets wrecked up you can restore your most precious data.

With this script you can sync your data using Bash, Rsync and Open SSH.

Let me first explain the doSync function.

Using rsync to transfer the data is quite simple but if the connection fails while transferring rsync will stop the sync, since we don’t want that this script has a while loop which repeats in case rsync does not clean exit.

Optionally I added a line that in case the backup fails over 5 times it will sent me an email so I know of the problem that occurred.

Ok, now lets explain how to call the function, this is quite simple just fill out the right arguments:

 

 

Another note to the doSync function, you might want to remove the v from the rsync line near ”-aWzv” and comment the following 3 echo lines to mute the output.

 

 

The last thing you might want to add is a line to your crontab config.

 

The backup.sh content

 

I hope you can use this for your backups, and in case you run into any problems. Please let me know 🙂