PDA

View Full Version : Help convert from Windows to Mac



mndad
28th June 2011, 06:56 AM
I just bought my daughter a MacBook Pro and am trying to set up some remote synchronization scripts. I'd like some suggestions/pointers as to how to convert the following Windows Batch job to Mac.

There is an attached drive P: that I need to verify is connected before proceeding.
I only want to try ~5 times. If internet is not connected....I just wait until the next day and try again.

Here is the batch file commands.
@Echo off
SET /a i=0
:Retry
echo %time% %i%
IF EXIST P: GOTO :Start
IF %i% LSS 5 (GOTO :Delay) ELSE (GOTO :End)
:Delay
PING 1.1.1.1 -n 1 -w 60000 >NUL
SET /a i+=1
GOTO :RETRY
:Start
Echo do sync here
:End
Echo this is now the end
echo %time%

I believe my steps need to be:
1. mounting the drive (Buffalo Cloudstor Pro)
2. if successful, sync (leverage rsync)
3 if not successful retry up to 5 minutes ( I need the delay, because it takes a minute
or 2 for the drive to be recognized)
4 if still no connection; quit and try again the next day.


I believe I need to set this up as a launchd script so that I can ensure that this sync gets performed. I would like the sync to happen at least once a day, but if it doesn't happen (the computer is off, closed, not connected to
internet, etc) I want to it to "catch up" with any missed jobs.

If this isn't the correct forum, please let me know other resources to try.
Thank you!

iGobbleoff
28th June 2011, 07:46 AM
i'm not up to speed with terminal, but i thought that would be the way, and then use automator to write an ical script for the timing?

glacierdave
28th June 2011, 08:07 AM
I'm reminded of a quote:

"If all you have is a hammer, every problem looks like a nail."

Obviously I have no context for what you're trying to achieve but it strikes me as being fairy complex where, often, a sync between two computers need not be complex.

In terms of your batch file, if you've ever used bash (common linux shell environment) then you can use the same thing on OS X. You could also look at creating an Automator action.

But, honestly, I'd probably start at a point before that - i.e. "what do I want to achieve?" and see if there's a more elegant way of achieving it.

David

mndad
29th June 2011, 05:06 AM
I am trying to set up a remote sync process to a Buffalo Cloudstor Pro. My daughter is away at school, the NAS server is at home. I had the sync process working fine from her Windows machine. Now that she has a Mac, I need to rework the process so she is still getting her data backed up.

When there is internet access, the drive appears just like a local drive. The basic part of the scripting should be fairly straight-forward. Where it gets more complicated is as follows:

1) Due to start up and connection speeds, etc, the sync may try to start before the drive is fully accesible. That is where I want to force a delay/retry. I don't want the sync to start until the drive is available.
2) If there is no internet connection (within 5 min) then I just want to end and just skip the sync
3) log the results

glacierdave
29th June 2011, 07:17 AM
Would you get a more effective result by using some kind of cloud storage service (e.g. DropBox although there's other options (http://techpp.com/2010/07/05/dropbox-alternatives-sync-files-online/)) which could then also sync back to your local storage solution?

David

Brains
29th June 2011, 01:32 PM
Crikey, Dad, you need to think outside the box! Batch scripts on a Mac, my left arse-cheek!

Synkron (http://synkron.sourceforge.net/) -- free, flexible, schedulable, network-friendly, cross-platform GUI-driven synchronisation tool.

Of course, you realise that this will become completely superfluous when Apple's iCloud service goes live next month :p

mndad
30th June 2011, 10:19 AM
Interesting responses, but obviously you are not addressing the problem. So stay in the box for a moment and see if you can offer a useful suggestion to my problem.

1) The REAL PROBLEM I am trying to solve is timing and drive availability. The sync part is easy. Some of the products I've used on Windows can be triggered by many events and also include the option of delayed start and/or catch up missed backups. I am looking for a way to delay the start of the sync to give the drive enough time to mount so that it is accessible. The 2nd scenario would be if there were no internet connection available. I want the sync process to "fail gracefully" or know to retry as soon as the drive becomes available.

2) Also, I am not interested, nor will I ever utilize 3rd Party cloud storage. I have the same features/functions with my Buffalo Cloudstor Pro AND i keep my private data private. Not to be too cynical, but go-ahead and post all of your identification numbers for me. What you say that information is private? Well then just let Apple and others have at your personal information. They'll keep it safe!

glacierdave
1st July 2011, 07:46 AM
Interesting responses, but obviously you are not addressing the problem. So stay in the box for a moment and see if you can offer a useful suggestion to my problem.

The responses are addressing the problem from a different angle.

I'd suggest that if something looks complex and requests for help elicit few response then perhaps you're on the wrong track and there's a better way to achieve your goal. Complex equals fragile. Fragile equals a pain to keep running properly. If it's a pain to keep running properly it inevitably won't get run properly. At that point, all the careful work falls in a heap. Good backups should be easy, painless and fully automated. It's the only way they'll keep happening in the long run.


