2012-01-08 113 views
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文件。也从/ public_html/backups /文件夹运行任何想法如何限制从'/'保存到'/ public_html /'?谢谢!只备份public_html的PHP备份脚本

回答

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); 
+0

+1我发现该命令而不/ *更好,因为它不包括与点开始,否则文件:'焦油CVF〜/ $文件名/ public_html' – noob 2012-01-08 15:13:09

+0

我试过了,却得到了一个错误: 警告:ftp_put(public_h tml/backups/Full_Account_Backup.tar.gz)[function.ftp-put]:无法打开流:48上的/home/USER/public_html/backups/site_cron_backup.php中没有这样的文件或目录 FTP上传失败。 警告:取消链接(public_html/backups/Full_Account_Backup.tar.gz)[function.unlink]:没有这样的文件或目录在/home/USER/public_html/backups/site_cron_backup.php在线63 我会发布完整的脚本但我不能在评论中,这太长 – Tom 2012-01-08 19:57:59

+0

我试过MrGLass和micha的建议 – Tom 2012-01-08 20:01:46