如何将PG转储从测试服务器带到我的PC

发布于 2025-01-18 13:13:31 字数 138 浏览 5 评论 0原文

我正在尝试将PG转储从测试服务器带到本地计算机,我已登录到服务器

root@myProject stiging-development1:〜/myproject/current#

我应该在这里写下哪个命令,以将PG转储到我的本地机器?

I am trying to take pg dump from testing server to my local machine, i have been logged into my server

root@myproject-staging-development1:~/myproject/current#

Which command should i write in here to get pg dump into my local machine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你是孤单的心事 2025-01-25 13:13:31

转储您的 PostgreSQL 数据库

第 1 步 通过

SSH 连接到临时/生产服务器。

步骤 2

转储所需的数据库:

pg_dump database_name > database_name_20160527.sql

您可以根据需要命名转储 - 我使用日期来区分多个转储。

步骤 3

离开 SSH 并使用 SCP 下载新的 SQL 文件。

scp login@host:path_to_dir_with/database_name_20160527.sql database_name_20160527.sql

此命令使用 SSH 将您登录到远程服务器,并将给定文件下载到您指定的本地目录。如果您没有提供本地目录的路径,转储将保存在您当前的工作目录中。

示例:

scp [email protected]:/home/my_app/backups/my_app_database_20160527.sql my_app_database_20160527.sql 

恢复您的 PostgreSQL 转储

步骤 1

如果您想使用当前的本地主机数据库,则必须先删除它:

psql template1 -c 'drop database database_name;'

步骤 2

在本地主机上创建一个新数据库:

psql template1 -c 'create database database_name with owner your_user_name;

步骤 3

将转储写入数据库:

psql database_name < database_name_20160527.sql

来源

Dump Your PostgreSQL Database

Step 1

SSH to the staging/production server.

Step 2

Dump the desired database:

pg_dump database_name > database_name_20160527.sql

You can name your dump as you wish - I'm using dates to distinguish multiple dumps.

Step 3

Leave SSH and download your new SQL file using SCP.

scp login@host:path_to_dir_with/database_name_20160527.sql database_name_20160527.sql

This command logs you into your remote server using SSH and downloads a given file to the local directory specified by you. If you give no path to the local directory, the dump will be saved in your current working dir.

Example:

scp [email protected]:/home/my_app/backups/my_app_database_20160527.sql my_app_database_20160527.sql 

Restore Your PostgreSQL Dump

Step 1

If you want to use the current localhost database, you must drop it first:

psql template1 -c 'drop database database_name;'

Step 2

Create a new database on the localhost:

psql template1 -c 'create database database_name with owner your_user_name;

Step 3

And write your dump into the database:

psql database_name < database_name_20160527.sql

Source

清风无影 2025-01-25 13:13:31

您可以通过ssh命令运行pg_dump,因此您有一个单位:

filename="tmp/backup_$(date +%Y-%m-%d_%H-%M-%S).sql"

ssh user@IP \
  "pg_dump --no-owner postgresql://user:[email protected]/dbname" \
  >"$filename"

You can run the pg_dump via the ssh command so you have a one-liner:

filename="tmp/backup_$(date +%Y-%m-%d_%H-%M-%S).sql"

ssh user@IP \
  "pg_dump --no-owner postgresql://user:[email protected]/dbname" \
  >"$filename"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文