Menu Close

RSync and bash

Hey guys, once again welcome back! Since I’m trying to be a good server admin I was playing with making a little mirror/backup service of my files. Since I love programming I didn’t want to just copy paste a static line to crontab and let him execute it once a day so I wrote a little bash script for using rsync.

Rsync is a great to to sync folders and has been around for years now but I didn’t have any experience with it so I started with trying to build up the command and later on making it variable. I wanted to do this with the help of ssh and schedule it with cron. How to add your bash script to cron is explaned HERE

I’ve set up the following line to do this over SSH.

rsync -az –safe-links ~/ -e ssh


  • -a means archive mode
  • -z means compress the data during data transfer
  • –safe-links means ignore symlinks that point outside the tree that you transfer
  • ~/ is the local path that will be copied, in my case ~ also known as my homedir
  • -e means execute command,
  • ssh
  • junke@ is the username with what will be loged on at the other server
  • is the destiantion
  • : after the : you set your remote location, this will be automaticly set to your homedir on the other server

To automate this you’ll need to upload your public key to the server so cron doesn’t have to put in your password. This can be done by doing the following

ssh-keygen  # followed by a lot of enters





To make this availible for other people I made the following of it:



$RSYNC -az –safe-links $LPATH -e “$SSH” $RUSER@$RHOST:$RPATH

The only thing you need to change to use it yourself is the RHOST, the remote host and make sure the other server has the ssh server running.

0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments