背景

有时候我们需要备份 schema或者包括数据,然后恢复到另外一个postgres db中。

备份

可以使用 pg_dump 来备份,或者加上 –schema-only 只备份schema.

pg_dump --file "/root/repo/uat-copy.tar" --host "db host name" --port "23123" --username "admin" --password --verbose --format=t --blobs --schema-only "compose"

恢复

同样的,可以使用pg_restore来恢复

pg_restore --host "hostname here" --port "31090" --username "usernamehere" --password --dbname "ibmclouddb" --verbose "/root/repo/uat-copy.tar"

不管备份还是恢复,都会要求输入密码。