如何从 .t​​ar 文件恢复 PostgreSQL 数据库?

如何从 .t​​ar 文件恢复 PostgreSQL 数据库?

我使用 WHM 在增量备份期间备份了所有 PostgreSQL 数据库,它会创建 $dbName。柏油文件。

数据存储在这些 .tar 文件中,但我不知道如何通过 SSH 将其恢复到各个数据库中。特别是文件位置。

我一直在使用:

pg_restore -d client03 /backup/cpbackup/daily/client03/psql/client03.tar

生成错误“无法打开输入文件:权限被拒绝”

任何帮助均感激不尽。

答案1

找到了正确的代码串,以防其他人发现这个线程。

pg_restore -c -U postgres -d client03 -v "/tmp/client03.tar" -W

细分来自http://www.postgresql.org/docs/7.3/static/app-pgrestore.html并进行一些反复试验。

本质上...

-c to clean the database
-U to force a user
-d to select the database
-v verbose mode, don't know why
"$$" the location of the files to import in tmp to get around permission issues
-W to force asking for the password to the user (postgres)

希望以上内容能够帮助到其他人。

答案2

当使用 PgAdmin III 为我进行恢复时,它通过使用其自身构建的以下命令完美地运行:

pg_restore --host localhost --port 5432 --username "my_user_name" --dbname "my_db_name" --role "my_user_name" --no-password  --verbose "/Users/me/Desktop/backup_file.tar"

请注意,为了避免出现警告,最好让备份文件中的对象所有者角色已存在于目标服务器中。此外,您还应该已创建目标数据库并由该角色拥有。

答案3

对于版本 9.5,在命令行中运行以下命令

pg_restore -W -c -U [username] -d [database_name] -v "[path to extracted tar]"

答案4

下面是通过单击数据库并右键单击并选择恢复从 pgAdmin iii 生成的。我导航到我拥有的 .tar 文件,它自己完成了此操作。

/usr/bin/pg_restore --host localhost --port 5434 --username "postgres" \
--dbname "dvdrental" --no-password  --schema public --verbose \
"/home/npena/Desktop/dvd/dvdrental.tar"

相关内容