Home > bash, PostgreSQL > PostgreSQL backup and compress schemas only of a db server

PostgreSQL backup and compress schemas only of a db server

root@darkwater:[Sun May 13 00:27:32]:[/home/db.schema.backup]$ cat /home/db.schema.backup/bin/db.schema.dump.sh
#!/bin/sh

here=`pwd`
cd /home/db.schema.backup/


for db in `echo "\l" |  /opt/pgsql/bin/psql -U postgres  | grep -v template | sed '4,$!d' | awk '{print $1}' | grep -v "(" | sed 's/^$//'`
do
  
  echo  "$(date): ${db} schema dump START" | tee -a | gzip -9 -c  >> ${db}.schema.only.sql.gz
  /opt/pgsql/bin/pg_dump -s -U postgres ${db} | /usr/bin/sed '/^$/d' | gzip -9 -c  >> ${db}.schema.only.sql.gz
  echo  "$(date): ${db} schema dump END" | tee -a | gzip -9 -c >>  ${db}.schema.only.sql.gz
done

cd "${here}"

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: