簡體   English   中英

使用pg_dump結果作為pg_restore的輸入

[英]Use pg_dump result as input for pg_restore

我需要在同一台服務器上克隆數據庫(僅架構)。 我想使用pg_dump的輸入並將其傳遞給pg_restore。 我知道這可以用psql完成,但psql沒有“-c clean”選項。

這有可能,但pg_restore?

 pg_dump --schema public dbName | psql dbNameTest

接下來是:

pg_dump --schema-only --format c dbName | \
  pg_restore --schema-only --clean --dbname=dbNameTest

除非dbNameTest尚不存在, dbNameTest它不起作用。 以下工作(雖然它抱怨dbNameTest已經存在。我可以忍受)

createdb dbNameTest
pg_dump --schema-only --format c dbName | \
  pg_restore --schema-only --clean --dbname=dbNameTest

短期選擇的oneliner將是:

createdb dbNameTest ; pg_dump -s -F c dbName | pg_restore -s -c -d dbNameTest

sh腳本pg_copy_schema會像:

#!/bin/sh
if [ -z "$2" ] ; then echo "Usage: `basename $0` original-db new-db" ; exit 1 ; fi
echo "Copying schema of $1 to $2"
createdb "$2" 2> /dev/null
pg_dump --schema-only --format c "$1" | pg_restore --schema-only --clean --dbname="$2"

http://www.postgresql.org/docs/9.1/static/app-pgdump.html

您需要將-F與-c,-d或-t選項與pg_dump結合使用,以便將其與pg_restore一起使用。 您不能將pg_restore與純文本SQL轉儲一起使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM