Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Okay. So I have a few executable .sh files that backup a directory. In this case, the Development directory. I have two computers. A Mac (Which is the main computer, and a Windows 7 desktop.) Since my Mac only has 500 GB of storage, I want to back up data to the other computer. I do this wirelessly.

To accomplish this, I have a shell script which checks whether I am connected to main-pc/Users/Public/. I know that the location isn't secure, and I will change the location in a few days, but for now, I just want it to work.

Overall the script works fine, it makes sure the location exists, if I am not connected I have it set up to mount the computer. It copies everything correctly as well.

EXCEPT, if the internet suddenly loses connections, or my connection to the other computer is interrupted (Which happens every now and then). When this happens, the location suddenly doesn't exist, and it keeps running the script, but does nothing and just does things like

x -> y Location does not exist... Blah blah blah.

My question is, how can I make sure that if I were to lose connection, it simply just pauses the backup and waits till the location connects? Is this even possible? I can't just recreate the location, as I am not storing this locally.

Thanks. (And I realize it would be easier to just get an external drive, but what is the fun in that?)

My script is pretty long, but here is the section that concerns the backup.

rm -r -v /Volumes/Users/Public/InfiniteBackups/Development
cd /Volumes/Users/Public/InfiniteBackups
mkdir Development
cp -v -f -rip ~/Development/ /Volumes/Users/Public/InfiniteBackups/Development
echo "Files have finished transferring"
say "Files have finished transferring"
exit 0

It is not the prettiest looking script, but it works. This is on OS X 10.8.

share|improve this question
up vote 1 down vote accepted

I would use rsync and check the exit value. Keep retrying until it exits successful.

Rsync will use hashes to make sure and send the least amount of data possible, and is really hardy across network connections.

share|improve this answer
So it's like it's own tool right? I was hoping for something I could use through my own script, but it might not be possible. Thanks for the answer. :) – Josiah Dec 20 '12 at 16:12
It is it's own tool, you use it instead of cp. It's pretty ubiquitous, and may already be installed on your OSX system (i'm not sure). It is very scriptable! i've used it in many bash scripts. – Woodrow Douglass Dec 20 '12 at 16:13
Alright, I'll take a look. +1. I won't except your answer until I see if anyone else has an idea, but if not, I'll accept yours. I'll give it a few hours. – Josiah Dec 20 '12 at 16:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .