SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question rsync shell script to continuously sync local directory to remote server

    I need to set up a shell script on Mac OS X Mountain Lion to sync a local directory to a remote directory (web server) using either an SSH connection (tunnel) or SFTP and have it run continuously every 30 seconds.

    I also need to exclude certain files or folders from being synced.

    The syncing would be unidirectional (mac -> webserver).

    The basic parameters I need to have implemented are as follows:

    Code:
    Local path: /Volumes/path/to/local/directory
    Remote server: example.com
    username: someUser
    password: somePassword
    Remote path: /path/from/server/root/to/htdocs
    Files to exclude: '.ht*', '*.sublime-*'
    Folders to exclude: 'cache','administrator/cache'
    I would also need help writing the crontask and adding it to my system to execute automatically.

    Any help would be greatly appreciated.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Every 30 seconds....why?! o.O
    Also...do you have a question or just making a statement?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    Quote Originally Posted by logic_earth View Post
    Every 30 seconds....why?! o.O
    Also...do you have a question or just making a statement?
    Yes...my question was how do I set that up. I got the answer...but now I am facing a different issue.

    The command I am issuing is:

    Code:
    rsync -avz -e ssh --exclude '*.ht*' --exclude '*.jpa*' --exclude '*.sublime-*' --exclude 'cache/' --exclude 'administrator/cache' username@example.com:/home/public_html/domains/clients/sosdivorce /Volumes/Clients/htdocs/sites/domains/clients/sosd2
    It isn't doing exactly what I need.

    What is happening is that the entire remote directory 'sosdivorce' is being synced into the local directory 'sosd2' as a subdirectory of the local.

    What I need to have happen is that the contents of the remote directory 'sosdivorce' sync with the contents of the local directory 'sosd2'.

    How do I modify the command above to do that?

  4. #4
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    357
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Add a trailing slash to the source path
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon

  5. #5
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,627
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Also, you can use the --daemon switch to make rsync run as a daemon which is more suitable than running it every 30 seconds. Especially since cron can't handle every 30 seconds.


Tags for this Thread

Bookmarks

Posting Permissions

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