{"id":39,"date":"2016-06-14T23:06:08","date_gmt":"2016-06-14T23:06:08","guid":{"rendered":"http:\/\/188.223.144.42:4130\/?p=13"},"modified":"2016-06-14T23:06:08","modified_gmt":"2016-06-14T23:06:08","slug":"simple-shell-backup-script","status":"publish","type":"post","link":"https:\/\/ihni.uk\/?p=39","title":{"rendered":"Simple Shell Backup script"},"content":{"rendered":"<p>I had a need to backup some Call logging\/asset management software we have running on a CentOs7 install to a network location, so that we can restore, should everything go tits up.<\/p>\n<p>It contains a backup of the MySQL DB&#8217;s and TARing them for moving to a new location and output to a log file.<\/p>\n<p>This could probably be slimmed down immensely, but it was my 1st shell script, so it&#8217;s rough around the edges!<!--more--><\/p>\n<p>Here is the script.<\/p>\n<blockquote><p><em>#!\/bin\/sh<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em># GLPI Live Backup of SQL, WWW State currently not being backed up.<\/em><\/p>\n<p><em># Runs at 06:00 evry day via a CronTab<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>runat=&#8221;$(date &#8220;+%F&#8221;)&#8221;<\/em><\/p>\n<p><em>timethen=&#8221;$(date +&#8221;%H:%M:%S&#8221;)&#8221;<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>printf &#8220;Daily Backup for %s\\n&#8221; &#8220;$runat&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p>\n<p><em>printf &#8220;Start of Task. $timethen %s\\n&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p>\n<p><em>printf &#8220;Create Todays Backup Folder&#8230;%s\\n&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>mkdir \/bkp\/&#8221;$runat&#8221;<\/em><\/p>\n<p><em>#mkdir \/bkp\/&#8221;$runat&#8221;\/www<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>printf &#8220;Extracting SQL File&#8230;%s\\n&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p>\n<p><em>\/usr\/bin\/mysqldump -u glpi -p&#8217;Access to GLPI-Live 01&#8242; glpi-live &gt; \/bkp\/&#8221;$runat&#8221;\/GLPILiveBackup-&#8220;$runat&#8221;.sql<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>printf &#8220;Compressing SQL File&#8230;%s\\n&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>7z a \/bkp\/GLPILiveBackup-&#8220;$runat&#8221;.7z \/bkp\/&#8221;$runat&#8221;\/GLPILiveBackup-&#8220;$runat&#8221;.sql<\/em><\/p>\n<p><em>rm -f \/bkp\/&#8221;$runat&#8221;\/GLPILiveBackup-&#8220;$runat&#8221;.sql<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>#printf &#8220;Creating www root archive&#8230;%s\\n&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p>\n<p><em>#env pigz=-9 tar -zcvf \/bkp\/&#8221;$runat&#8221;\/www\/GLPIwwwBackup-&#8220;$runat&#8221;.tar.gz \/var\/www\/glpi<\/em><\/p>\n<p><em>#7z a \/bkp\/GLPILive-0.90.1-&#8220;$runat&#8221;.7z \/bkp\/&#8221;$runat&#8221;<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>printf &#8220;Copying locally to Bel-NAS-01&#8230;%s\\n&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p>\n<p><em>cp &#8211;force \/bkp\/GLPILive-0.90.1-&#8220;$runat&#8221;.7z \/mnt\/bel-NAS-01\/GLPI-Backups\/<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>printf &#8220;Copying remotely to Bel_Del&#8230;%s\\n&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p>\n<p><em>cp &#8211;force \/bkp\/GLPILive-0.90.1-&#8220;$runat&#8221;.7z &#8220;\/mnt\/bel_del\/Technical Team\/GLPI-Backup\/&#8221;<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>rm -Rf \/bkp\/&#8221;$runat&#8221;<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>timenow=&#8221;$(date +&#8221;%H:%M:%S&#8221;)&#8221;<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em>printf &#8220;\/bkp\/sql\/GLPILiveBackups-&#8220;$runat $timenow&#8221;.sql.gz %s\\n&#8221; &gt;&gt; \/mnt\/bel-NAS-01\/GLPI-Backups\/archive.txt<\/em><\/p>\n<p><em>printf &#8220;End of Task. $timenow %s\\n&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p>\n<p><em>printf &#8220;==============================%s\\n&#8221; &gt;&gt; \/bkp\/logs\/BackupLog.log<\/em><\/p><\/blockquote>\n<p>This works well and using p7zip i was able to get the over all size of the 100mb SQL dump down to 8mb 4 less than Gzip or TAR.<\/p>\n<p>As time wore on with this script running i had a need to tidy the out put. So done house keeping was required&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had a need to backup some Call logging\/asset management software we have running on&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11,12],"tags":[],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-scripts","category-shell-scripts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=39"}],"version-history":[{"count":0,"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}