{"id":272,"date":"2021-04-29T08:45:37","date_gmt":"2021-04-29T14:45:37","guid":{"rendered":"https:\/\/thecweb.com\/?p=272"},"modified":"2021-04-29T08:45:37","modified_gmt":"2021-04-29T14:45:37","slug":"website-backup","status":"publish","type":"post","link":"https:\/\/thecweb.com\/index.php\/2021\/04\/29\/website-backup\/","title":{"rendered":"Website Backup"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Why?<\/h2>\n\n\n\n<p>I\u2019ve tried several backup solutions for linux, and I wasn\u2019t able to find something that did what I wanted.&nbsp; Backula was way too much work to set up.&nbsp; I actually spent several hours installing and configuring a web interface for Bacula to make it easier, but once I got it all up and running I found it was just a reporting tool.&nbsp; Bacula is more for an enterprise with hundreds of servers to backup.&nbsp; Backuppc wasn\u2019t really flexible enough.&nbsp; I read through various tar backup scripts and finally decided to install Powershell on the server, and see about writing my own.&nbsp; Then, I realized that I need to conceptualize what I want to accomplish, before I decide what tools to use\u2026&nbsp; So this document.&nbsp;&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What?<\/h2>\n\n\n\n<p>The major components are going to be the website, database, and all of \/etc at least.\u00a0 I also think a backup of the installed packages should be good.\u00a0 I don\u2019t want a large backup.\u00a0 I don\u2019t really think I should have to dedicate 30 GB to it.\u00a0 One hiccup is that I want it to be stored on my Win 10 PC, so it can be synced with a google cloud account.\u00a0 One of mine has a TB, so there should be plenty.\u00a0\u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Specifically?<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>DB &#8211; I\u2019m guessing the output of this will be small, but testing<br>mysqldump &#8211;all-databases &gt; dump.sql<\/li><\/ul>\n\n\n\n<p>Only 2.8MB&nbsp; ~ 84 MB per month<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>WordPress &#8211; everything appears to be under \/var\/www, so I\u2019ll just tar that whole bitch up.<br>sudo tar -cpvzf website.tar.gz \/var\/www\/<br>142MB &#8211; this might require incremental.\u00a0 4.3 GB per month.\u00a0\u00a0<\/li><li>Packages &#8211; apt-clone doesn\u2019t appear to be a base package, but seems to be exactly what I want, so the command below will work.\u00a0 I don\u2019t really see needing more than one of these, but the files are small enough that 30 days would be fine.\u00a0<br>sudo apt-clone clone &lt;filename>\u00a0\u00a0<\/li><\/ul>\n\n\n\n<p>Backup is 22k which is not worth my time to do the math.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\/etc &#8211; super important because I don\u2019t know how many hours I\u2019ve dumped into this server.\u00a0 Way too long to not have a backup.\u00a0<br>sudo tar -cpvzf etc.tar.gz<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">When?<\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>Hourly<ul><li>In \u201chourly\u201d folder we\u2019ll have tar archives labeled 1-24<\/li><\/ul><\/li><li>Daily<ul><li>In \u201cdaily\u201d folder we\u2019ll have tar archives labeled 1-31<\/li><\/ul><\/li><li>Monthly<ul><li>In \u201cmonthly\u201d folder we\u2019ll have tar archives labeled 1-12<\/li><\/ul><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Code example<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/snap\/bin\/pwsh\r\n#\r\n# Chris Weber\r\n# 4\/16\/2021\r\n# Updated\r\n#\r\n# Backup solution for web server\r\n#\r\n\r\n\r\n# Get day of month\r\n$Hour = get-date -Format \"hh\"\r\n# backup storage\r\n#$backupStore = \"\/media\/backup\/hourly\/$Hour\"\r\n# Generate backups and put in tmp\r\nSet-Location -Path \"\/tmp\"\r\n\r\n# DB\r\n\/usr\/bin\/mysqldump --all-databases > db.sql\r\n\r\n# Website\r\n\/usr\/bin\/tar -cpzf website.tar.gz \/var\/www\/\r\n\r\n# Packages\r\n\/usr\/bin\/apt-clone clone \/tmp\r\n\r\n# etc\r\n\/usr\/bin\/tar -cpzf etc.tar.gz \/etc\r\n\r\n\r\n# Move stuff to the place\r\nMove-Item -force -path \/tmp\/db.sql -destination \/media\/backup\/hourly\/$Hour.sql\r\nMove-Item -force -path \/tmp\/website.tar.gz -destination \/media\/backup\/hourly\/$Hour.website.tar.gz\r\nMove-Item -force -path \/tmp\/apt-clone-state-thecweb.com.tar.gz -destination \/media\/backup\/hourly\/$Hour.apt-clone-state-thecweb.com.tar.gz\r\nMove-Item -force -path \/tmp\/etc.tar.gz -destination \/media\/backup\/hourly\/$Hour.etc.tar.gz\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Issues to fix!!!1!<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Hourly backup is only doing 12 because I didn&#8217;t specify 24 hour time format when setting $hour<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Why? I\u2019ve tried several backup solutions for linux, and I wasn\u2019t able to find something that did what I wanted.&nbsp; Backula was way too much work to set up.&nbsp; I actually spent several hours installing and configuring a web interface for Bacula to make it easier, but once I got it all up and running [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":101,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[30],"class_list":["post-272","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-tinkering"],"_links":{"self":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":1,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"predecessor-version":[{"id":273,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts\/272\/revisions\/273"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/media\/101"}],"wp:attachment":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}