Reputation:
I have two machines, both running on linux with centos 7. I have installed the rsync packages on both of them and i am able to sync a directory from one machine to the other.
Right now i am doing the syncing manually, each time i want to sync i am running the next line:
rsync -r /home/stuff [email protected]/home
I was wondering if there is a way of configuring the rsync to do the syncing automatically, every some amount of time or preferably when there is a new file of sub directory in the home directory?
Thank you for your help. Any help would be appreciated.
Upvotes: 5
Views: 7931
Reputation: 11950
If you want to rsync every some amount of time you can use cronjobs
which can be configured to run a specific command each amount of time and if you want to run rsync when there is an update or modification you can use lsyncd
. check this article about use lsyncd
Update: As links might get outdated, I will add this brief example (You are free to modify it with what works best for you):
First create an ssh key on the source machine and then add the public key at the ~/.ssh/authorized_keys
file on the destination machine.
In the source machine update this file ~/.ssh/config
with the following content:
# ~/.ssh/config
...
Host my.remote.server
identityfile ~/.ssh/id_rsa
IdentitiesOnly yes
hostname 123.0.0.99
user root
port 22
...
And configure your lsyncd with the following then restart lsyncd's service
# lsyncd.conf
...
sync {
default.rsyncssh,
source="/home/stuff",
host="my.remote.server",
targetdir="/home/stuff",
excludeFrom="/etc/lsyncd/lsyncd.exclude",
rsync = {
archive = true,
}
}
...
Upvotes: 5
Reputation: 45
You can setup an hourly cron job to do this. rsync in itself is quite efficient in that it only transfers changes. You can find more info about cron here: cron
Upvotes: 0