Find the answer to your Linux question:
Results 1 to 8 of 8
Hi all! I am new to Linux and don't know how rsync works. First off, here is what I am supposed to do. I save the jpeg file(from email attachment) ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2006
    Posts
    12

    how to rsync web folders on different servers


    Hi all!
    I am new to Linux and don't know how rsync works.
    First off, here is what I am supposed to do. I save the jpeg file(from email attachment) in Server A:/htdocs/test/img.. Whenever there is new file saved in Server A, it will also have to be in Server B:/webapps/testb/img.

    How do I do this using rsync? Please give me sample scripts. Also, should I install rsync or it is also installed during Linux installation?

    Thanks.

  2. #2
    Linux User DThor's Avatar
    Join Date
    Jan 2006
    Location
    Ca..na...daaa....
    Posts
    319
    Well, this can be simple or get complicated. To approach it methodically:

    You can ascertain whether rsync is installed simply by entering "rsync" on a shell command line. If it's there, you'll get a nice verbose help, if not, you'll get a terse "command not found". If it's not installed, you'll need to use whatever software management tool that comes with your Linux distro to install it. It's almost without a doubt either installed or somewhere on the Linux install disks.

    To sync up those locations, you would typically enter:

    rsync -av servera:/htdocs/test/img serverb:/htdocs/test/img

    (note: - don't use spaces in paths on Linux. You can get around it in some cases, but it will cause you grief. Use an underscore instead if you must).

    "img" can be either a file or a directory - typically you'll want to sync up directories containing files since you may or may not know the name of any given file, and that avoids having to type it out.

    Now, if you want that command run every time you save a file, you can make a simple bash script and run it manually. Alternatively, you can use cron to run it. It allows you to run commands and scripts automatically at defined intervals.

    DT

  3. #3
    Just Joined!
    Join Date
    Jan 2006
    Posts
    12

    Talking

    Hi! Thank you for your reply.
    Now I have this script that works(through reading via the internet for hours! ):

    Code:
    #=======================================
    #!/bin/sh
    
    echo "=================START======================" >>$SOURCE_HOST/logs/rsync.log
    
    date >> /usr/local/tomcat/webapps/logs/rsync.log
    
    rsync -av --delete --include "*.jpg" --exclude "*" $SOURCE_HOST/img/ /home/img >>$SOURCE_HOST/logs/rsync.log
    
    echo "==================END=======================" >>$SOURCE_HOST/logs/rsync.log
    
    #=======================================
    I have a follow-up question, is there a command in Linux to know if a certain folder has been updated/changed?

    Cheers!

  4. #4
    Linux User DThor's Avatar
    Join Date
    Jan 2006
    Location
    Ca..na...daaa....
    Posts
    319
    Glad you got it working. Off the top of my head, I don't know specifically of a command that returns "yup, this has been touched" except for parsing the date of the files or setting/noting the backup bit. However, when you think about it, whatever this utility would do, you'd need to run it at certain times(whether it's once an day, once an hour, or every 10 seconds). It wouldn't be able to omnipresently just "know" that someone's altered a file, it's got to traverse the tree. Therefore, it turns into some sort of utility that would be run, say by cron, and actually rsync would be the perfect one - since it traverses the entire tree, and only updates things that were altered. Getting into setting and clearing backup bits I suspect would be more crunching that you need.

    DT

  5. #5
    Just Joined!
    Join Date
    Jan 2006
    Posts
    12

    Thumbs up

    I see.. Then I guess, I'll make a workaround on the java side..

    And another question arises.. I edited my crontab file, I changed the time to every 1 hour instead of every 15 minutes. But the changed I made is not working.. Should I restart/run something when I change the crontab file?
    It is still running every 15 minutes..

    below is what I've written in the crontab
    Code:
    0,1,30,45 * * * * root sh /usr/local/tomcat/webapps/shellscript/rsync.sh

  6. #6
    Linux User DThor's Avatar
    Join Date
    Jan 2006
    Location
    Ca..na...daaa....
    Posts
    319
    Did you manually edit the crontab? It's best to alter your crontab with:

    crontab -e

    When saved, this ensures the cron daemon gets told there was a change and re-reads it. Currently active crontab can be displayed with:

    crontab -l

    Try that and see if it's displaying what you think.

    Anyway, you can always(as root) go to /etc/init.d and enter:

    ./cron restart

    to give it a kick.

    DT

  7. #7
    Just Joined!
    Join Date
    Jan 2006
    Posts
    12
    Yeah, I manually edited my crontab. But I did not restart it.

    I don't know how to do it by crontab -e.
    Can you give me the steps on how to do this? I know it's just simple, but I really don't know..

    Thanks.

  8. #8
    Linux User DThor's Avatar
    Join Date
    Jan 2006
    Location
    Ca..na...daaa....
    Posts
    319
    Heh - you just enter....crontab -e

    It brings up your text editor, you add/alter/delete lines, and when you save and quit it tags cron to let it know you've changed things.

    Also, as root, you can go to /etc/init.d and enter

    ./cron restart

    although having to become root is what the '-e' param is helping you avoid. Use that, it's safer. It also ensures you're editing the right file.

    DT

Posting Permissions

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