{"id":157,"date":"2011-09-21T13:18:42","date_gmt":"2011-09-21T10:18:42","guid":{"rendered":"http:\/\/fatihacar.com\/blog\/?p=157"},"modified":"2011-09-21T13:37:00","modified_gmt":"2011-09-21T10:37:00","slug":"pg_dumpall-with-shell-script-and-crontab-in-linux","status":"publish","type":"post","link":"https:\/\/www.fatihacar.com\/blog\/pg_dumpall-with-shell-script-and-crontab-in-linux\/","title":{"rendered":"pg_dumpall with shell script and crontab in Linux"},"content":{"rendered":"<p>You can take schedule backup with shell script. Firstly, You must create shell script file in operating system. After you can append to crontab.<\/p>\n<p><strong>Crontab<\/strong> is a UNIX command that creates a table or list of commands, each of which is to be executed by the operating system at a specified time. crontab is used to create the crontab file (the list) and later used to change the previously created crontab file.<\/p>\n<p><strong>Crontab<\/strong><\/p>\n<blockquote><p>\ncrontab -e      Edit your crontab file, or create one if it doesn\u2019t already exist.<br \/>\ncrontab -l      List your crontab file.<br \/>\ncrontab -r      Remove your crontab file.<br \/>\ncrontab -v      Display the last time you edited your crontab file. <\/p>\n<p>Minute   Hour   Day of Month       Month          Day of Week        Command<br \/>\n(0-59)  (0-23)     (1-31)    (1-12 or Jan-Dec)  (0-6 or Sun-Sat)<br \/>\n 0        2          12             *               0,6           \/usr\/bin\/shellscriptname.sh\n<\/p><\/blockquote>\n<p>We will take backup wirh pg_dumpall. Firstly, You must create shell script.<\/p>\n<p><strong>Example<\/strong><\/p>\n<blockquote><p>\n$>cd \/etc\/scripts\/<br \/>\n$>vi shellscriptname.sh<br \/>\n<strong>Note :<\/strong> We created shellscriptname.sh with vi shellscriptname.sh statement. You have to write below script.<\/p>\n<p>export today=`date +%Y%m%d`<\/p>\n<p>export deleteday=`\/bin\/date &#8211;date=&#8221;15 days ago&#8221; +%Y%m%d`<\/p>\n<p>##delete old backup script<br \/>\nrm -f \/tmp\/pgalldump_$deleteday.dump.out<\/p>\n<p>##create backup script<br \/>\npg_dumpall > \/tmp\/pgalldump_$today.dump.out<\/p>\n<p><strong>Note :<\/strong> After write, You close editor with &#8221; escape > :wq! > enter &#8220;. You saved.\n<\/p><\/blockquote>\n<p>We wrote shell script. Now, We have to append to crontab.<\/p>\n<p><strong>Example<\/strong><\/p>\n<blockquote><p>$>crontab -e<br \/>\n10 1 * * * \/etc\/scripts\/shellscriptname.sh<\/p>\n<p><strong>Note :<\/strong> After write, You close editor with &#8221; escape > :wq! > enter &#8220;. You saved. This time statement mean that shell script will execute every days of week,every month, every day, at 1 hour past 10 minute.\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>You can take schedule backup with shell script. Firstly, You must create shell script file in operating system. After you can append to crontab. Crontab is a UNIX command that creates a table or list of commands, each of which is to be executed by the operating system at a specified time. crontab is used&#8230;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,18],"tags":[14,15,93],"class_list":["post-157","post","type-post","status-publish","format-standard","hentry","category-administration-postgresql","category-linux-unix","tag-database-administration","tag-linux","tag-postgresql"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p39NFI-2x","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/comments?post=157"}],"version-history":[{"count":6,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/157\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/157\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/media?parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/categories?post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/tags?post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}