about me | email me | search | archives | blogroll | reader map | the forum | the store | rss/feed | pda

Bettnet.com - Domenico Bettinelli Jr.
Text-Link Ads
< # St. Blog's Parish ? >

BLOGROLL (More blogs...)



CATEGORIES

  • Archdiocese of Boston
    • Catholic Charities
  • Bishops
  • Blogging
  • Books
  • Church Property
    • Art & Architecture
    • Parish & school closings
  • Cooking
  • Culture
  • Doctrine and Dissent
  • Economics
  • Environment
  • Faith and Liturgy
    • Prayer requests
  • Humor
  • Legal Issues
  • Life Issues
  • Marriage, Family & Parenthood
  • Media
  • News
  • Personal
    • Driving and commuting
    • Memoir
      • Growing up in Canton
      • Steubenville
    • Moving
  • Other religions and denominations
    • Islam
  • Politics
    • Catholics in the Political Sphere
    • Local Politics
    • Mass. Politics
    • National politics
  • Sexuality
  • Religious Freedom & Persecution
  • Technology
    • Internet
    • Macs, iPods, and the like
  • Sports
  • The Scandal
    • Talking about Touching
  • Vatican News
  • Travelogues
    • Massachusetts
      • Boston
      • North Shore
    • New England
    • Texas
  • National Defense
    • Iraq





Powered by ExpressionEngine

Copyright © 2001-2008
Domenico Bettinelli, Jr.
All Rights Reserved.

disclaimer : privacy policy
Catholics Against Joe Biden

RECENT PHOTOS

Members: Login | Register | Member List

Previous: Bertone promoted to camerlengo
Next: Red dye at night...

Back to main

Mac tip: One iPhoto library to rule them all…

(Update Aug 27, 07 5:28 pm): I have an update to this tip now that iLife '08 has been released. The change to the way iPhoto stores its library of photos causes some re-thinking, but doesn't completely break the tip.

Not the usual fare here, so I’ll drop the entire post behind the jump, but if you’re a Mac user whose family has several computers and you all want to share all your digital photos, you’ll want to check it out. Mainly I want to keep a record of what I’ve done in case I ever need to recreate it.

Technorati Tags: Mac | OS X | rsync | ssh | iPhoto | file sharing | howto |

Still here? Good.

Here’s the situation. I gave Melanie my old iBook so now we’re both on Macs. She’s realized that she has iPhoto and wanted access to the digital photos so she doesn’t have to wait for me to get with the program and upload them for her. iPhoto has a great feature that allows other users on the network to get at the photos on your Mac. The downside is that my Mac would have to be running iPhoto whenever she wants the photos, meaning she has to bug me again, defeating the purpose.

Now, the upside is that my old PowerMac is running as a file server, so I thought, why not keep a duplicate of my photos on the server, run iPhoto on the server, and then Melanie can access those all she wants. Sounds simple and it is, once I figured out everything I had to do.

First, I needed a simple way to synchronize the photos on my MacBook to the PowerMac. I wanted to keep my Mac as the primary repository for photos because that’s where I’d be downloading them from the camera and editing them and uploading them to Flickr. Thus, I decided to use the Unix terminal command ‘rsync’.

(Warning: If you’re not familiar with the Terminal program, take some time to familiarize yourself with some simple tutorials online. It’s a powerful program that if misused, can do damage to your data. You’ve been warned.)

My first stop was an excellent tutorial at Lifehacker.com which covered using rsync when backing up files between a Mac and a PC. Here we’re doing something a little different.

Open the application “Terminal” in your “/Applications/Utilities” folder. At the command prompt, type the following:

rsync -azv --delete --exclude '.DS_Store' /Users/domenicbettinelli/Pictures/iPhoto_Library_1/ :/Volumes/Neptune/Pictures/

terminal_rsync_thumb.jpg

That is the rsync followed by a series of switches and parameters. The exact syntax doesn’t matter, but here’s what some of it means. In the block of -azv, the first time you run the command, you change the “v” to “n”, which sends it as a dry-run, telling you what files would have been sent and/or replaced if it had been an actual sync. The --delete parameter tells the server to replace any changed files on its hard drive with the files from the primary Mac. The --exclude '.DS_Store' ignores those invisible little OSX files that are in every folder and don’t need to be copied.

The parameter /Users/domenicbettinelli/Pictures/iPhoto_Library_1/ is the path to the original iPhoto library on my primary Mac and :/Volumes/Neptune/Pictures/ is the path to the folder on the server.

(This bit—:—is found by opening “System Preferences” and selecting “Sharing” then clicking on the “Services” tab. Now select the check box next to “Remote login” and you will have enabled ssh, which I explain below.)

services_thumb.jpg

The first time you run the rsync command with the -n switch, you should look to make sure everything appears correctly. Make sure that you do not have any spaces in your source or destination addresses. This could cause rsync to delete lots of data. I actually had to go back and rename the “Neptune” volume and iPhoto_Library_1 after my dry run because of that very problem.

When you run this command, you will be asked for a password. This is the password for the “dombett” account (or your equivalent) on the server. Remember it.

Now, once you’re sure everything is good, run the rsync command again, but this time replace the “n” in “-avn” with “z”. At this point, the sync will begin and depending on how many photos you have, it could take some time. Be patient. The first time is the longest and after this, it should go very quickly unless you add tons of photos or makes lots of edits to your primary iPhoto library.

The next step is to automate the rsync to update, say, every night. For this we use a built-in Unix utility called cron. But to put a nice easy-to-use face on it, download a utility called Cronnix.

I won’t go into detail about how Cronnix works, but as you can see from the following screenshot, it offers a means by which we can have the Mac run a regularly scheduled action, whether it’s opening an Applescript or launching an application or, in this case, executing a Unix command.

cronnix1_thumb.jpg

Click on “New” and then on the “Simple” tab. Paste the rsync command you’ve been using into the “Command” box. Then put in the time you want the command to occur. If you want to happen every day, click the check boxes for “Day of month”, “month”, and “Day of week”. The checked box means “every”, as in “every day.” For hours and minutes, enter the time you want the command to be executed each day (using a 24-hour clock). In my case, I want the sync to occur each night at 11:30 pm.

cronnix2_thumb.jpg

Click on the “New” button, then click “Save” and quit. Now every evening at 11:30 pm, my iPhoto library will be synchronized with the server.

Passwordless ssh logins

There’s one problem though: Every time it runs, it will ask for the server password, meaning I’ll need to be there to enter it. Don’t worry; we have a solution in the form of passwordless ssh logins.

For the purposes of this tutorial, this is what ssh is. Entering that command in the terminal allows you to take control of another computer as if you were sitting in front it instead of your own, which is what we’re doing with the rsync command. Pretty powerful stuff, which is why they don’t make it easy for you to let just anyone come in and muck about in your system’s innards without being an authorized user. So what we’re going to do is tell the server that when it sees an ssh connection from this one computer, to accept it without demanding a password.

Here’s how to do it. In Terminal, type cd ~, Return, then cd .sshand Return. Next type ssh-keygen -t dsa and Return. Assuming you’ve had no error messages so far, at the next prompt type scp id_dsa.pub :~/.ssh/Palantir_dombett_id_dsa.pub, replacing with the ssh info for your server we got up above in the rsync section. As for Palantir_dombett_id_dsa.pub, you can replace Palantir_dombett with your primary Mac’s hard drive and your user account. This is the public encryption key file for ssh.

At the next prompt, type ssh 10.0.1.187: (use your server’s IP address) and Return. Your prompt should change slightly to reflect the fact that you’re now in control of your server. Type cd ~, Return, cd .ssh, Return, cat Palantir_dombett_id_dsa.pub >> authorized_keys (replacing it with the name of the actual public encryption key file you just generated.)

To quit the ssh connection to your server type ~. (tilde-period).

At all prompts for your password, enter your server password. If you’ve come this far without errors, you’re now set up for passwordless ssh logins. The next time the rsync command runs, it won’t ask for a password. (If you did run into a problem, I suggest consulting this Hackzine post, which provided a lot of help for me when I was doing this and these ssh public key authentication instructions. The latter page is not specifically for the Mac and I had to adapt it somewhat to work for me, but the essential data is there. If you still can’t figure it out, ask me in the comments and I’ll let you know if I encountered the same error and how I fixed it.)

Automating iPhoto on the server

Of course for all this to work properly, iPhoto must always be running on the server, but when a sync occurs iPhoto needs to be restarted to recognize that its library has changed. It would be a real pain to automate everything else, but have to remember to go to the server everyday and quit and relaunch iPhoto. Happily, this can be automated too.

Open a text editor on the server, whether TextEdit or TextWrangler or TextMate or BBedit or what have you. Type the following into a new window:

#!/bin/bash
osascript -e 'tell application '"iPhoto"' to quit'
osascript -e 'tell application '"Finder"' to delay 20'
osascript -e 'tell application '"iPhoto"' to activate'

What this little file does is run a batch of Unix command that call Applescript from within the Unix environment to quit iPhoto if it’s running, wait 20 seconds to give it time to quit, and then restart it. That’s it.

Save the file as “restart_iPhoto.sh” to your /User folder and then open Terminal. You need to turn this text file into an executable script so type chmod u+x ~/restart_iPhoto.sh and hit Return.

From the prompt, type restart_iPhoto.sh and Return. This should quit iPhoto (if it’s running), pause, then launch it again. Now to set up a schedule.

You could download Cronnix to this computer too, but here’s the Unix way of manipulating cron. In another text file, type the following:

#minute hour mday month wday sh
30 01 * * * sh /Volumes/Neptune/restart_iPhoto.sh

Substitute your own path/to/file.sh. Save the text file as “restartiPhotocron”. Now, back in Terminal, type crontab /Volumes/Neptune/restartiPhotocron and hit Return. Type crontab -l to make sure that it went in correctly and you’re all set. Now, ever day at 1:30 am, the server will quit and restart iPhoto. Because this will run two hours after the rsync, this gives plenty of time for all the copying to be finished first.

Final steps

The last step is to turn on Sharing in iPhoto on the server. First, you need to open a hole in the firewall for iPhoto to see through, so open up “System Preferences” on the server and then click on “Sharing”. This time, click on the “Firewall” tab. Check the box next to “iPhoto Bonjour Sharing.” Quit “System Preferences” and switch to iPhoto.

firewall_thumb.jpg

Click on “Sharing” and then select “Share my photos”. In my case, I chose to share all my photos (may as well since you copied them all over there), and then set my shared name to “Server’s photos”. You can require a password for access if you want.

iPhoto_sharing_thumb.jpg

Go back to your other Mac, open up iPhoto, and if you have “look for shared photos” set in your preferences, you should see “Server’s photos” in the source list.

iPhoto_source.jpg

You’re done!

Epilogue and final thoughts

With a little experimenting, I’m sure this method could be adapted for iTunes and other programs that keep a library of files and share them out.

I’m also sure that some of these steps are a bit of kludge and that an experience Unix and/or scripting guru could clean my method up a lot (after he shakes his head in disgust at this mess). On the other hand, I had fun figuring this out on my own and learning quite a bit in the process, which is half the reason I do it. (The other half is that great feeling of satisfaction knowing that you were able to go from “I wish I could…” to “I did it!” )

Any comments, questions, and most importantly corrections and advice would be greatly appreciated in the comments below.

Update (Apr 9, 07 11:20 pm): I think the rsync command I'm using needs to be adjusted a little in order to ensure that it's syncing everything in the folders of the iPhoto library. This should work: rsync -azv --delete --exclude '.DS_Store' /Users/domenicbettinelli/Pictures/iPhoto_Library_1 :/Volumes/Neptune/Pictures. You have to take the trailing slashes off the source and destination. The other problem I've encountered is if a user is still sharing the library, the program on the server won't quit. I need to find a way in Applescript to make it quit, which I'm sure is possible even if I have to resort to the brute method of a kill command.

Update (Apr 10, 07 5:14 pm): Jason advises in the comments that we should add the -E attribute to the rsync command in order to make all the proper Mac OS X metadata gets copied as well so that it would take this form: rsync -azvE --delete --exclude ‘.DS_Store’ "source" "dest"

Posted by Domenico Bettinelli on 04/4/07 at 08:53 PM  •   • 



-->

COMMENTS

oh. my. lord.

I thought you’d just be impressed if I told you I’d recently converted. I think you’d be impressed if I actually knew what the heck you are talking about! (Analogy: Convert who discovers he or she should take grad theology classes...)

United States Posted by JenB  on  04/5/07  at  07:57 AM



Jen, welcome to the family. grin I am impressed you converted.

Don’t be too impressed with me. I’m just applying what I’ve picked up here and there.

United States Posted by Domenico Bettinelli  on  04/5/07  at  05:33 PM



Great tip, but I have a few questions if I may. Are you setting up syncing from your wife’s machine back to the server so that changes she makes are captured? I guess I’m thinking of a solution where the server is the central repository, but my wife’s iMac and my MacBookPro could both sync to the server and we would both have each other’s changes. I’m probably asking for too much, but this is where the tip led me.

Thanks.

United States Posted by  on  04/9/07  at  09:14 PM



Stephan: I think that in order to do that, you’d need to check the photos in and out, comparing them to one another. And what happens if I edit a photo and she edits the same one? I think that would take much more sophisticated software than what you can cobble together from what’s built-in or downloadable as shareware.

Sorry.

United States Posted by Domenico Bettinelli  on  04/9/07  at  09:19 PM



