The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using rsync to enable automatic backup MX mail server domains

Discussion in 'E-mail Discussions' started by aarondwyer, Aug 8, 2007.

  1. aarondwyer

    aarondwyer Well-Known Member

    Joined:
    Mar 26, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Brisbane
    cPanel Access Level:
    Root Administrator
    Hi

    This is for the techies out there. So flex your techie muscle on this...

    I have a redundant mail server setup and I've got a crontab setup to rsync copy my /etc/localdomains on the primary to /etc/secondarymx on the fallback mail server.

    Like this from the backup mailserver crontab

    0 1 * * * rsync -e ssh -avz root@primaryserver:/etc/localdomains /etc/secondarymx 2>&1 > /var/log/nightly_email_backup.log

    However I'm noticing that the rsync takes a direct copy of the file from the primary server, but I thought it would just append by default.

    I have domains that I've manually put into the /etc/secondarymx on the backup server that keep dissapearing after the crontab has run. So the rsync is removing them as well as adding in the new domains.

    I just want the rsync to append the new domains that end up in the /etc/localdomains on the primary at the end of each day, whatever is in /etc/secondarymx can stay there even if the domains are removed from the primary.

    Does anyone know how I can do this with rsync or scp or whatever.?

    Thanks
    Aaron
     
  2. jerrybell

    jerrybell Well-Known Member

    Joined:
    Nov 27, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    6
    Seems like it might be as easy as creating a script that looks like this:
    rsync -e ssh -avz root@primaryserver:/etc/localdomains /tmp/secondarymx
    cat /etc/secondarymx >>/tmp/secondarymx
    cat /tmp/secondarymx |sort |uniq >/tmp/secondarymx.new
    mv /tmp/secondarymx.new /etc/secondarymx
    rm /tmp/secondarymx



    Then, put that script in cron and it should do what you want. Mine is probably not the only way to go, and there may be ways to optimize, but that's what I can pull out of my head at the moment.
     
  3. aarondwyer

    aarondwyer Well-Known Member

    Joined:
    Mar 26, 2005
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Brisbane
    cPanel Access Level:
    Root Administrator
    Thank you I will try that out tonight, the logic looks very sound, and I'm sure that would work so I'll report back my results.

    Just a thought, doesn't rsync have an append function, would that work I wonder? I'll have to test that as well.

    Thanks
    Aaron
     
  4. jerrybell

    jerrybell Well-Known Member

    Joined:
    Nov 27, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    6
    rsync does have an append fucntion, but it doesn't do what you think. Here is the man page excerpt:
    --append
    This causes rsync to update a file by appending data onto the
    end of the file, which presumes that the data that already
    exists on the receiving side is identical with the start of the
    file on the sending side. If that is not true, the file will
    fail the checksum test, and the resend will do a normal
    --inplace update to correct the mismatched data. Only files on
    the receiving side that are shorter than the corresponding file
    on the sending side (as well as new files) are sent. Implies
    --inplace, but does not conflict with --sparse (though the
    --sparse option will be auto-disabled if a resend of the
    already-existing data is required).

    So, essentially, it is just another, more bandwidth efficient method to transfer the whole file.

    Note: my rough script above would not remove a domain that was deleted from secondarymx on primaryhost. Otherwise, I think it'll work too.
     
    #4 jerrybell, Aug 9, 2007
    Last edited: Aug 9, 2007
Loading...

Share This Page