{"id":718,"date":"2018-06-13T21:18:27","date_gmt":"2018-06-14T04:18:27","guid":{"rendered":"http:\/\/10.0.1.201\/?p=718"},"modified":"2018-06-13T21:18:27","modified_gmt":"2018-06-14T04:18:27","slug":"auto-backup-of-photos-library-photoslibrary-when-portable-drive-is-attached","status":"publish","type":"post","link":"https:\/\/strawhousepig.net\/wordpress\/2018\/06\/13\/auto-backup-of-photos-library-photoslibrary-when-portable-drive-is-attached\/","title":{"rendered":"Auto-backup of Photos Library.photoslibrary when portable drive is attached"},"content":{"rendered":"<p>This script relies on Folder Actions to fire it once it is attached to <strong>\/Volumes<\/strong> and the appropriately named hard drive is plugged in. I use it to update my off-site photo backup drive.<\/p>\n<p>Settings in the script are commented with instructions, which are hopefully clear enough. It does mention iPhoto, because it was written when iPhoto was a thing. A good thing, a great thing even. Now&#8230; *meh*<\/p>\n<p>The options for rsync are fairly standard (recursive, preserve times, extended attributes, and skip files already on the backup). The path to rsync is from OS X shipping with a version of rsync that was unbearably slow and me installing a newer version. I&#8217;m not sure when Apple ditched the older rsync version, but it sure wasn&#8217;t soon enough. I&#8217;m leaving it here for example purposes, but this script will fail if you don&#8217;t have an rsync binary there.<\/p>\n<p><code>-- The name of the physical disk.<br \/>\nproperty top_drive : \"Portable HDD\"<\/p>\n<p>-- The name of the disk image file.<br \/>\n-- If it is beyond root of top_drive, the (non-POSIX) path will need to be added. ie \"backups:iPhoto backup.dmg\"<br \/>\nproperty iPhoto_dmg : \"Photos backup.sparseimage\"<\/p>\n<p>-- The name of the disk image drive.<br \/>\nproperty iPhoto_drive : \"Photos backup\"<\/p>\n<p>-- POSIX path to iPhoto Library (Default is ~\/Pictures\/iPhoto Library).<br \/>\nproperty iPhoto_lib : quoted form of (POSIX path of ((path to pictures folder) as text) & \"Photos Library.photoslibrary\")<\/p>\n<p>-- rsync options<br \/>\nproperty rsync_options : \"-rtE --ignore-existing\"<\/p>\n<p>-- Path to rsync binary.<br \/>\nproperty rsync_path : \"\/usr\/local\/bin\/\" -- Leave blank (\"\") if not using a user installed version of rsync.<\/p>\n<p>on logErr(the_msg, the_num)<br \/>\n\tdo shell script \"logger '\" & \"iPhoto backup: \" & the_msg & \" (\" & the_num & \")'\"<br \/>\nend logErr<\/p>\n<p>on adding folder items to this_folder after receiving added_items<br \/>\n\tset new_item to item 1 of added_items as text<br \/>\n\tif new_item is (top_drive & \":\") then<br \/>\n\t\ttell application \"Finder\"<br \/>\n\t\t\ttry<br \/>\n\t\t\t\topen top_drive & \":\" & iPhoto_dmg as alias<br \/>\n\t\t\t\tdelay 10<br \/>\n\t\t\ton error errMsg number errNum<br \/>\n\t\t\t\tmy logErr(errMsg, errNum)<br \/>\n\t\t\tend try<br \/>\n\t\tend tell<br \/>\n\t\tset n to 0<br \/>\n\t\ttry<br \/>\n\t\t\tset rsync_options to rsync_options & \" \"<br \/>\n\t\t\trepeat until n = 10<br \/>\n\t\t\t\ttell application \"Finder\" to set all_drives to name of every disk<br \/>\n\t\t\t\tif iPhoto_drive is in all_drives then<br \/>\n\t\t\t\t\tset start_time to current date<br \/>\n\t\t\t\t\tset rsync_it to (do shell script rsync_path & \"rsync \" & rsync_options & iPhoto_lib & \" \" & quoted form of (\"\/Volumes\/\" & iPhoto_drive))<br \/>\n\t\t\t\t\tset total_time to (current date) - start_time<br \/>\n\t\t\t\t\tmy logErr(\"Done\", \"\" & total_time & \" sec\")<br \/>\n\t\t\t\t\texit repeat<br \/>\n\t\t\t\telse<br \/>\n\t\t\t\t\tdelay 6<br \/>\n\t\t\t\t\tset n to n + 1<br \/>\n\t\t\t\tend if<br \/>\n\t\t\tend repeat<br \/>\n\t\t\ttell application \"Finder\" to eject disk iPhoto_drive<br \/>\n\t\t\tdisplay dialog \"iPhoto backup complete.\" & return & return & \"You may now eject the disk \\\"\" & top_drive & \"\\\".\" with icon 2<br \/>\n\t\ton error errMsg number errNum<br \/>\n\t\t\tmy logErr(errMsg, errNum)<br \/>\n\t\t\tdisplay dialog \"Oops! An error occurred. :(\" & return & return & errNum & \" : \" & errMsg with icon 0<br \/>\n\t\tend try<br \/>\n\tend if<br \/>\nend adding folder items to<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This script relies on Folder Actions to fire it once it is attached to \/Volumes and the appropriately named hard drive is plugged in. I use it to update my off-site photo backup drive. Settings in the script are commented with instructions, which are hopefully clear enough. It does mention iPhoto, because it was written [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[10,20,23],"class_list":["post-718","post","type-post","status-publish","format-standard","hentry","category-code","tag-applescript-2","tag-iphoto","tag-macintosh"],"_links":{"self":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/comments?post=718"}],"version-history":[{"count":0,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/718\/revisions"}],"wp:attachment":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/media?parent=718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/categories?post=718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/tags?post=718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}