
{"id":302,"date":"2016-03-10T18:30:44","date_gmt":"2016-03-10T18:30:44","guid":{"rendered":"http:\/\/timallen.name\/?p=302"},"modified":"2016-03-10T18:37:28","modified_gmt":"2016-03-10T18:37:28","slug":"remote-backup","status":"publish","type":"post","link":"https:\/\/timallen.name\/index.php\/2016\/03\/10\/remote-backup\/","title":{"rendered":"remote backup"},"content":{"rendered":"<p>This runs a remote backup via ssh to a mounted file system (ext4 or btrfs). It does de-duplication at the file level; that is, the first backup copies everything, subsequent backups only copy the changed files and hard link to the unchanged files. RAID storage systems like NetApp de-duplicate at the block level but the snapshot paradigm is very similar.<\/p>\n<pre class=\"lang:default decode:true \" >#!\/bin\/bash\r\n\r\nhostname=\"kmac\"\r\nnow=`date \"+%Y-%m-%dT%H:%M:%S\"`\r\n\r\necho -e \"\\n\\nBackup of $hostname on `date`\"\r\n\r\n#check args, set backupdir\r\nif [ $# -lt 1 ]; then\r\n        echo \"$0: missing path operand\"\r\n        echo \"Usage: $0 DEST\"\r\n        exit 1;\r\nfi\r\nbackupdir=$1\r\n\r\n#make sure the destination dir is there\r\nif [ ! -d $backupdir\/$hostname ]; then\r\n        mkdir $backupdir\/$hostname\r\nfi\r\n\r\n#run the backup\r\nrsync -aHA --stats --delete \\\r\n--rsh 'ssh -c arcfour128' \\\r\n--exclude \/boot \\\r\n--exclude \/proc \\\r\n--exclude \/sys \\\r\n--exclude \/srv\/ProgrammersFiles \\\r\n--exclude \/media \\\r\n--exclude \/dev \\\r\n--exclude \/tmp \\\r\n--exclude \/run \\\r\n--exclude \/mnt \\\r\n--exclude \/opt \\\r\n--exclude \/exports \\\r\n--exclude \/var\/lock \\\r\n--exclude \/var\/run \\\r\n--exclude='ExcludeFromBackup' \\\r\n--link-dest=..\/current \\\r\n$hostname:\/ \\\r\n$backupdir\/$hostname\/back-$now\r\n\r\n#update the \"current\" soft link\r\nrm $backupdir\/$hostname\/current\r\nln -s back-$now $backupdir\/$hostname\/current\r\n\r\n#prune backups\r\n#After ten days we only keep weekly\r\nfor daysago in `seq 11 90`;\r\ndo\r\n        date=`date --date=\"$daysago days ago\" \"+%Y-%m-%d\"`\r\n        dow=`date --date=\"$date\" \"+%a\"`\r\n        eom=`date --date=\"$[daysago-1] days ago\" \"+%-d\"` #1 if it's the end of the month\r\n        if [ \"$dow\" == \"Fri\" ]; then\r\n                continue; fi\r\n        if [ \"$eom\" == \"1\" ]; then\r\n                continue; fi\r\n\r\n        rm -rf $backupdir\/$hostname\/back-$date*\r\ndone\r\n\r\n#After 90 days we only keep monthly\r\nfor daysago in `seq 91 365`;\r\ndo\r\n        date=`date --date=\"$daysago days ago\" \"+%Y-%m-%d\"`\r\n        eom=`date --date=\"$[daysago-1] days ago\" \"+%-d\"` #1 if it's the end of the month\r\n        if [ \"$eom\" == \"1\" ]; then\r\n                continue; fi\r\n\r\n        rm -rf $backupdir\/$hostname\/back-$date*\r\ndone\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This runs a remote backup via ssh to a mounted file system (ext4 or btrfs). It does de-duplication at the file level; that is, the first backup copies everything, subsequent backups only copy the changed files and hard link to the unchanged files. RAID storage systems like NetApp de-duplicate at the block level but the &hellip; <a href=\"https:\/\/timallen.name\/index.php\/2016\/03\/10\/remote-backup\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">remote backup<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-302","post","type-post","status-publish","format-standard","hentry","category-general-programming"],"_links":{"self":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts\/302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/comments?post=302"}],"version-history":[{"count":2,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts\/302\/revisions"}],"predecessor-version":[{"id":308,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/posts\/302\/revisions\/308"}],"wp:attachment":[{"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/media?parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/categories?post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/timallen.name\/index.php\/wp-json\/wp\/v2\/tags?post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}