{"id":103,"date":"2011-07-07T17:30:07","date_gmt":"2011-07-07T17:30:07","guid":{"rendered":"http:\/\/www.davidhedges.info\/?p=103"},"modified":"2018-06-03T17:31:24","modified_gmt":"2018-06-03T17:31:24","slug":"backup-script-for-mac","status":"publish","type":"post","link":"https:\/\/www.davidhedges.info\/index.php\/2011\/07\/07\/backup-script-for-mac\/","title":{"rendered":"Backup Script for Mac"},"content":{"rendered":"<p>I really don&#8217;t like working with Mac&#8217;s, though the fact that they are based off of unix now does make it easier to work with. A little while back I had to write a script to backup a Mac to a usb drive. I had first looked for some free or low cost software that would backup the Mac and a NAS, but didn&#8217;t have a lot of luck. Instead I ended up writing a shell script to do it. It&#8217;s a little rough, but works, another note the logging to email isn&#8217;t the best, but does work if you enable postfix on the Mac.<\/p>\n<p>here is the script:<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;start of script&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>#!\/bin\/sh<br \/>\n#written by David Hedges<\/p>\n<p>DATE=`date +%Y%m%d` #get the date<br \/>\nDOW=`date +%a` #get day of the week<br \/>\nTIMEDIR=\/Volumes\/LaCie\/time<\/p>\n<p>mkdir \/Volumes\/scans<br \/>\nmkdir \/Volumes\/shareddata<br \/>\nmkdir \/Volumes\/usersdata<br \/>\nmkdir \/Volumes\/it<br \/>\nmkdir \/Volumes\/LaCie<\/p>\n<p>mount -t hfs \/dev\/disk1s1 \/Volumes\/LaCie<br \/>\nmount -t smbfs \/\/administrator:&lt;password&gt;@192.168.42.10\/it \/Volumes\/it<br \/>\nmount -t smbfs \/\/administrator:&lt;password&gt;@192.168.42.10\/usersdata \/Volumes\/usersdata<br \/>\nmount -t smbfs \/\/administrator:&lt;password&gt;@192.168.42.10\/shareddata \/Volumes\/shareddata<br \/>\nmount -t smbfs \/\/administrator:&lt;password&gt;@192.168.42.10\/scans \/Volumes\/scans<\/p>\n<p>rsync -avz \/Volumes\/it \/Volumes\/LaCie\/current\/it &gt;\/Volumes\/LaCie\/logs\/$DOW.log<br \/>\nrsync -avz \/Volumes\/usersdata \/Volumes\/LaCie\/current\/usersdata &gt;&gt;\/Volumes\/LaCie\/logs\/$DOW.log<br \/>\nrsync -avz \/Volumes\/shareddata \/Volumes\/LaCie\/current\/shareddata &gt;&gt;\/Volumes\/LaCie\/logs\/$DOW.log<br \/>\nrsync -avz \/Volumes\/scans \/Volumes\/LaCie\/current\/scans &gt;&gt;\/Volumes\/LaCie\/logs\/$DOW.log<br \/>\nrsync -avz &#8211;exlcude Volumes \/ \/Volumes\/LaCie\/current\/local &gt;&gt;\/Volumes\/LaCie\/logs\/$DOW.log<\/p>\n<p># Weekly full backup<br \/>\nif [ $DOW = &#8220;Fri&#8221; ]; then<br \/>\nNEWER=&#8221;&#8221;<br \/>\nNOW=`date +%d-%b`<br \/>\necho $NOW &gt; $TIMEDIR\/full-date<br \/>\ntar $NEWER -zcvf \/Volumes\/LaCie\/$DOW.tgz \/Volumes\/LaCie\/current &gt;&gt;\/Volumes\/LaCie\/logs\/$DOW.log<br \/>\nelse<br \/>\nNEWER=&#8221;&#8211;newer `cat $TIMEDIR\/full-date`&#8221;<br \/>\ntar $NEWER -zcvf \/Volumes\/LaCie\/$DOW.tgz \/Volumes\/LaCie\/current &gt;&gt;\/Volumes\/LaCie\/logs\/$DOW.log<br \/>\nfi<\/p>\n<p>grep -i fail \/Volumes\/LaCie\/logs\/$DOW.log &gt;\/Volumes\/LaCie\/logs\/$DOW.error.log<br \/>\ngrep -i error \/Volumes\/LaCie\/logs\/$DOW.log &gt;&gt;\/Volumes\/LaCie\/logs\/$DOW.error.log<br \/>\nmail -s backup-results &lt;email address&gt; &lt;\/Volumes\/LaCie\/logs\/$DOW.error.log<br \/>\nmail -s backup-results &lt;email address&gt; &lt;\/Volumes\/LaCie\/logs\/$DOW.log<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;end script&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I really don&#8217;t like working with Mac&#8217;s, though the fact that they are based off of unix now does make it easier to work with. A little while back I had to write a script to backup a Mac to a usb drive. I had first looked for some free or low cost software that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","category-it-blog","entry"],"_links":{"self":[{"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":1,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions\/104"}],"wp:attachment":[{"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.davidhedges.info\/index.php\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}