Find the answer to your Linux question:
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.
  1. #1
    Just Joined!
    Join Date
    Mar 2011
    Posts
    34

    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. .

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,317
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •