以下 Windows 批处理脚本在数据库还原时失败:
@Echo off
set Path=C:Program Files (x86)
set Backup_Path=C:Program Files (x86)
c:
cd
cd C:Program Files (x86)PostgreSQL9.1bin
@echo "Wait ..."
setlocal
set PGPASSWORD=1234
psql.exe -U postgres -c "create database Mydata"
"C:Program Files (x86)PostgreSQL9.1binpg_restore.exe" -h localhost -U postgres -d Mydata -f "Mydata.backup"
pause
endlocal
错误是:
pg_restore : -d/- dbname 和 -f/- 文件不能一起使用 试试" pg_restore --帮助 "
-f
是输出文件名,而不是输入文件。
输入文件没有任何参数开关。
c:>pg_restore --help
pg_restore restores a PostgreSQL database from an archive created by pg_dump.
Usage:
pg_restore [OPTION]... [FILE]
General options:
-d, --dbname=NAME connect to database name
-f, --file=FILENAME output file name
-F, --format=c|d|t backup file format (should be automatic)
-l, --list print summarized TOC of the archive
-v, --verbose verbose mode
-V, --version output version information, then exit
-?, --help show this help, then exit
所以你需要使用:
pg_restore.exe -h localhost -U postgres -d Mydata "Mydata.backup"
手册中的更多详细信息:http://www.postgresql.org/docs/current/static/app-pgrestore.html