PHP postgres 备份

发布于 2024-08-25 07:20:24 字数 465 浏览 9 评论 0原文

我正在尝试制作一个 Postgres PHP 备份脚本。我已经下载了一个命令行,如下所示:

#!/bin/bash
find /home/russell/pg_bkp -type f -mtime +7 -exec rm {} \;
time=`date +%Y-%m-%d`; # date in reverse so that lastest date appears last in the list of backup files.
PGPASSWORD=****** pg_dump -i -h localhost -p 5432 -U postgres -F c -b -v -f "/home/russell/pg_bkp/$time.backup" ah3

How can I Implement this in PHP?这创建的扩展名是.backup。它效果很好并且已经使用了很多次。数据很完美,但从我的网站内部进行会更好。谢谢

I am trying to make a Postgres PHP backup script. I have downloaded one for the command line which looks like this:

#!/bin/bash
find /home/russell/pg_bkp -type f -mtime +7 -exec rm {} \;
time=`date +%Y-%m-%d`; # date in reverse so that lastest date appears last in the list of backup files.
PGPASSWORD=****** pg_dump -i -h localhost -p 5432 -U postgres -F c -b -v -f "/home/russell/pg_bkp/$time.backup" ah3

How can I implement this in PHP? The extension that this creates is .backup. It works great and have used it many times. the data is perfect, but doing it from inside my website would be better. Thanks

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

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

发布评论

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

评论(1

杀手六號 2024-09-01 07:20:24

请更好地格式化代码。

对于您的问题,您可以将这些命令保存在文件中,然后通过 execpassthru

在 php 中,你甚至可以用特殊的撇号 ` 编写命令,它就会被执行。

只需确保 PHP 服务有运行该脚本的权限

Please, format better the code.

For your question, you can save those command in a file, and then call it throught php via exec or passthru.

In php, you can even write the command with the special apostrophes, `, and it will be executed.

Just make sure the PHP service has the permission to run that script

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文