Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-04-2012 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 30
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.
The above command will only sync the source folder on server1 to destination folder on server2.Code:rsync -parv user@server1:source/ user@server2:destination/
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. .
- 10-05-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,746
for rsync, try the --delete option. See this helpful article:
How to Backup Linux? 15 rsync Command Examples
Example 10 discusses what you're talking about, I think.


Reply With Quote
