Last active
December 26, 2015 23:58
-
-
Save 3manuek/7233930 to your computer and use it in GitHub Desktop.
Dump only views from a postgres database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VIEWS="" ; for view in $(psql -U postgres -c 'select schemaname || $$.$$ ||viewname from pg_views where schemaname::text !~ $$information_schema|pg_catalog$$ ' -tA) ; do VIEWS="$VIEWS -t $view" ; done ; /opt/pg/bin/pg_dump -Upostgres -c -s $VIEWS | |
Optionally you can dump into a file: | |
VIEWS="" ; for view in $(psql -U postgres -c 'select schemaname || $$.$$ ||viewname from pg_views where schemaname::text !~ $$information_schema|pg_catalog$$ ' -tA) ; do VIEWS="$VIEWS -t $view" ; done ; /opt/pg/bin/pg_dump -Upostgres -c -s $VIEWS -f view_dump.sql | |
===== | |
#!/usr/local/bin/bash | |
DB=$1 | |
PGBIN=/usr/local/bin | |
VIEWS="" ; for view in $($PGBIN/psql -U $USER $DB -c 'select schemaname || $$.$$ ||viewname from pg_views where schemaname::text !~ $$information_schema|pg_catalog$$ ' -tA) ; do VIEWS="$VIEWS -t $view" ; done ; $PGBIN/pg_dump -U $USER -c -s $VIEWS -f view_dump.sql $DB | |
#!/usr/local/bin/bash | |
DB=$1 | |
DIA=$(date +%Y%m%d%H%M) | |
PGBIN=/usr/local/bin | |
VIEWS="" ; for view in $($PGBIN/psql -U $USER $DB -c 'select schemaname || $$.$$ ||viewname from pg_views where schemaname::text !~ $$information_schema|pg_catalog$$ ' -tA) ; do VIEWS="$VIEWS -t $view" ; done ; $PGBIN/pg_dump -U $USER | |
-c -s $VIEWS -f view_dump.sql $DB | |
uuencode view_dump.sql view_dump_$DIA.sql | mail -s "Backup vistas" [email protected] | |
uuencode view_dump.sql view_dump_$DIA.sql | mail -s "Backup vistas" [email protected] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment