Postgres:在从bash脚本重新创建/重新填充之前,清除整个数据库 [英] Postgres: clear entire database before re-creating / re-populating from bash script
本文介绍了Postgres:在从bash脚本重新创建/重新填充之前,清除整个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个shell脚本(将成为cronjob),该脚本将:
I'm writing a shell script (will become a cronjob) that will:
1:转储我的生产数据库
1: dump my production database
2:将转储导入到我的开发数据库中
2: import the dump into my development database
在步骤1和2之间,我需要清除开发数据库(删除所有表?).如何从shell脚本中最好地完成这一工作?到目前为止,它看起来像这样:
Between step 1 and 2, I need to clear the development database (drop all tables?). How is this best accomplished from a shell script? So far, it looks like this:
#!/bin/bash
time=`date '+%Y'-'%m'-'%d'`
# 1. export(dump) the current production database
pg_dump -U production_db_name > /backup/dir/backup-${time}.sql
# missing step: drop all tables from development database so it can be re-populated
# 2. load the backup into the development database
psql -U development_db_name < backup/dir/backup-${time}.sql
推荐答案
我只是删除数据库,然后重新创建它.在UNIX或Linux系统上,应该这样做:
I'd just drop the database and then re-create it. On a UNIX or Linux system, that should do it:
$ dropdb development_db_name
$ createdb development_db_name
实际上,这就是我的方法.
That's how I do it, actually.
这篇关于Postgres:在从bash脚本重新创建/重新填充之前,清除整个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文