cut for whole lines
Craig White
craigwhite at azapple.com
Wed Oct 31 20:22:33 MST 2007
On Wed, 2007-10-31 at 15:46 -0700, Craig White wrote:
> I am trying to script reading the table info from postgres into a file.
>
> I need to get rid of the first 2 and last 2 lines and it should be easy
> but obviously cut is for grabbing bits of lines where I need to remove
> the whole line.
----
OK for posterity purposes, below is the end result script
Thanks JT, Steve, Nathan, Eric... I didn't realize that head/tail had
negated options and my man page doesn't indicate that is possible and
since I lack imagination, I didn't even guess at it (but I did look for
it in man tail). This seems to be a good looking script...I have PLUG to
thank for anything I manage to eek out of shell scripts ;-)
anyway, the resultant script turns out to be...
*** begin pg_table_dump.scr ***
#/bin/sh
#
# Script to identify tables, backup schema and data separately and
# then finally, vacuum each table
#
DB_NAME=MY_DB
BACKUP_PATH=/home/backup/postgres/production
MY_SCHEMA=public
PG_USER=craig
#
psql -U $PG_USER \
$DB_NAME \
-c "SELECT tablename FROM pg_tables WHERE \
schemaname = "\'$MY_SCHEMA\'";" | \
grep -v 'tablename' | \
grep -v [\--*] | \
grep -v rows\) > $BACKUP_PATH/pg_tables
#
for i in `cat $BACKUP_PATH/pg_tables`
do
pg_dump \
--username=$PG_USER \
--schema=$MY_SCHEMA \
--table=$i \
--schema-only \
$DB_NAME > $BACKUP_PATH/schemas/$i.sql
pg_dump \
--username=$PG_USER \
--schema=$MY_SCHEMA \
--table=$i \
--data-only \
$DB_NAME > $BACKUP_PATH/data/$i.sql
vacuumdb \
--username=$PG_USER \
--dbname=$DB_NAME \
--table=$MY_SCHEMA.$i \
--verbose \
--full
done
*** end pg_table_dump.scr ***
More information about the PLUG-discuss
mailing list