1) The REAL PROBLEM I am trying to solve is timing and drive availability. The sync part is easy. Some of the products I've used on Windows can be triggered by many events and also include the option of delayed start and/or catch up missed backups. I am looking for a way to delay the start of the sync to give the drive enough time to mount so that it is accessible. The 2nd scenario would be if there were no internet connection available. I want the sync process to "fail gracefully" or know to retry as soon as the drive becomes available.

The emphasis from your comment here should be on "Some of the products". Brains offered you a product that'll do what you're after. Yet you seem to want to persist with converting a Windows/DOS batch file to OS X. Why not use a tool specifically designed to achieve the result you're after?


2) Also, I am not interested, nor will I ever utilize 3rd Party cloud storage. I have the same features/functions with my Buffalo Cloudstor Pro AND i keep my private data private. Not to be too cynical, but go-ahead and post all of your identification numbers for me. What you say that information is private? Well then just let Apple and others have at your personal information. They'll keep it safe!

The article I linked above included a range of cloud storage options. Some of them encrypt all your data BEFORE it goes into the cloud. That means you're the only one who can decrypt it. Don't trust that this is the case? Fine. Create an encrypted DMG (http://wiki.dropbox.com/TipsAndTricks/IncreasePrivacyAndSafety) and store that in the cloud. Use a cloud service that also encrypts and you're now double-encrypted.

If your NAS had "the same features/functions" as these other suggested solutions, you wouldn't be asking for a way to shoe-horn it into this particular usage case.

As I understand it, you have a desired result and a process for achieving that result. In your case...

Desired result = a sync'd backup of data from your daughter's Apple laptop.
Process = a batch file to trigger a data sync to a NAS on your LAN.

However, "desired result" can be achieved in a myriad of ways. "Process" is just one of them. That you've had few responses on helping "process" work might suggest it's not the most effective way to achieve "desired result".

David

mndad
1st July 2011, 01:22 PM
The product that Brains offered:
Does synchronizations - Yes
Can be scheduled - Yes
Can be triggered on multiple events - No
Recovers from missed scheduled runs - No

But lets forget about the sync process at the moment. And forget about me looking for a "process". I don't care how it gets done, but it needs to meet the following criteria. Let me try one more time to ask my question more generically.

How can a program on a Mac be set up to run:
(a) when and only when a specific network drive is successfully mounted and accessible?
(b) at regular time intervals only while condition (a) is valid?

forno
1st July 2011, 01:52 PM
. .

Brains
1st July 2011, 03:21 PM
Can be triggered on multiple events - No
Recovers from missed scheduled runs - No
...
How can a program on a Mac be set up to run:
(a) when and only when a specific network drive is successfully mounted and accessible?
(b) at regular time intervals only while condition (a) is valid?

Yes to both, if you make the laptop contextually aware by adding MarcoPolo (http://www.symonds.id.au/marcopolo/), a free, Australian-made system enhancement that can change configurations, network settings, and trigger program events depending on what the computer itself can 'sense'. It would be a trivial matter to have the Mac automatically attach a network share and trigger a Synkron update whenever it detected the home wifi network, or launch a VPN connection to the home network and sync that way whenever and wherever network access becomes available. Elegance in its pure simplicity, and a decidedly Mac way of achieving the goal.

It is even possible to trick Time Machine into doing the backups instead of Synkron, by using the "Secrets" prefpane (a panel for OSX's System Preferences) and creating a .dmg (Mac-specific virtul disk container) on your home NAS, MarcoPolo can mount the NAS and then open the .dmg, as soon as Time Machine sees it it goes "ooo, goody!" and chucks on the latest changes.

No programming required, you just have to clip the right GUI tools together.

(Does this work? My daughter's beein using MarcoPolo on her MacBook for the last eight months to automount her partner's WHS and trigger Time Machine to do a backup whenever she gets home.)

forno
1st July 2011, 03:27 PM
I notice a tweet in my feed today, talking about apple exploring location aware docks on macs

soulman
1st July 2011, 09:55 PM
How can a program on a Mac be set up to run:
(a) when and only when a specific network drive is successfully mounted and accessible?
(b) at regular time intervals only while condition (a) is valid?This is pretty straightforward to do in AppleScript, though I'm sure there would be other, better, ways using some sort of shell script in conjunction with cron. I just don't know much about those tools.

With AppleScript, one would create a stay open applet that checks for the existence of your network drive periodically and then launch your app if found.

outbak
5th July 2011, 03:20 PM
Have a read of this link for ideas. It uses Rsync and Automator.


Geek Stuff - Synchronize two folders on a Mac with Automator and Rsync - Branko Jevti?'s Piece Of Web (http://www.bananica.com/Geek-Stuff/Synchronize-two-folders-on-a-Mac-with-Automator-and-Rsync/)