PHP备份脚本仅备份public_html

发布于 2024-12-25 19:53:47 字数 801 浏览 0 评论 0原文

$filename= "Backup.tar";   // The name (and optionally path) of the dump file 
$ftp_server = "IP";      // Name or IP. Shouldn't have any trailing slashes and shouldn't be prefixed with ftp:// 
$ftp_port = "21";   // FTP port - blank defaults to port 21 
$ftp_username = "User";      // FTP account username 
$ftp_password = "Pass";      // FTP account password - blank for anonymous 
$filename = "public_html/backups/" . $filename . ".gz"; 

$command = "tar cvf ~/$filename ~/*"; 
$result = exec($command); 

$command = "gzip -9 -S .gz ~/$filename"; 
$result = exec($command); 

这是我使用的工作备份。它备份服务器上的所有内容,包括电子邮件(例如/mail/。我只想备份/public_html文件夹及其下的所有子目录。它在/public_html/backups/文件夹中创建一个tar.gz文件。PHP脚本也从 /public_html/backups/ 文件夹运行。关于如何限制从 '/' 保存到 '/public_html/' 的内容,有什么想法吗?

$filename= "Backup.tar";   // The name (and optionally path) of the dump file 
$ftp_server = "IP";      // Name or IP. Shouldn't have any trailing slashes and shouldn't be prefixed with ftp:// 
$ftp_port = "21";   // FTP port - blank defaults to port 21 
$ftp_username = "User";      // FTP account username 
$ftp_password = "Pass";      // FTP account password - blank for anonymous 
$filename = "public_html/backups/" . $filename . ".gz"; 

$command = "tar cvf ~/$filename ~/*"; 
$result = exec($command); 

$command = "gzip -9 -S .gz ~/$filename"; 
$result = exec($command); 

This is my working backup that I use. It backs up everything on the server including emails (for example /mail/. I only want to backup the /public_html folder and all subdirectories under it. It creates a tar.gz file in the /public_html/backups/ folder. The PHP script also runs from the /public_html/backups/ folder. Any idea on how to restrict what is saved from '/' to '/public_html/' ? Thanks!

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

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

发布评论

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

评论(1

残月升风 2025-01-01 19:53:47

您只需要更改 tar 命令的第三个输入

$filename= "Backup.tar";   // The name (and optionally path) of the dump file 
$ftp_server = "IP";      // Name or IP. Shouldn't have any trailing slashes and shouldn't be prefixed with ftp:// 
$ftp_port = "21";   // FTP port - blank defaults to port 21 
$ftp_username = "User";      // FTP account username 
$ftp_password = "Pass";      // FTP account password - blank for anonymous 
$filename = "public_html/backups/" . $filename . ".gz"; 

$command = "tar cvf ~/$filename /public_html/*"; 
$result = exec($command); 

$command = "gzip -9 -S .gz ~/$filename"; 
$result = exec($command); 

you just need to change the third input of the tar command

$filename= "Backup.tar";   // The name (and optionally path) of the dump file 
$ftp_server = "IP";      // Name or IP. Shouldn't have any trailing slashes and shouldn't be prefixed with ftp:// 
$ftp_port = "21";   // FTP port - blank defaults to port 21 
$ftp_username = "User";      // FTP account username 
$ftp_password = "Pass";      // FTP account password - blank for anonymous 
$filename = "public_html/backups/" . $filename . ".gz"; 

$command = "tar cvf ~/$filename /public_html/*"; 
$result = exec($command); 

$command = "gzip -9 -S .gz ~/$filename"; 
$result = exec($command); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文