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

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!

Tom
  • 1,215
  • 3
  • 19
  • 30

1 Answers1

1

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); 
MrGlass
  • 9,094
  • 17
  • 64
  • 89
  • +1 I found out that the command without /* is better because it won't include files beginning with dot otherwise: `tar cvf ~/$filename /public_html` – noob Jan 08 '12 at 15:13
  • I tried that, but got an error: Warning: ftp_put(public_html/backups/Full_Account_Backup.tar.gz) [function.ftp-put]: failed to open stream: No such file or directory in /home/USER/public_html/backups/site_cron_backup.php on line 48 FTP upload has failed. Warning: unlink(public_html/backups/Full_Account_Backup.tar.gz) [function.unlink]: No such file or directory in /home/USER/public_html/backups/site_cron_backup.php on line 63 I would post the full script but I can't in the comments, it's too long – Tom Jan 08 '12 at 19:57
  • It doesn't work as i suggested, but works as you had it above? also, try: $command = "tar cvf ~/$filename ~/public_html/*"; – MrGlass Jan 08 '12 at 22:26
  • @MrGlass Thanks, that did the trick! Is there a way to exclude a folder under public_html? For example backup all of public_html except for public_html/backups. Hope I'm not pushing my luck. Thanks again! – Tom Jan 09 '12 at 03:05
  • I'm not that familiar with the tar command, so I can't help with that. I'm sure there is some way though – MrGlass Jan 09 '12 at 03:26