Sync folders across two remote servers or machines
Can someone help me creating a script that will sync the folders between 2 servers such that if we delete any file on either of the machine, the other should reflect the same.
I will be using a cronjob to run the script daily.
Code:
rsync -parv user@server1:source/ user@server2:destination/
The above command will only sync the source folder on server1 to destination folder on server2.
Now on any given day if I delete a huge file from destination folder (as I dont need it anymore) and if the cronjob gets executed, the huge file in source folder will again be copied over to destination.
I need to avoid this. In the above case, the script should delete the huge file from source folder.
I think unison would be helpful here but how to integrate it within a bash script.
Else, how can we do it with rsync itself?
Thanks in advance. .