{"id":776,"date":"2010-01-27T13:46:29","date_gmt":"2010-01-27T18:46:29","guid":{"rendered":"http:\/\/www.gamescheat.ca\/?p=776"},"modified":"2019-09-04T19:57:39","modified_gmt":"2019-09-05T00:57:39","slug":"success-failure-of-the-tar-command-recorded-with-time-and-date-stamp","status":"publish","type":"post","link":"http:\/\/www.gamescheat.ca\/?p=776","title":{"rendered":"Success, failure of the tar command recorded with time and date stamp"},"content":{"rendered":"<p>I needed to determine the amount of time it would take to archive large amount of data on my unix server.  If I had infinite amount of free time I could sit in front of the screen with a stop watch.  But the better way is to create a script that would record the start time, stop time, success and failures.  Below is the script I created in the bash shell.                                             <\/p>\n<blockquote><p>#!\/bin\/sh<br \/>\n# This script archive directories and create a log file with the time and date stamp.<br \/>\n# Andrew Lin<br \/>\n# www.GamesCheat.ca<br \/>\n# 27 January, 2010<\/p>\n<p>cd \/backup\/archive<br \/>\necho \u201cBackup start: \u201d > backup.log 2>&1<br \/>\ndate >> backup.log 2>&1<\/p>\n<p>cd \/export\/home<\/p>\n<p># tar cvf \/backup\/archive\/backup.tar dir1 dir2 >> \/backup\/archive\/backup.log 2>&1                                             <\/p>\n<p>tar cvf \/backup\/archive\/backup.tar dir1 dir2 2>>\/backup\/archive\/backup.log<\/p>\n<div style=\"float: left;\"><div style=\"margin: 15px 15px 15px 15px\";><script type=\"text\/javascript\"><!--\ngoogle_ad_client = \"pub-3319935785736004\";\ngoogle_alternate_color = \"FFFFFF\";\ngoogle_ad_width = 336;\ngoogle_ad_height = 280;\ngoogle_ad_format = \"336x280_as\";\ngoogle_ad_type = \"text_image\";\ngoogle_ad_channel =\"\";\ngoogle_color_border = \"cccccc\";\ngoogle_color_link = \"cc0000\";\ngoogle_color_bg = \"ffffff\";\ngoogle_color_text = \"000000\";\ngoogle_color_url = \"008000\";\n\/\/--><\/script>\n<script type=\"text\/javascript\"\n  src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\n<\/script><\/div><\/div><p>echo \u201cBackup Stop: \u201d >> \/backup\/archive\/backup.log 2>&1<br \/>\ndate >> \/backup\/archive\/backup.log 2>&1<\/p><\/blockquote>\n<p>#!\/bin\/sh<br \/>\nThis indicates that the script is written to be executed in the Bash shell.<\/p>\n<p>The # sign indicates the line is a comment.<\/p>\n<p>cd \/backup\/archive<br \/>\nChange the path \/backup\/archive to where this script is located on your machine.<\/p>\n<p>echo \u201cBackup start: \u201d > backup.log 2>&1<br \/>\nCreate a file backup.log. The text Backup start: is inserted into this file.  The file will be created in the directory<br \/>\n\/backup\/archive.<\/p>\n<p>date >> backup.log 2>&1<br \/>\nThe date will be appended into the file backup.log.  This is useful if you wanted to determine the time of execution of the  script.<\/p>\n<p>cd \/export\/home<br \/>\nGo to the directory \/export\/home.  This directory contains the files or directories you wish to backup.<\/p>\n<p># tar cvf \/backup\/archive\/backup.tar dir1 dir2 >> \/backup\/archive\/backup.log 2>&1<br \/>\nThis line is commented out with the # sign.  Uncomment this line if you want a detailed log of the tar command.  Success and  failure will be recorded in the log.  Depending on the amount of files being archived this log could become very long.<\/p>\n<p>tar cvf \/backup\/archive\/backup.tar dir1 dir2 2>>\/backup\/archive\/backup.log<br \/>\nThis command will copy the directories dir1 and dir2.  The copies will be stored in \/backup\/archive\/backup.tar.  Any error will be recorded in the file backup.log.  If you wanted  both error and success recorded then comment this line out and uncomment the line above it.<\/p>\n<p>echo \u201cBackup Stop: \u201d >> \/backup\/archive\/backup.log 2>&1<br \/>\nAfter the completion of the tar command, insert the line Backup Stop: into the file backup.log.<\/p>\n<p>date >> \/backup\/archive\/backup.log 2>&1<br \/>\nInsert the date and time into the file backup.log.  This is useful for determining the completion time\/date of the script.<\/p>\n<p>Save this file with the name of backup-script.  Make sure that you make the file executable, with the chmod command, e.g.<br \/>\nchmod 777 backup-script.log<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I needed to determine the amount of time it would take to archive large amount of data on my unix server. If I had infinite amount of free time I could sit in front of the screen with a stop&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/www.gamescheat.ca\/?p=776\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[21,55,64,35],"_links":{"self":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/776"}],"collection":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=776"}],"version-history":[{"count":4,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/776\/revisions"}],"predecessor-version":[{"id":970,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/776\/revisions\/970"}],"wp:attachment":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=776"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}