Sponsored Content
Full Discussion: Backup-Script for Postgres
Top Forums Shell Programming and Scripting Backup-Script for Postgres Post 302381863 by karl_ha on Monday 21st of December 2009 07:27:55 AM
Old 12-21-2009
Here is a script which is working:

Code:
ST="localhost"
PG_PORT="5432"
PG_USER="postgres"
PG_BIN="/usr/lib/postgresql/8.3/bin/"

#LOG_DIR="/backup/logs"
#LOGFILE=$LOG_DIR/"pgBackup_log"
LOGFILE="/backup/logs/pg_backup.log"

ACT_DATE=$(date '+%d-%m-%y')
EXP_DATE=$(date -d '1 day ago' '+%d-%m-%y')
BACKUP_DIR="/backup/tmp"
COMPRESSION="9"
PG_CON="-U $PG_USER"
BACKUP_OPTIONS="$PG_CON -b -C -F c -Z $COMPRESSION"
VACUUM_OPTIONS="$PG_CON -e"

echo "***** DB_BACKUP $ACT_DATE *****" >>$LOGFILE
for db in `$PG_wk {'print $1'}`BIN/psql $PG_CON -lt | sed /\eof/p | grep -v rows\) | awk {'print $1'}`
  do
    # vacuum
    echo $(date '+%c')" -- vacuuming database $db" >> $LOGFILE
    if $PG_BIN/vacuumdb $VACUUM_OPTIONS $db
      then
      echo "OK!" >>$LOGFILE
    else
      echo "No Vacuum in database $db!" >>$LOGFILE
    fi
    # backup
    echo $(date '+%c')" -- backing up database $db" >>$LOGFILE
    if  $PG_BIN/pg_dump $BACKUP_OPTIONS -f $BACKUP_DIR/$db-$ACT_DATE.pgdump $db
      then
      echo "OK, deleting old backup" >>$LOGFILE
      rm ./$db-$EXP_DATE.pgdump
    else
      echo "Database $db not backuped!" >>$LOGFILE
    fi
  done



---------- Post updated at 01:27 PM ---------- Previous update was at 01:26 PM ----------

Code:
awk {'print $1'}`

What is awk doing?

Last edited by pludi; 12-21-2009 at 09:39 AM.. Reason: code tags instead of php please...
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how will i connect postgres database from unix shell script

I have got the solution so just closing this issue. (3 Replies)
Discussion started by: jambesh
3 Replies

2. Shell Programming and Scripting

Postgres : pg_dump Error

hi friends, i have script to take backup of postgresql server ....i am getting error like access denied myscript.sh sendEmail=/home/backup/scripts/sendEmail.pl DAY=`/bin/date +%d-%m-%y` DIR=/home/backup/psql/$DAY test -d $DIR | mkdir -p $DIR dblist="test test1 postgres" for db in... (8 Replies)
Discussion started by: jagnikam
8 Replies

3. Shell Programming and Scripting

testing postgres connection in shell script

I have a script that does db query in postgres. I'm trying to put in some error checking in the script. I keep running into the password prompt problem where when invalid credentials/or database is put it, it would prompt me for a password which hangs the script. Is there a way that I can check for... (0 Replies)
Discussion started by: zerofire123
0 Replies

4. Shell Programming and Scripting

help copy *.txt to postgres

hi all, a have problem to load *.txt to postgres my database: id_list_ip (nextval) list_ip (varchar) txt file (list_ip.txt) hasilping_10.8.248.1 hasilping_119.110.112.226 hasilping_119.110.125.33 hasilping_125.22.1.25 hasilping_192.168.2.1 hasilping_202.73.96.70 script... (3 Replies)
Discussion started by: adi0926
3 Replies

5. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

6. Shell Programming and Scripting

Help with Backup Shell Script for Network Device Configuration backup

HI all, im new to shell scripting. need your guidence for my script. i wrote one script and is attached here Im explaining the requirement of script. AIM: Shell script to run automatically as per scheduled and backup few network devices configurations. Script will contain a set of commands... (4 Replies)
Discussion started by: saichand1985
4 Replies

7. Shell Programming and Scripting

Postgres in Linux

I have this 15 postgres sql queries similar to below to run in linux... Its taking a lot of time to run (3hours) . can any one plz guide me how can i reduce the time of execution execute 'insert into cc.rpt_cons_sub_ccdb_data(report_date, server_name, report_type, count) select... (3 Replies)
Discussion started by: nikhil jain
3 Replies

8. Shell Programming and Scripting

Script for removing Postgres

I made a script to remove Postgres if this is already installed on your system. I have a other script to install Postgres, so this script can be used before you going to install Postgres. Do you like this script? I would love to hear feedback. #!/bin/bash # #################################... (2 Replies)
Discussion started by: dannyvdberg
2 Replies

9. Shell Programming and Scripting

Taking information from a postgres sql query and putting it into a shell script array

I have a postgres sql statement that is the following: select age from students; which gives me the entries: Age --- 10 15 13 12 9 14 10 which is about 7 rows of data. Now what I would like to do with this is use a shell script to create an array age. As a results... (3 Replies)
Discussion started by: JSNY
3 Replies
shells(4)							   File Formats 							 shells(4)

NAME
shells - shell database SYNOPSIS
/etc/shells DESCRIPTION
The shells file contains a list of the shells on the system. Applications use this file to determine whether a shell is valid. See getuser- shell(3C). For each shell a single line should be present, consisting of the shell's path, relative to root. A hash mark (#) indicates the beginning of a comment; subsequent characters up to the end of the line are not interpreted by the routines which search the file. Blank lines are also ignored. The following default shells are used by utilities: /bin/bash, /bin/csh, /bin/jsh, /bin/ksh, /bin/ksh93, /bin/pfcsh, /bin/pfksh, /bin/pfsh, /bin/sh, /bin/tcsh, /bin/zsh, /sbin/jsh, /sbin/sh, /usr/bin/bash, /usr/bin/csh, /usr/bin/jsh, /usr/bin/ksh, /usr/bin/ksh93, /usr/bin/pfcsh, /usr/bin/pfksh, /usr/bin/pfsh, and /usr/bin/sh, /usr/bin/tcsh, /usr/bin/zsh, and /usr/sfw/bin/zsh. /etc/shells overrides the default list. Invalid shells in /etc/shells could cause unexpected behavior, such as being unable to log in by way of ftp(1). FILES
/etc/shells list of shells on system SEE ALSO
vipw(1B), ftpd(1M), sendmail(1M), getusershell(3C), aliases(4) SunOS 5.11 20 Nov 2007 shells(4)
All times are GMT -4. The time now is 06:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy