4

我正在使用 PostgreSQL 8.4,我想做备份和恢复(从 Ubuntu 11.10 到 Ubuntu 12.4)

我想包括所有分区、集群、角色和东西。

我的命令:备份:

dumb_all > filename 

压缩:

zip -f mybackup

解压和恢复:

sudo gunzip -c /home/ubuntu/Desktop/backupFile.zip | psql -U postgres

问题在恢复过程中,我收到错误

invalid command \.
ERROR:  syntax error at or near "2"
LINE 1: 2 2 1
        ^
invalid command \.
ERROR:  syntax error at or near "1"
LINE 1: ...
        ^
out of memory

另外,带有分区的表没有恢复。还有一些没有任何数据的表恢复!

请帮忙!

编辑

我使用 pgAdmin 进行备份,使用“备份服务器”选项。

备份

4

1 回答 1

3

If you did used zip to compress the output, then you should use unzip do uncompress it, not gunzip, they use different formats/algorithms.

I'd suggest you to use gzip and gunzip only. For instance, if you generated a backup named mybackup.sql, you can gzip it with:

gzip mybackup.sql

It will generate a file named mybackup.sql.gz. Then, to restore, you can use:

gunzip -c mybackup.sql.gz | psql -U postgres

Also, I'd suggest you to avoid using pgAdmin to do the dump. Not that it can't do, it is just that you can't automatize it, you can easily use pg_dumpall the same way:

pg_dumpall -U postgres -f mybackup.sql

You can either dump and compress without intermediate files using pipe:

pg_dumpall -U postgres | gzip -c > mybackup.sql.gz

BTW, I'd really suggest you avoiding pg_dumpall and use pg_dump with custom format for each database, as with that you already get the result compressed and easier to use latter. But pg_dumpall is ok for small databases.

于 2013-10-10T12:19:24.730 回答