老大让st把表给我,于是她发了备份数据库文件给我,居然是.backup后缀名(后来验证,是错给的windows下的备份文件了)因为我保存了却没有这个后缀,再让单独保存后给我,依旧不能还原。QQ是个很**的东东啊,发送文件,居然自动给我加上了.list和.dynamic后缀名
这后缀名是要我有多无语,自己备份下
发现了命令调用
上图的最上方
搜到了postgresql的文档http://www.postgresql.org/docs/8.1/static/backup.html ,备份和还原,http://www.linuxsir.org/main/node/265(这个是中文版,不过有个问题,是不能-D选项为错,如下所示)
xia@ubuntu:~$ /usr/lib/postgresql/8.4/bin/pg_dump -D -h localhost -U sa example > example.bak
得到如下提示
/usr/lib/postgresql/8.4/bin/pg_dump: invalid option -- 'D'
Try "pg_dump --help" for more information.
根据上面个图最上行的提示,在st电脑上运行以下类似命令行:
xia@ubuntu:~$ /usr/bin/pg_dump --host 127.0.0.1 --port 5432 --username sa example > example.bak再在我电脑上进行还原
xia@ubuntu:~$ /usr/lib/postgresql/8.4/bin/psql -h localhost -U sa -d example < example.bak
正确情况下,提示如下:
Password for user sa:
SET
SET
SET
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
CREATE INDEX
ALTER TABLE
WARNING: no privileges could be revoked for "public"
REVOKE
WARNING: no privileges could be revoked for "public"
REVOKE
WARNING: no privileges were granted for "public"
GRANT
WARNING: no privileges were granted for "public"
GRANT
经验证,成功还原。
在我电脑上,也可以先删除example数据库
xia@ubuntu:~$ sudo -u postgres sh [sudo] password for xia: $ dropdb example
再新建数据库并退出
$ createdb -O sa example $ exit用windows下的backup文件进行还原,则得到以下提示:
ERROR: syntax error at or near "PGDMP"
LINE 1: PGDMP
REVOKE ALL ON SCHEMA public FROM postgres;
^
WARNING: no privileges were granted for "public"
GRANT
ERROR: syntax error at or near ""
.......
ERROR: invalid byte sequence for encoding "UTF8": 0xd302
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".
其实用pgadmin3备份还原也可以的,只是新建数据库还是得通过命令行来,对标操作可以直接图形化搞定。
成功情况下,退出码为0
不成功,则退出码为1
至此,搞定~~~
菜鸟go go go ~~~