pg_dump备份数据

pg_dump -U admin -a --column-inserts -t <table_name> <db_name>

以insert的方式显示,这时控制台可能为乱码,修改为输出到文件即可


备份一个数据库,用insert输出:

@echo off
echo execute pg_dump
set /p dbname=please input database name:
echo dump database is %dbname%
f:\pgsql\pgsql9.1.4\bin\pg_dump.exe --file %dbname%.sql --host=localhost --port=5432 -U admin -a --column-inserts %dbname%
echo done!
pause

复制并保持为bat,执行之即可。



转帖:http://xiaofengtoo.iteye.com/blog/1815129


@echo off
e:
cd E:\PostgreSQL\PostgreSQL\bin\
set server=192.168.1.99
set post=5432
set username=test
set schema="\"test"\"
set catalog="test"
::: 获取时间
set datevar=%date:~0,4%%date:~5,2%%date:~8,2%
set timevar=%time:~0,2%
if /i %timevar% LSS 10 (
set timevar=0%time:~1,1%
)
set timevar=%timevar%%time:~3,2%%time:~6,2%
set datetime=%datevar%%timevar%
set file=C:\Users\Administrator\Desktop\%datetime%.sql
                         
rem single table_scripte and data
rem pg_dump.exe --host  %server% --port %post% --username  %username% --no-password  --verbose --table ge_game_type --column-inserts --file %file% --schema %schema% %catalog%
rem single table_scripte
rem pg_dump.exe --host  %server% --port %post% --username  %username% --no-password  --verbose --table tt_test2 --schema-only --file %file% --schema %schema% %catalog%
rem all script
pg_dump.exe --host  %server% --port %post% --username  %username% --no-password  --verbose  --schema-only --file %file% --schema %schema% %catalog%
rem all script and data
rem pg_dump.exe --host  %server% --port %post% --username  %username% --encoding UTF8 --no-password  --verbose  --column-inserts  --file %file% --schema %schema% %catalog%
rem single table data
rem pg_dump.exe --host  %server% --port %post% --username  %username% --no-password   --data-only --verbose --table ge_game_type --column-inserts --file %file% --schema %schema% %catalog%
rem all table data
rem pg_dump.exe --host  %server% --port %post% --username  %username% --no-password --data-only --verbose  --column-inserts --file %file% --schema %schema% %catalog%
@echo 备份完成!


你可能感兴趣的:(pgsql)