| 知乎专栏 |
本地备份
pg_dump --compress=9 --file=/backup/mydb.sql.gz mydb
Backup
pg_dump -i -h localhost -p 5432 -U user -Fc -c -f "your_db.backup" your_db
Restore
pg_restore -i -h localhost -p 5432 -U user -d your_db -v -c -Fc "your_db.backup"
local -> remote
set PG_HOME="C:\Program Files\PostgreSQL\8.1\bin" %PG_HOME%\pg_dump.exe -i -h localhost -p 5432 -U woodart -Fc -c -f "woodart.backup" woodart %PG_HOME%\pg_restore.exe -i -h woodart.8800.org -p 5432 -U woodart -d woodart -v -c -Fc "woodart.backup"
split 命令可以将大型文件切成小块以适应文件系统限制的单个文件大小。
分割,每650M为一个文件,试用于光盘备份
$ pg_dump dbname | split -b 650m - filename
合并,并且恢复到数据库中。
$ createdb dbname $ cat filename* | psql dbname
从 schema 中导出数据
pg_dump -h 192.168.1.242 -U user -s database -n schema > schema.sql
导入目标数据库
psql -U user -d your-db -f schema.sql
首先吧 pg_dump 导出的数据复制到 docker 容器内
[root@rwa pptx]# docker cp api.sql postgres:/tmp/ Successfully copied 73.7kB to postgres:/tmp/ [root@rwa pptx]# docker cp bills.sql postgres:/tmp/ Successfully copied 125kB to postgres:/tmp/
[root@rwa pptx]# docker exec -it postgres bash root@f402670ad8c3:/# createdb -h 127.0.0.1 -U postgres -E UTF8 -O postgres nano-bills root@f402670ad8c3:/# psql -U postgres -d nano-bills -f /tmp/bills.sql root@f402670ad8c3:/# exit exit