{"id":320,"date":"2012-05-24T04:17:03","date_gmt":"2012-05-23T22:47:03","guid":{"rendered":"http:\/\/asgaur.com\/wp\/?p=320"},"modified":"2012-05-24T04:17:03","modified_gmt":"2012-05-23T22:47:03","slug":"linux-bak_backup-sh","status":"publish","type":"post","link":"http:\/\/www.asgaur.com\/wp\/linux-bak_backup-sh\/","title":{"rendered":"Linux: BAK_***backup.sh"},"content":{"rendered":"<p>#!\/bin\/sh\t\t\t\t\t\t\t\t\t<br \/>\n##########################################\t\t\t\t\t\t\t\t\t<br \/>\n#\t\t\t\t<\/p>\n<p><!-- Adsense block #930 not displayed since it exceed the limit of 3 --><\/p>\n<p>\n# SYSTEM NAME : \t\t\t\t\t\t\t\t\t<br \/>\n# SUBSYSTEM   : \t\t\t\t\t\t\t\t\t<br \/>\n# SHELL_NAME  : BAK_***backup.sh\t\t\t\t\t\t\t\t\t<br \/>\n# FUNCTION    : backup OS image for ****\t\t\t\t\t\t\t\t\t<br \/>\n# USAGE       :\tSYSTEM Backup\t\t\t\t\t\t\t\t<br \/>\n# CALLED BY   : NONE\t\t\t\t\t\t\t\t\t<br \/>\n# CALL TO     : NONE\t\t\t\t\t\t\t\t\t<br \/>\n# RETURNS     : 0=OK, 1=NG\t\t\t\t\t\t\t\t\t<br \/>\n# DESCRIPTION : backup OS image for ****\t\t\t\t\t\t\t\t\t<br \/>\n# HISTORY     :\t\t\t\t\t\t\t\t\t<br \/>\n#    2009\/04\/10  ****  FIRST RELEASE\t\t\t\t\t\t\t\t\t<br \/>\n#\t\t\t\t\t\t\t\t\t<br \/>\n##########################################\t\t\t\t\t\t\t\t\t<\/p>\n<p>##########################################\t\t\t\t\t\t\t\t<br \/>\n# Enviroment :\t\t\t\t\t\t\t\t\t<br \/>\n##########################################\t\t\t\t\t\t\t\t\t<br \/>\n# \/dev\/sda1  = \/\t\t\t\t\t\t\t\t\t<br \/>\n# \/dev\/sda2  = \/var\t\t\t\t\t\t\t\t\t<br \/>\n# \/dev\/sda3  = \/tmp\t\t\t\t\t\t\t\t\t<br \/>\n# \/dev\/sda5  = swap\t\t\t\t\t\t\t\t\t<br \/>\n##########################################\t\t\t\t\t\t\t\t\t<br \/>\nBK_PART=&#8221;\/dev\/sda1 \/dev\/sda2 \/dev\/sda3&#8243;\t\t\t\t\t\t\t\t\t<\/p>\n<p>##########################################\t\t\t\t\t\t\t\t\t<br \/>\n# Main :\t\t\t\t\t\t\t\t\t<br \/>\n##########################################\t\t\t\t\t\t\t\t<br \/>\n# tape position set to BOT\t\t\t\t\t\t\t\t\t<br \/>\nmt -f \/dev\/nst0 rewind\t\t\t\t\t\t\t\t\t<br \/>\nRC=$?\t\t\t\t\t\t\t\t\t<br \/>\nif [ $RC -ne 0 ]\t\t\t\t\t\t\t\t\t<br \/>\nthen\t\t\t\t\t\t\t\t\t<br \/>\n\techo &#8220;Failed to set tape position to BOT!! RC=$RC&#8221;\t\t\t\t\t\t\t\t<br \/>\n\texit 1\t\t\t\t\t\t\t\t<br \/>\nfi\t\t\t\t\t\t\t\t\t<\/p>\n<p># copy \/etc\/fstab\t\t\t\t\t\t\t\t\t<br \/>\nif [ $RC -eq 0 ]\t\t\t\t\t\t\t\t\t<br \/>\nthen\t\t\t\t\t\t\t\t\t<\/p>\n<p>\tmkdir -p \/mnt\/sda1\t\t\t\t\t\t\t\t<br \/>\n\tmount \/dev\/sda1 \/mnt\/sda1\t\t\t\t\t\t\t\t<br \/>\n\tRC=$?\t\t\t\t\t\t\t\t<br \/>\n\tif [ $RC -ne 0 ]\t\t\t\t\t\t\t\t<br \/>\n       \tthen\t\t\t\t\t\t\t\t<br \/>\n       \t        echo &#8220;Mount \/dev\/sda1 partition to \/mnt\/sda1 failed!! RC=$RC&#8221;\t\t\t\t\t\t\t\t<br \/>\n       \tfi\t\t\t\t\t\t\t\t<br \/>\n\tcp -p \/mnt\/sda1\/etc\/fstab \/etc\/fstab\t\t\t\t\t\t\t\t<br \/>\n\tRC=$?\t\t\t\t\t\t\t\t<br \/>\n\tif [ $RC -ne 0 ]\t\t\t\t\t\t\t\t<br \/>\n       \tthen\t\t\t\t\t\t\t\t<br \/>\n       \t        echo &#8220;Copy \/etc\/fstab failed!! RC=$RC&#8221;\t\t\t\t\t\t\t\t<br \/>\n       \tfi\t\t\t\t\t\t\t\t<br \/>\n\tumount \/mnt\/sda1\t\t\t\t\t\t\t\t<br \/>\nfi\t\t\t\t\t\t\t\t\t<\/p>\n<p># getting partition-info and backup partition-info &amp; restore shell.\t\t\t\t\t\t\t\t\t<br \/>\nif [ $RC -eq 0 ]\t\t\t\t\t\t\t\t\t<br \/>\nthen\t\t\t\t\t\t\t\t\t<br \/>\n\tsfdisk -d \/dev\/sda > \/tmp\/sfdisk.dump\t\t\t\t\t\t\t\t<br \/>\n\tRC=$?\t\t\t\t\t\t\t\t<br \/>\n\tif [ $RC -eq 0 ]\t\t\t\t\t\t\t\t<br \/>\n\tthen\t\t\t\t\t\t\t\t<br \/>\n\t\t#mkdir -p \/mnt\/sda1\t\t\t\t\t\t\t<br \/>\n\t\tmount \/dev\/sda1 \/mnt\/sda1\t\t\t\t\t\t\t<br \/>\n\t\tRC=$?\t\t\t\t\t\t\t<br \/>\n\t\tif [ $RC -ne 0 ]\t\t\t\t\t\t\t<br \/>\n        \tthen\t\t\t\t\t\t\t\t<br \/>\n        \t        echo &#8220;Mount \/dev\/sda1 partition to \/mnt\/sda1 failed!! RC=$RC&#8221;\t\t\t\t\t\t\t\t<br \/>\n\t\t\texit 1\t\t\t\t\t\t<br \/>\n        \tfi\t\t\t\t\t\t\t\t<br \/>\n\t\tcp -p \/mnt\/sda1\/acom\/***\/bin\/backup\/BAK_***restore.sh \/tmp\t\t\t\t\t\t\t<br \/>\n\t\tRC=$?\t\t\t\t\t\t\t<br \/>\n\t\tif [ $RC -eq 0 ]\t\t\t\t\t\t\t<br \/>\n\t\tthen\t\t\t\t\t\t\t<br \/>\n\t\t\tcd \/tmp\t\t\t\t\t\t<br \/>\n\t\t\ttar -cf \/dev\/nst0 sfdisk.dump BAK_***restore.sh\t\t\t\t\t\t<br \/>\n\t\t\tRC=$?\t\t\t\t\t\t<br \/>\n\t\t\tif [ $RC -ne 0 ]\t\t\t\t\t\t<br \/>\n\t\t\tthen\t\t\t\t\t\t<br \/>\n\t\t\t\techo &#8220;getting tar image for \/tmp failed!! RC=$RC&#8221;\t\t\t\t\t<br \/>\n\t\t\tfi\t\t\t\t\t\t<br \/>\n\t\telse\t\t\t\t\t\t\t<br \/>\n\t\t\techo &#8220;Copy restore shell failed!! RC=$RC&#8221;\t\t\t\t\t\t<br \/>\n\t\tfi\t\t\t\t\t\t\t<br \/>\n\t\tumount \/mnt\/sda1\t\t\t\t\t\t\t<br \/>\n\t\t#rmdir \/mnt\/sda1\t\t\t\t\t\t\t<br \/>\n\telse\t\t\t\t\t\t\t\t<br \/>\n\t\techo &#8220;getting partition info failed!! RC=$RC&#8221;\t\t\t\t\t\t\t<br \/>\n\t\texit 1\t\t\t\t\t\t\t<br \/>\n\tfi\t\t\t\t\t\t\t\t<br \/>\nfi\t\t\t\t\t\t\t\t\t<\/p>\n<p># getting dump images\t\t\t\t\t\t\t\t\t<br \/>\nif [ $RC -eq 0 ]\t\t\t\t\t\t\t\t\t<br \/>\nthen\t\t\t\t\t\t\t\t\t<br \/>\n\tfor part in $BK_PART\t\t\t\t\t\t\t\t<br \/>\n\tdo\t\t\t\t\t\t\t\t<br \/>\n\t\techo &#8220;getting dump image for $part&#8221;\t\t\t\t\t\t\t<br \/>\n\t\tdump -uf \/dev\/nst0 $part\t\t\t\t\t\t\t<br \/>\n\t\tRC=$?\t\t\t\t\t\t\t<br \/>\n\t\tif [ $RC -ne 0 ]\t\t\t\t\t\t\t<br \/>\n\t\tthen\t\t\t\t\t\t\t<br \/>\n\t\t\techo &#8220;getting dump image for $part failed!! RC=$RC&#8221;\t\t\t\t\t\t<br \/>\n\t\t\tbreak\t\t\t\t\t\t<br \/>\n\t\tfi\t\t\t\t\t\t\t<br \/>\n\t\techo &#8220;finished getting dump image for $part&#8221;\t\t\t\t\t\t\t<br \/>\n\tdone\t\t\t\t\t\t\t\t<br \/>\nfi\t\t\t\t\t\t\t\t\t<\/p>\n<p>mt -f \/dev\/nst0 rewind\t\t\t\t\t\t\t\t\t<br \/>\nRC=$?\t\t\t\t\t\t\t\t\t<br \/>\nif [ $RC -ne 0 ]\t\t\t\t\t\t\t\t\t<br \/>\nthen\t\t\t\t\t\t\t\t\t<br \/>\n\techo &#8220;Warning : Failed to set tape position to BOT!!(RC=$RC). check tape condition.&#8221;\t\t\t\t\t\t\t\t<br \/>\n\tRC=0\t\t\t\t\t\t\t\t<br \/>\nfi\t\t\t\t\t\t\t\t\t<\/p>\n<p># add dumpdates to \/etc\/dumpdates\t\t\t\t\t\t\t\t\t<br \/>\nif [ $RC -eq 0 ]\t\t\t\t\t\t\t\t\t<br \/>\nthen\t\t\t\t\t\t\t\t\t<\/p>\n<p>\tmount \/dev\/sda1 \/mnt\/sda1\t\t\t\t\t\t\t\t<br \/>\n\tRC=$?\t\t\t\t\t\t\t\t<br \/>\n\tif [ $RC -ne 0 ]\t\t\t\t\t\t\t\t<br \/>\n       \tthen\t\t\t\t\t\t\t\t<br \/>\n       \t        echo &#8220;Mount \/dev\/sda1 partition to \/mnt\/sda1 failed!! RC=$RC&#8221;\t\t\t\t\t\t\t\t<br \/>\n       \tfi\t\t\t\t\t\t\t\t<br \/>\n\tcat \/etc\/dumpdates >> \/mnt\/sda3\/etc\/dumpdates\t\t\t\t\t\t\t\t<br \/>\n\tumount \/mnt\/sda1\t\t\t\t\t\t\t\t<br \/>\n\trmdir \/mnt\/sda1\t\t\t\t\t\t\t\t<br \/>\nfi\t\t\t\t\t\t\t\t\t<\/p>\n<p>if [ $RC -ne 0 ]\t\t\t\t\t\t\t\t\t<br \/>\nthen\t\t\t\t\t\t\t\t\t<br \/>\n\texit 1\t\t\t\t\t\t\t\t<br \/>\nelse\t\t\t\t\t\t\t\t\t<br \/>\n\techo &#8220;Backup Finished. Please reboot.&#8221;\t\t\t\t\t\t\t\t<br \/>\n\texit 0\t\t\t\t\t\t\t\t<br \/>\nfi\t\t\t\t\t\t\t\t\t<\/p>\n<p>##########################################\t\t\t\t\t\t\t\t\t<br \/>\n### End of file<\/p>\n<div class=\"item_footer\">\n<p><small><a href=\"http:\/\/asgaur.com\/asgaur.php\/2009\/06\/26\/linux-bak_-backup-sh\" target=\"_blank\" rel=\"noopener\">Original post<\/a> blogged on <a href=\"http:\/\/b2evolution.net\/\" target=\"_blank\" rel=\"noopener\">b2evolution<\/a>.<\/small><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/sh ########################################## # # SYSTEM NAME : # SUBSYSTEM : # SHELL_NAME : BAK_***backup.sh # FUNCTION : backup OS image for **** # USAGE : SYSTEM Backup # CALLED BY : NONE # CALL TO : NONE # RETURNS : 0=OK, 1=NG # DESCRIPTION : backup OS image for **** # HISTORY : # 2009\/04\/10 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-320","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"http:\/\/www.asgaur.com\/wp\/wp-json\/wp\/v2\/posts\/320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.asgaur.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.asgaur.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.asgaur.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.asgaur.com\/wp\/wp-json\/wp\/v2\/comments?post=320"}],"version-history":[{"count":0,"href":"http:\/\/www.asgaur.com\/wp\/wp-json\/wp\/v2\/posts\/320\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.asgaur.com\/wp\/wp-json\/wp\/v2\/media?parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.asgaur.com\/wp\/wp-json\/wp\/v2\/categories?post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.asgaur.com\/wp\/wp-json\/wp\/v2\/tags?post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}