• Home
  • Services
    • HR Services
      • HR Advisory Services
      • Contract Staffing
      • HR Outsourcing Services
      • Manpower Supply Services
      • Payroll Processing
      • Permanent Placement
      • Recruitment and Placement Services
      • Recruitment Process Outsourcing
      • Staffing Agency Services
    • DBA Support
      • DBA Consultancy Services
      • PostgreSQL Support
    • Website Maintenance
    • Company Registration Services
    • Virtual Office Space Address
  • Company
    • FAQs
    • About Us
    • Contact
  • Locations
  • Blogs
    • Blog
    • Blog – PostgreSQL Support
    • Blog – PostgreSQL Migration
    • Blog – All DB’s
    • Blog – Linux
  • Courses

    About Courses

    • List Of Courses
    • Become an Instructor
    Greenplum

    Greenplum

    $1,500.00
    Read More
    Have any question?
    (+91)8838953252
    ITsupport@rayafeel.com
    Login
    RayaFeeL
    • Home
    • Services
      • HR Services
        • HR Advisory Services
        • Contract Staffing
        • HR Outsourcing Services
        • Manpower Supply Services
        • Payroll Processing
        • Permanent Placement
        • Recruitment and Placement Services
        • Recruitment Process Outsourcing
        • Staffing Agency Services
      • DBA Support
        • DBA Consultancy Services
        • PostgreSQL Support
      • Website Maintenance
      • Company Registration Services
      • Virtual Office Space Address
    • Company
      • FAQs
      • About Us
      • Contact
    • Locations
    • Blogs
      • Blog
      • Blog – PostgreSQL Support
      • Blog – PostgreSQL Migration
      • Blog – All DB’s
      • Blog – Linux
    • Courses

      About Courses

      • List Of Courses
      • Become an Instructor
      Greenplum

      Greenplum

      $1,500.00
      Read More

      PostgreSQL Daily backup automated shell script

      • Home
      • PostgreSQL Daily backup automated shell script

      PostgreSQL Daily backup automated shell script

      • Posted by 2ndnijam
      • Date January 4, 2019

      this script will take the postgresql base backup based on  daily changes (if you scheduled daily) &  it will delete the old backup if backup  retention period is reached 2 days. you can call this as postgresql incremental  backup Script  because this Script is taking backup of changes only  means it is taking archive and XLOG files only. If postgresql instance is crashed means you can recover the data by using point​ in time recovery.

      cat /home/script/Postgres_backup.sh
      #!/bin/bash
      
      PGDATA=/data/
      PGHOME=/opt/PostgreSQL/9.3/bin
      HOT=/backup
      WAL_LOC=/archive/
      LOG=/home/script/script_logs
      TODAY=$(date +"%m-%d-%Y")
      
      /opt/PostgreSQL/9.3/bin/psql -X -U postgres -h localhost -c 'select now() as "Online Backup Start Time";' >> $LOG/backupinfo_$TODAY.log
      
      /opt/PostgreSQL/9.3/bin/psql -X -U postgres -h localhost -c  "select setting from pg_settings where name='data_directory'; " >> $LOG/backupinfo_$TODAY.log
      
      #psql -U postgres -c " select pg_switch_xlog(); " >> $LOG/backupinfo_$TODAY.log
      
      ## Adding Checkpoint for consistent backup
      
      echo "CHECKPOINT;
      SELECT pg_start_backup('Full Backup');
      -- Making Sure all in WAL is archived after checkpoint
      
      select pg_switch_xlog();"|/opt/PostgreSQL/9.3/bin/psql -X -U postgres -h localhost >> $LOG/backupinfo_$TODAY.log
      
      tar -cvzf $HOT/onlinebackup_$TODAY.tar.gz $PGDATA/* >> $LOG/backupinfo_$TODAY.log
      
      tar --remove-files -cvzf $HOT/arch_$TODAY.tar $WAL_LOC/* >> $LOG/backupinfo_$TODAY.log
      
      /opt/PostgreSQL/9.3/bin/psql -X -U postgres  -h localhost -c " select pg_stop_backup(); " >> $LOG/backupinfo_$TODAY.log
      
      ## Archiving all transaction in Mid of Backup
      
      /opt/PostgreSQL/9.3/bin/psql -X -U postgres -h localhost -c "select pg_switch_xlog();" >> $LOG/backupinfo_$TODAY.log
      
      /opt/PostgreSQL/9.3/bin/psql -X -U postgres -h localhost -c 'select now() as "Online Backup End Time";' >> $LOG/backupinfo_$TODAY.log
      
      # Online Backup file Retention policy will be 2 day's
      
      find /backup -name "onlinebackup_*.tar.gz" -mtime +2 -exec ls -l {} \; >> $LOG/backupinfo_$TODAY.log
      
      find /backup -name "onlinebackup_*.tar.gz" -mtime +2 -exec rm -r {} \;
      
      # Archive Backup file Retention policy will be 2 day's
      
      find /backup -name "arch_*.tar" -mtime +2 -exec ls -l {} \; >> $LOG/backupinfo_$TODAY.log
      
      find /backup -name "arch_*.tar" -mtime +2 -exec rm -r {} \;
      
      #mail -s " `hostname` :: Fullbackup Information" rdba-alerts@enterprisedb.com < $LOG/backupinfo_$TODAY.log
      exit 0
      

      Contact Us

      Fields with (*) are compulsory.

      • Share:
      2ndnijam

      Previous post

      PostgreSQL Multile Schema Backup & Restore,Backup Script,Restoring Script,Backup & Restore Prerequest & PostRequest
      January 4, 2019

      Next post

      PostgreSQL Script For 30 Days Old error log file moving
      January 4, 2019

      Search

      ADVERTISEMENT

      Latest Posts

      Tips to Choose the Best Serviced Office for Your Business
      24May2022
      What key considerations do you need to keep in mind when choosing a new serviced office to house your business?
      24May2022
      The Benefits of Coworking
      24May2022
      The Long-Term Impact of Coworking
      24May2022
      Are you spending more money than you earn? Outsource with Ease and Move When You’re Ready
      24May2022
      PostgreSQL

      PostgreSQL

      $800.00 $500.00
      Greenplum

      Greenplum

      $1,500.00
      Oracle Database

      Oracle Database

      $350.00
      2ndquadrant.in

      (+91) 8838953252

      ITsupport@rayafeel.com

      Company

      • About Us
      • Our Team

      COURSES

      • List Of Course
      • Become An Instructor

      Support

      • DBA Support
      • Consultancy Services

      Recommend

      • Login
      • Contact Us

      IT Services by rayafeel.com. Powered by Rayafeel Technologies Pvt Ltd.

      • Privacy
      • Terms

      Become An Instructor?

      Join thousand of instructors and earn money hassle free!

      Get Started Now

      Connect with

      Login with Google Login with Twitter Login with Linkedin Login with Windowslive Login with Yahoo

      Login with your site account

      Connect with



      Lost your password?