Guest User

Untitled

a guest
Jan 22nd, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. WHICH="`which which`"
  5. DT="`date +"%Y_%m_%d_%H_%M"`"
  6.  
  7.  
  8. DUMP=`which pg_dump`
  9.  
  10. BACKUP_DIR="/pg_backup"
  11. USER="postgres"
  12.  
  13. MAIL="kishore.k@domain.com"
  14. HOST=`hostname`
  15. LOGFILE="${BACKUP_DIR}/pg_sql_bkp_${DT}.log"
  16.  
  17. touch ${LOGFILE}
  18. exec 6>&1 # Link file descriptor #6 with stdout.
  19. # Saves stdout.
  20.  
  21. exec 7>&2 # Link file descriptor #7 with stderr.
  22. # Saves stderr.
  23.  
  24. exec > ${LOGFILE} # stdout and err replaced with file ${LOGFILE}.
  25. exec 2> ${LOGFILE}
  26.  
  27.  
  28. # Do the actual dump
  29. echo "Starting backups `date` "
  30. ${DUMP} -U${USER} -F t -f ${BACKUP_DIR}/"db_name_"${DT} "db_name"
  31. user_ret=$?
  32.  
  33.  
  34. size=`du -h ${BACKUP_DIR}`
  35.  
  36. echo "Deleting 10 day old files ..."
  37. find ${BACKUP_DIR}/ -mtime +10 -exec rm -vf {} \;
  38.  
  39. echo -e "User: $user_ret \nsize: ${size} "
  40.  
  41. echo "Done backups `date` "
  42. cat ${LOGFILE} | mail -s "PgSQL log for ${HOST} - ${DT}" ${MAIL}
  43.  
  44.  
  45. #Clean up IO redirection
  46. exec 1>&6 6>&- # Restore stdout and close file descriptor #6.
  47. exec 2>&7 7>&- # Restore stdout and close file descriptor #7.
Add Comment
Please, Sign In to add comment