Results 1 to 5 of 5

Thread: Require shell script using rsync

  1. #1
    Member
    Join Date
    Mar 2006
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Require shell script using rsync

    Dear All.

    I require a shell script using rsync. I have two Linux servers both are identical. I want to copy data from one server to another server in every 1 hour using rsync and I want to put in Cron Script.

    I tried this but when I do rsync it asks for password even I give --password-file option but no luck.

    Example :- rsync -avz server1:/mail server2:/mail
    I wan to put this in cron scheduler , so it copy all data every day in a gap of one hour and this script should start every day after 6: PM and stop at 2 AM .

    Regards.
    Puppen

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,513
    Thanks
    17
    Thanked 807 Times in 511 Posts
    Rep Power
    10

    Default

    Replace your rsync command (assuming that you want to sync server1 with local server2)

    Code:
    rsync -avz server1:/mail server2:/mail
    with (type command on server2)
    Code:
    rsync -avrR --links --rsh=/usr/bin/ssh server1:/mail :/mail
    To avoid password prompt you need to setup ssh-keys, so on server2 type following commands:
    Code:
    ssh-keygen -t rsa
    ssh you@server1 "mkdir .ssh"
    scp .ssh/id_rsa.pub you@server1:.ssh/authorized_keys2
    Now you can login to server1 from server2 without password. Now setup cron job using following script (save script on server2):
    Code:
    #!/bin/bash
    MASTER="server1"
    DIR="/mail"
    LDIR="/mail"
    SSH="/usr/bin/ssh"
    rsync -avrR --links --rsh=$SSH $MASTER:$DIR $LDIR
    Cron job
    Setup cronjob using following syntax:
    Code:
    1 18,19,20,21,22,23,0,1,2 * * * /path/to/script.sh
    Script.sh will run at 6:01pm, 7:01pm, 8:01pm ... 2:01am

    Read following docs for more info:

    How do I add jobs to cron under Linux or UNIX oses
    SSH Public key based authentication - How-to?
    How do I sync data between two Load balanced Linux/UNIX servers?

    if you have more question just reply back and we will be glad to assist you
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Member
    Join Date
    Mar 2006
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Dear

    Thanks a bunch for reply.
    But I am confused between 2 servers and which command runs on which server.
    Currently what I am doing is,
    I am running this command on server2 where I am taking back up i.e on server2
    rsync -avz server1:/mail /mail
    the above command copy files from server1 to server2

    One more thing I have so many dir in mail folder but I do not want to take backup of all dir except certain dir. in this case what should I do/

    Regards.
    Puppen
    someone somewhere is made for you.
    LOVE is Journey not a destination.
    ALL I want is EVERYTHING.

  4. #4
    Is that all you got? rockdalinux's Avatar
    Join Date
    May 2005
    Location
    Planet Vegeta
    Posts
    987
    Thanks
    27
    Thanked 71 Times in 62 Posts
    Rep Power
    20

    Default

    One more thing I have so many dir in mail folder but I do not want to take backup of all dir except certain dir. in this case what should I do/
    Use --exclude option

    Code:
    rsync -avz --exclude '/mail/rocky' server1:/mail /mail
    Above command will not include /mail/rocky directory. If you have lots of dir then you can store them in file. For example:

    file.txt
    Code:
    /mail/rocky
    /mail/xyz
    /mail/dddd
    And your command should be as follows:
    Code:
    rsync -avz --exclude-from file.txt server1:/mail /mail
    Hope this helps
    Rocky Jr.
    What's wrong? I hope I am not making you uncomfortable...

    Never send a boy to do a mans job.

  5. #5
    Member
    Join Date
    Mar 2006
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Dear All
    Thanks a bunch, Ya I have got it. This script works properly.

    regards.
    Puppen
    someone somewhere is made for you.
    LOVE is Journey not a destination.
    ALL I want is EVERYTHING.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. rsync pls help
    By linuxmanjusha in forum Web servers
    Replies: 1
    Last Post: 23rd October 2007, 11:12 AM
  2. writing a shell script to find out my shell name
    By jaymob123 in forum Shell scripting
    Replies: 1
    Last Post: 8th October 2007, 12:36 AM
  3. rsync folder
    By zafar466 in forum Shell scripting
    Replies: 1
    Last Post: 28th April 2007, 03:28 AM
  4. Replies: 3
    Last Post: 25th October 2006, 08:07 PM
  5. require shell script
    By puppen in forum Shell scripting
    Replies: 4
    Last Post: 12th April 2006, 09:42 PM

Posting Permissions

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