Yeah, that’s what I was thinking too. Something like Portfolio Server from Extensis would be needed.

Thanks for the quick response and the original tip.

United States Posted by  on  04/9/07  at  09:37 PM



instead of renaming the folders so they do not have spaces, you could simply put quotes around any argument that has spaces in it.

United States Posted by  on  04/10/07  at  06:16 AM



You might want to add the ‘E’ option to your rsync command. This tells rsync to keep all of the Apple specific information that rsync usually ignores. my typical rsync command is:

rsync -azvE --delete --exclude ‘.DS_Store’ <source> <dest>

United States Posted by  on  04/10/07  at  12:17 PM



Or, for $20 you can buy a copy of iPhoto library manager.

United States Posted by  on  04/10/07  at  01:43 PM



This is great, but what about sharing iPhoto libraries amongst the users on your machine? I still can’t get my wife’s copy of iPhoto on her account to see my iPhoto library (even though I put it in the Shared directory). Any advice/help is appreciated.

United States Posted by James  on  04/10/07  at  02:10 PM



D’oh! I don’t even have to pay the $20 since I already own a copy. Just didn’t know it could do something like this. I will check it out.

At least this way I learned how to do rsync, ssh, passwordless ssh, and a cron job. Thanks for pointing it out.

United States Posted by Domenico Bettinelli  on  04/10/07  at  02:59 PM



Checking out iPhoto Library Manager, I’m not sure it allows synchronization, just duplication, which means I would have to copy the entire iPhoto library folder everytime, which is time consuming. I’d rather just copy what’s change, especially since I don’t make changes to the library ever day.

Am I missing something?

United States Posted by Domenico Bettinelli  on  04/10/07  at  03:04 PM



I did it a different way. I have a fileserver where I copied the whole iPhoto library to. Then on each of my mac’s I held the alt key and clicked the iPhoto icon - at that point it asked where the iPhoto library was and I directed it to the network share.

I did the same on my other mac and bobs your uncle - they both link to the same library.

This also works for the iTunes library if you didn’t know.

United Kingdom Posted by  on  04/11/07  at  08:05 AM



It’s not a bad solution, but what happens if you and another person are changing the library at the same time? Since iPhoto is not designed to be a multi-user product, I’m wondering if it could cause major problems to the iPhoto database.

United States Posted by Domenico Bettinelli  on  04/11/07  at  08:19 AM



Domencio, I don’t know - I’ve never tried. I use it in a slightly different scenario to you as I use it as a way so that both my mac mini and macbook are using the same sources so I can switch between them easily. There’s never been the occasion that both machines have been used at the same time yet as we tend to use the macbook.

I’ll agree that it could get a bit messy if both machines are making changes to the same file though. 

Cheers - Nick

United Kingdom Posted by  on  04/11/07  at  08:35 AM



As far as Stephan’s question goes, if you’ve both edited the file someones changes are going to get overwritten.  Though this is making me think of taking this all a step further and putting the iPhoto Library under subversion control since it’s built in to OS X anyway.  I may have to look at that.

United States Posted by rev_matt_y  on  06/2/07  at  09:02 PM



What happens if you and another person are changing the library at the same time?

Poland Posted by AboutAmerica  on  09/7/07  at  09:41 AM



You’re not using the networked library as your main iPhoto library. It only shows up as a shared library in your iPhoto so you can copy photos out of the shared library. So you’re not making any changes to it except copying it every night.

United States Posted by Domenico Bettinelli  on  09/7/07  at  09:46 AM



HI, so if I understand this right, my parents can take their Macbook on the road (without having to connect to the net or the library on the server), update it with photo’s they take on the road. Then when they get home, sync it and the iMac at home will be updated.

is that correct

Canada Posted by  on  12/13/07  at  06:34 PM



It should work that way, as long as you set things up according to the version of iPhoto and Mac OS X they have installed.

Actually, it would be easier for them because they’re only dealing with two computers, not three. In their case, before they leave, they should copy the iMac’s iPhoto library to the Macbook; take pictures and upload them to the Macbook’s iPhoto; and when they get home copy the Macbook’s iPhoto library to the iMac, overwriting the old copy there.

That’s lots easier than dealing with rsync and all the rest.

United States Posted by Domenico Bettinelli  on  12/13/07  at  09:03 PM



More comments: Page 1 of 1 pages
-->
Commenting is not available in this weblog entry.

Comments are being moderated. After you submit your comment it could take up to a couple hours, but usually only a few minutes, before it will appear. Thank you for your patience. If you have any questions, you may contact Domenico Bettinelli.