使用PHP备份MySQL数据库,然后加密文件上传到另一台服务器

发布于 2024-11-29 16:08:20 字数 684 浏览 1 评论 0原文

我已经阅读了一些有关相关代码片段和建议的文章,但我认为他们之间没有就我的任务达成共识,所以我结合了一些问题再次提出。另外,其他的都相当旧了,我想得到一些更新的响应...

目标

  • 完全转储 SQL DB(这样可以将其导入回 MySQL,如果DB被消灭了...)。理想情况下,该 sql 转储可以通过 PHPMyAdmin 导入。
  • 获取转储,通过 PHP5 对其进行加密(我正在考虑使用 mcrypt) 。
  • 获取加密文件,并通过 PHP 中的 SSH2 将其上传到远程服务器。
  • 删除本地加密文件和本地未加密转储。

相反 - 我是否需要访问保存的备份

  • 手动 SFTP 到存储备份的远程服务器。
  • 下载加密备份。
  • 解密它。
  • 通过 PHPMyAdmin 手动导入回 MySQL

我真的不需要脚本来执行相反的过程。如果我需要备份,我已经深入参与了恢复和运行的工作 - 所以手动解密应该不成问题。然而,除了阅读 PHP 手册之外,我确实想确保我知道最佳方法来做到这一点......

I've read several SO about related code snippets and suggestions for this, but I don't think there has been consensus between them for my task, so I'm combining some questions to ask once more. Also, the other ones were pretty old, and I'd like to get some updated responses...

The Goal

  • Dump SQL DB completely (in such a way that this could be imported back into MySQL should the DB be wiped out...). Ideally, this sql dump could be imported via PHPMyAdmin, for example.
  • Take the dump, encrypt it via PHP5 (I am thinking with mcrypt).
  • Take the encrypted file, and upload it to a remote server via SSH2 in PHP.
  • Delete local encrypted file and local unencrypted dump.

On the reverse - should I need to access the saved backup

  • Manually SFTP into remote server where backups are stored.
  • Donwload encrypted backup.
  • Decrypt it.
  • Manually import back into MySQL via PHPMyAdmin

I don't really need a script to do the reverse process. Should I ever need a backup, I'm already deeply involved in getting things back up and runing - so decrypting manually shouldn't be a problem. However I do want to be sure I know the best way to do it, beyond reading the PHP manual...

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

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

发布评论

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

评论(2

哭泣的笑容 2024-12-06 16:08:20

谢谢蒂姆。我在 PHPMySQLAutoBackup 中找到了一个很好的预构建解决方案。我正在添加将使用 system() 用 GPG 进行加密的代码。尽管目前我也遇到了困难。如果我仍然遇到 GPG 问题,我将提出一个新问题......

Thanks tim. I found a good pre-built solution in PHPMySQLAutoBackup . I am adding in the code which will encrypt with GPG using system().. although its not without my hardships at the moment. I will open a new question if I continue to have GPG issues...

栩栩如生 2024-12-06 16:08:20

听起来很简单,真的。

如果您想用 PHP 编写脚本,那没问题。但是,您可能不需要太多 PHP 功能。您基本上只需使用简单的控制结构,shell_exec(),您将使用它来驱动几个命令行工具,例如 mysqldump、gpg(或其他加密实用程序)、scp(将数据发送到异地)和 unlink() 来删除本地副本。

所以听起来您只需要一些指向命令行工具的指针。我在上面提到了我会使用的。除此之外,只需将正确的命令行字符串放在一起并执行 exec() 或 shell_exec() 即可。

Sounds pretty straightforward, really.

If you want to script it in PHP, that's fine. However, you probably don't need much PHP functionality. You'll basically just be using simple control structures, shell_exec(), which you'll use to drive a couple of command-line tools, such as mysqldump, gpg (or other crypto utility), scp (to send your data offsite), and unlink() to delete your local copy.

So it sounds like you just need some pointers to command-line tools. I mentioned the one's I'd use above. Beyond that, it's just a matter of putting together the right command-line strings and exec() or shell_exec()ing them.

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