{"id":11,"date":"2009-11-10T15:34:10","date_gmt":"2009-11-10T15:34:10","guid":{"rendered":"https:\/\/pim.famnit.upr.si\/wp\/?p=11"},"modified":"2021-11-17T11:22:41","modified_gmt":"2021-11-17T11:22:41","slug":"backing-up-mac-os-x-to-a-windows-machine","status":"publish","type":"post","link":"https:\/\/pim.famnit.upr.si\/wp\/?p=11","title":{"rendered":"Backing up Mac OS X to a Windows machine"},"content":{"rendered":"<p>I know there&#8217;s plenty of backing up\/synchronizing software for Mac. I know Time Machine is awesome. But  <a href=\"http:\/\/www.pure-mac.com\/backup.html\">none of the software<\/a> I tried was able to do it my way :). Thus, as I have a Linux\/FreeBSD background, I wanted to do it my way and the command line solution seamed to be a good one.<\/p>\n<p>My office Windows machine has plenty of disk space and is rarely used. It was an ideal system (with not so ideal file system) to do backups on.<\/p>\n<p><!--more--><\/p>\n<p>Prerequisites:&nbsp;<\/p>\n<ul>\n<li>First I needed to share a folder on my Windows machine to my Mac laptop. Here&#8217;s a nice tutorial on how to do this: <a target=\"_blank\" href=\"http:\/\/lifehacker.com\/247148\/how-to-mount-a-windows-shared-folder-on-your-mac\" rel=\"noopener\">How to mount a Windows shared folder on your Mac<\/a>.<\/li>\n<li>Next I needed the good backup software. I am fairly familiar with <strong>rdiff-backup<\/strong>. It&#8217;s doing incremental backups, it&#8217;s easy to use and it does its job really well. To install rdiff-backup I used <strong>MacPorts<\/strong>. Follow <a href=\"http:\/\/guide.macports.org\/\" target=\"_blank\" rel=\"noopener\">this guide<\/a> to install MacPorts. It&#8217;s easy as installing every mac software.<\/li>\n<li>I also wanted a notification window to pop up each time it tried to do a backup and informing me if it succeeded or not. I used <strong><a target=\"_blank\" href=\"http:\/\/growl.info\/documentation\/growlnotify.php\" rel=\"noopener\">growlnotify<\/a><\/strong>. Needless to say you have to install <strong>Growl<\/strong> as well.<\/li>\n<\/ul>\n<p><strong>1. step: install rdiff-backup <\/strong><\/p>\n<p>First I needed to install rdiff-backup:<\/p>\n<pre>$ sudo port install rdiff-backup<\/pre>\n<p><strong>2. step: install growlnotify<br \/>\n<\/strong><\/p>\n<p>Next I had to install growlnotify (moving into a folder of a mounted Growl-x.x.dmg image)<\/p>\n<pre>$ cd \/Volumes\/Growl-1.2\/Extras\/growlnotify\/\n$ .\/install.sh\n<\/pre>\n<p><strong>3<\/strong><strong>. step: check local IP address <\/strong><\/p>\n<p>Then I had to check my IP to see if I am connected to my office network (wired network interface en0). This could be probably done in a simpler way but I came up with this idea in seconds (all of this could be done with awk or sed :=)) and is funny to see so many pipes.<\/p>\n<pre>$ ifconfig | sed -n '\/en0\/,\/media\/p' | grep -v inet6 | grep inet | awk '{print $2}'  \n<\/pre>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I had few seconds and here&#8217;s a simpler version:<\/p>\n<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ ifconfig | awk '\/en0\/,\/ether\/ {if($1 == \"inet\") {print $2}}'\n<\/pre>\n<p><strong>4. step: ping the Windows PC <\/strong><\/p>\n<p>Then I needed to check if my Windows machine was on and listening (only one ping should be enough):<\/p>\n<pre>$ ping -c 1 148.88.226.250<\/pre>\n<p><strong>5. step: mount a shared samba folder <\/strong><\/p>\n<p>Then I checked if I could mount my Windows shared folder (samba). To<br \/>\ndo this I wanted to use Mac OS X keychain for for password so it would not be written in my bash script. My shared folder is <strong>smb:\/\/mkljun@MKLJUNDESKTOP\/mkljunHome<\/strong> where <strong>mkljun<\/strong> is my username, <strong>MKLJUNDESKTOP<\/strong> my Windows machine name (IP address should do the same) and <strong>mkljunHome<\/strong> my shared folder.<\/p>\n<pre>$ osascript -e \"try\" -e \"mount volume \"smb:\/\/mkljun@MKLJUNDESKTOP\/mkljunHome\"\" -e \"end try\"<\/pre>\n<p>This command would on other systems look something like like:<em><br \/>\n$ mount -t smbfs \/\/mkljundesktop\/mkljunHome \/Volumes\/mkljunHome -o username=mkljun, password=XXX<\/em>.<\/p>\n<p><strong>6. step: rdiff-backup<\/strong><\/p>\n<p>Then I checked if rdiff-backup is working properly (backing up my home folder on Mac OS X to a folder on the Windows machine).<\/p>\n<pre>$ rdiff-backup \/Users\/mkljun \/Volumes\/mkljunHome\/BackupMac<\/pre>\n<p><strong>7. step: growlnotify <\/strong><\/p>\n<p>A check if growlnotify is working.<\/p>\n<pre>$ growlnotify -t \"backup\" -m \"Your IP is XXX but backup computer YYY could not be reached\"\n<\/pre>\n<p><strong>8. step : The Script <\/strong><\/p>\n<p>And I was ready to write a bash script<\/p>\n<pre>#!\/bin\/bash\n# my backup script in \/Users\/mkljun\/backup.sh\n\nDestinationIP=\"148.88.226.250\"\nSourceIP=`ifconfig | sed -n '\/en0\/,\/media\/p' | grep -v inet6 | grep inet | awk '{print $2}'`\n\n# ping destination (backup) ip address; output redirected to \/dev\/null\nping -c 1 $DestinationIP &gt; \/dev\/null\n# check if ping successful\nif [ $? != 0 ]\nthen\n&nbsp;&nbsp;&nbsp; # if ping not successful, print notification (echo should be in one line!!)\n&nbsp;&nbsp;&nbsp; echo -e \"-t 'Backup failed' -m 'Your IP is $SourceIP. Backup PC $DestinationIP \n                could not be reached'\" | xargs \/usr\/local\/bin\/growlnotify\nelse\n&nbsp;&nbsp;&nbsp; # mount samba drive (osascript should be in one line)\n&nbsp;&nbsp;&nbsp; osascript -e \"try\" -e \"mount volume \"smb:\/\/mkljun@MKLJUNDESKTOP\/mkljunHome\"\" \n                 -e \"end try\" &gt; \/dev\/null\n&nbsp;&nbsp;&nbsp; # check if mount was successful\n&nbsp;&nbsp;&nbsp; if [ $? == 0 ]; then\n      # this echo should be in one line with a pipe\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo \"-t 'Backup' -m 'Your IP is $SourceIP. Starting backing up now'\" \n                    | xargs \/usr\/local\/bin\/growlnotify\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rdiff-backup \/Users\/mkljun \/Volumes\/mkljunHome\/BackupMac &gt; \/dev\/null\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # check if rdiff-backup successful\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ $? == 0 ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo \"-t 'Backup' -m 'Backup completed successfully'\" | xargs \/usr\/local\/bin\/growlnotify\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo \"-t 'Backup failed' -m 'Something was wrong'\" | xargs \/usr\/local\/bin\/growlnotify\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # delete all backups older than 2 weeks\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rdiff-backup --remove-older-than 2W \/Volumes\/mkljunHome\/BackupMac &gt; \/dev\/null\n&nbsp;&nbsp;&nbsp; fi\nfi\n\n<\/pre>\n<p>It is probably not the nicest script out there but its working. I could and probably should redirect standard outputs to a log file (with a day as a title) to to check it once in a while to see if the script is working (and even check if the file grew too big and delete it if necessary). But so far it works flawlessly for few days.<\/p>\n<p><strong>9. step: cron <\/strong><\/p>\n<p>The last thing to do was setting up a cron job so the script would run without my intervention. Let&#8217;s say I want to run it every week day at 10AM when I&#8217;m probably in the office (there are two stars between 10 and 1-5 which are not showing up for some reason &#8216;0 10 * * 1-5&#8217;).<\/p>\n<pre>$ crontab -e<\/pre>\n<pre>0 10 * * 1-5 \/Users\/mkljun\/backup.sh<\/pre>\n<p><strong>10. the last version of a script<\/strong><\/p>\n<p>UPDATE:<br \/>\n<a href=\"https:\/\/osebje.famnit.upr.si\/~mkljun\/blog-slike\/\/GeneralFiles\/backup.sh\">Here is the last version with logging to a file and all variables at the beginning of the script<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I know there&#8217;s plenty of backing up\/synchronizing software for Mac. I know Time Machine is awesome. But none of the software I tried was able to do it my way :). Thus, as I have a Linux\/FreeBSD background, I wanted to do it my way and the command line solution seamed to be a good&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":560,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,9],"tags":[15,28],"class_list":["post-11","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4-software-hints","category-8-software-interfaces","tag-meeting","tag-pim-framework"],"_links":{"self":[{"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11"}],"version-history":[{"count":3,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":562,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/posts\/11\/revisions\/562"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/media\/560"}],"wp:attachment":[{"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}