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 [email protected]:
- -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,
- [email protected] is the username with what will be loged on at the other server
- vendetta.junke.nl 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
ssh-copy-id [email protected]
To make this availible for other people I made the following of it:
$RSYNC -az –safe-links $LPATH -e “$SSH” [email protected]$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.
60 total views, 1 views today