开发者

making snapshots of postgres db [closed]

开发者 https://www.devze.com 2023-04-12 08:46 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

im trying to write a python script that takes snapshots of a postgres database and restores those snapshots. trying to get pg_dump > data.sql to work has been a nightmare and i came across an idea that i wanted to run past you guys.

the idea is to follow this logic for taking the snapshot:

1 - stop the postgres daemon
2 - copy the {postgres}/data folder out
3 - start the daemon

then to restore a snapshot:

1 - stop the postgres daemon
2 - delete the {postgres}/data folder
3 - copy the snapshot data folder in place
4 - reset the permissions of the data folder to the postgres user
5 - start开发者_如何学JAVA the daemon

this is a test database so downtime isn't an issue.


If your question is how to run commands from a Python script, you can use subprocess.Popen() to run shell commands such as sudo /etc/init.d/postgresql-x.x stop, etc.

But, in my opinion, you should use pg_dump and pg_restore utilities, they will do the work in a more safe and efficient way, and don't need to stop the Postgres daemon.

Take a look at the pg_dump and the pg_restore chapters in the PostgreSQL documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消