$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 /'的任何想法吗?谢谢!
答案 0 :(得分:1)
你只需要改变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);