I’d like to create a backup script for files and folders on my server and I found this:
# Name of the buckup file
$filename = 'BACKUP_' . date('Y.m.d') . '.tar.gz';
# Target path where to save the file
$targetPath = '/path/to/backup/';
# Directory to backup
$dir = "/path/to/files/";
# Execute the tar command and save file
system( "tar -pczf ".$targetPath ."".$filename." ".$dir );
Which works well, then I can just pass the URL to the script and the right headers and download the file.
My issues is that I’ll be running this frequently and don’t want to keep the backup on the server. So I’m trying to find a creative way to maybe create a temp file that gets removed. Issue is some of the files could be rather large and I have no way of knowing when the file has been downloaded completely.
You may create backup files in /tmp, and than use:
Read http://php.net/manual/ru/function.readfile.php for more info.
PS
Also you may use ZipArchive class(build-in) to create your own archive more flexible.