Ask Different is a question and answer site for power users of Apple hardware and software. 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

I have a Windows server that I want to backup all the Shares through a script automatically to my MacBook Pro running OSX 10.6.8. There is no common folder all the shares are in, they are just mounted as \\SERVER\Share_Name. I want to be able to have a script that cycles through all the shares on a server (even if the folder names are unknown at the time the script is created), and create a backup on a local folder on my Mac. Or, if there's an easier way than a script, or drag-and-drop (that doesn't seem to always copy all the files)

share|improve this question
up vote 1 down vote accepted

There's no root in Samba protocol. To list shares on your server you can use smbutil(1):

$ smbutil view //Administrator@ | awk '$2=="Disk"{print $1}'

and then use output with mount_smbfs(8):

smbutil view //Administrator@ | awk '$2=="Disk"{print $1}' | while read sharename; do 
  mkdir ${BASE}/${sharename}; 
  mount_smbfs //Administrator@${sharename} ${BASE}/${sharename};

Please, read man pages to check other options I haven't used here.

The best utility to make backup I know is rsync(1). You can found it from MacPorts. It'll be interest if you know better.

share|improve this answer
+1 for the Samba Protocol thing. I did some more reading on it last night, and I saw that part. I like the idea of using a script, but need to still learn more about RSYNC. I will try your script, then mark as the answer if it works. I assume just above the done line is where I put my cp command? – Canadian Luke Nov 16 '11 at 18:49
I know that there's some problems with UTF-8 support. I use Mac OS X Lion 10.7.2 and have problems with mount non-english shares when use mount_smbfs or Finder. I think it's general Mac OS X problem. And don't forget to make sudo(1) before running this script – Eir Nym Nov 16 '11 at 19:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.