How Do I Backup My PostgreSQL Database with Cron?

后端 未结 8 1178
孤街浪徒
孤街浪徒 2021-01-30 09:31

I can run commands like vacuumdb, pg_dump, and psql just fine in a script if I preface them like so:

/usr/bin/sudo -u postgres /usr/bin/pg_dump -Fc mydatabase &g         


        
8条回答
  •  攒了一身酷
    2021-01-30 10:25

    Instead of the following command: databases=psql -h localhost -U postgres -q -c "\l" | sed -n 4,/\eof/p | grep -v rows\) | grep -v template0 | grep -v template1 | awk {'print $1'}

    You can use below: databases=psql -t -c "select datname from pg_database where datname not like 'template%';" | grep -v '^$'

    The first one return '|' for template databases and an empty line.

    The second one is cleaner.

提交回复
热议问题