{"id":288,"date":"2019-12-29T12:50:35","date_gmt":"2019-12-29T20:50:35","guid":{"rendered":"https:\/\/nramkumar.org\/tech\/?p=288"},"modified":"2019-12-29T12:50:35","modified_gmt":"2019-12-29T20:50:35","slug":"wirelessly-syncing-photos-and-videos-from-your-iphone-to-your-ubuntu-home-server","status":"publish","type":"post","link":"https:\/\/nramkumar.org\/tech\/blog\/2019\/12\/29\/wirelessly-syncing-photos-and-videos-from-your-iphone-to-your-ubuntu-home-server\/","title":{"rendered":"Wirelessly syncing photos and videos from your iPhone to your Ubuntu home server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I have been trying unsuccessfully to setup automatic wireless sync of photos and videos from our iPhones to my home server running Ubuntu. After failures with <a href=\"https:\/\/support.plex.tv\/articles\/203167727-set-up-camera-upload-ios\/\">Plex camera roll upload<\/a> which does not seem to work consistently, I have finally found a good alternative. The method is inefficient but has been reliable for the last two months.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It involves setting up camera backup from your iPhone to <a href=\"https:\/\/onedrive.live.com\/\">OneDrive <\/a>through the OneDrive app and then syncing down the camera roll from OneDrive to your home server using <a href=\"https:\/\/rclone.org\/\">rclone<\/a>. You can use other cloud services like Amazon, Google or Dropbox as well based on your preference &#8211; I prefer OneDrive as the value of <a href=\"https:\/\/products.office.com\/en-us\/compare-all-microsoft-office-products?activetab=tab%3aprimaryr1\">Office 365 Home + 1 TB storage for 6 users<\/a> works great for me. You don&#8217;t have to pay for the subscription of course, in which case you just have to manage the free storage aggressively.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the setup &#8211; download the OneDrive app for your phone and go to <code>Settings > Camera Upload<\/code> and turn it on so it uploads to the account of your choice. You can keep the app open and check the camera upload progress to ensure your photos and videos get uploaded faster for the first sync.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then on your home server, download and setup <code><a href=\"https:\/\/rclone.org\/\">rclone<\/a><\/code> which is an excellent equivalent of <a href=\"https:\/\/rsync.samba.org\/\">rsync <\/a>for cloud providers. Setting up <code>rclone <\/code>to sync to OneDrive is very straightforward using <code>rclone config <\/code>and following the <a href=\"https:\/\/rclone.org\/onedrive\/\">directions<\/a>. You can verify that you&#8217;ve set it up correctly by running <code>rclone lsd onedrive:<\/code> where <code>onedrive<\/code> is the name you gave to the remote you configured in <code>rclone<\/code>. If your configuration was successful, you should see a listing of OneDrive folders and files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After that, you can use the <code>rclone copy<\/code>command to copy your OneDrive upload folder (in my case it is called <code>Skydrive camera roll<\/code> &#8211; but it might be just <code>Camera roll<\/code> for newer accounts). You should use the <code>--dry-run<\/code> option to check that this will do what you want. For example, this is the command I used to check what the <code>rclone copy<\/code> would do &#8211; <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>rclone copy \"onedrive:SkyDrive camera roll\" \/storage\/Pictures\/MyiPhone\/OneDrive\/ --dry-run <\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After verifying that everything works as expected, the final step is to setup a daily <code>cron <\/code>job to do this everyday automatically. Here is the base script I use for doing the sync from OneDrive (called <code>rclone_sync.sh<\/code>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nfunction mailuser () {\n    mailto=$1\n    mailsubject=$2\n    mailbody=`\/usr\/bin\/awk -f \/home\/me\/rclone_parse.awk \"$3\"`\n    \/bin\/cat &lt;&lt;EOF | \/usr\/sbin\/ssmtp $mailto\nTo: $mailto\nSubject: $mailsubject\n\n$mailbody\n\nEOF\n\n}\n\n\nSRC_DIR=\"$1\"\nDST_DIR=\"$2\"\nLOG_FILE=\"\/tmp\/$1_rclone.txt\"\n\nrclone copy \"$1\" \"$2\" --progress --log-level INFO --log-file \"$LOG_FILE\"\n\nrc=$?\n\nif &#91; $rc -ne 0 ]; then\n    mailuser \"me@mydomain.org\" \"Sync of $SRC_DIR failed with $rc\" \"$LOG_FILE\"\nelse\n    mailuser \"me@mydomain.org\" \"Sync of $SRC_DIR succeeded\" \"$LOG_FILE\"\nfi<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And here is the simple AWK script to parse the output logs from rsync for creating the daily email summary:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/awk\n\nBEGIN { copied_new = replaced_existing = 0 }\n\n\/Copied \\(new\\)\/ {\n    copied_new++\n}\n\n\/Copied \\(replaced existing\\)\/ {\n    replaced_existing++\n}\n\nEND {\n    total_operations = copied_new + replaced_existing\n    print \"New Files      : \" copied_new\n    print \"Modified Files : \" replaced_existing\n    print \"Total Files    : \" total_operations\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To use these, simply create one shell script per user\/camera folder you want to sync daily that calls <code>rclone_sync.sh<\/code> with the correct source (remote folder) and destination (local folder) and then schedule them using cron.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This setup has worked very well for me &#8211; it addresses several problems like managing storage on our iPhones (we can just delete older videos when we&#8217;re running low on storage space without worrying about whether we saved it elsewhere or not), full resolution photo and video backups to the home server automatically, availability of the photos and videos we take on our phones in Plex and our home network for easy access on a variety of devices.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been trying unsuccessfully to setup automatic wireless sync of photos and videos from our iPhones to my home server running Ubuntu. After failures with Plex camera roll upload which does not seem to work consistently, I have finally found a good alternative. The method is inefficient but has been reliable for the last&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,1],"tags":[88,91,90,89],"class_list":["post-288","post","type-post","status-publish","format-standard","hentry","category-ubuntu","category-uncategorized","tag-iphone","tag-onedrive","tag-photos","tag-sync"],"_links":{"self":[{"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/posts\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/comments?post=288"}],"version-history":[{"count":4,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/posts\/288\/revisions"}],"predecessor-version":[{"id":295,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/posts\/288\/revisions\/295"}],"wp:attachment":[{"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/media?parent=288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/categories?post=288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/tags?post=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}