Automator file/folder (incremental) copy?

Discussion in 'Mac Programming' started by jprint714, Nov 7, 2015.

  1. jprint714 macrumors member

    Joined:
    Feb 21, 2009
    #1
    Hi,

    I'm trying put together a kind of incremental backup that works as follow: whenever I add an file to a particular folder/subfolders (located on my external HD), I'd like to automatically copy that newly save file from my folder/subfolders (located on my external HD) to my backup HD (located on another external HD), that would mirror the same folder/subfolder structure.

    In other words, when I move an new file to my primary storage folders/subfolders, I'd like to copy that new file to be automatically backed up on my back up HD (which will have the same, corresponding folders/subfolders and files).

    At first I thought I should do this via Retrospect, but I've also been told that I should do this via Automator, but I'm a novice w/ this app. Is this an appropriate app for this function? If so, what are the suggested steps to do this?

    Thank you...
     
  2. hobowankenobi macrumors regular

    Joined:
    Aug 27, 2015
    Location:
    on the land line mr. smith.
    #2
    Hey -

    Not much help with scripting, but I was wondering why you would not use one of the myriad of sync/backup tools for this?

    There are literally dozens of sync/backup tools that do what you describe, including free ones. Unless you want the challenge of scripting it yourself, I would suggest a sync/backup tool.
     
  3. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #3
    Yep, there are plenty of third part apps that can do it. Or you could use a simple Automator folder action (see attached screenshot).

    Something like a rsync might be more efficient, but probably a bit much for you if you're not reasonably confident on the command line.
     

    Attached Files:

  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    I mentioned rsync, so for the sake of completeness...

    If you wanted to be a massive show-off then you could use a Launch Agent and rsync. Folders and files are copied on a schedule (of your choosing) and thanks to rsync, only differences are copied (you can tweak options as appropriate) so although the first file sync might take a while, subsequent ones should be quicker.

    Make a text file (I use TextWrangler) with the following contents:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
       "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
       <key>Label</key>
       <string>com.myCompany.folderSync</string>
       <key>ProgramArguments</key>
       <array>
          <string>/usr/bin/rsync</string>
          <string>-avz</string>
          <string>/Users/Admin/Desktop/source2/</string>
          <string>/Users/Admin/Desktop/dest2</string>
       </array>
       <key>StartInterval</key>
       <integer>3600</integer>
       <key>KeepAlive</key>
        <true/>
    </dict>
    </plist>
    
    ...and save the file into /Library/LaunchDaemons. Give it a name ending in plist. Convention says that you use your company's name, followed by a name for your daemon like this:

    com.myCompany.folderSync.plist

    Also, change that in the plist to match. Next set your source and destination folders.

    Then choose an interval (in seconds) on which to sync the folders. In my example I've used 3600 seconds - so every hour.

    Then, to activate the daemon either restart your Mac or type the following in Terminal:

    launchctl load -w /Library/LaunchDaemons/eu.sgsintl.folderSync.plist

    I strongly recommend that you read up on Launch Daemons and rsync first though.

    Guide to Launch Daemons
    http://www.thesafemac.com/scheduling-recurring-tasks/
    https://developer.apple.com/library...stemStartup/Chapters/CreatingLaunchdJobs.html

    Guide to rsync
    https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/rsync.1.html
     

Share This Page