Jump to content

Direct backup compression output


Guest

Recommended Posts

I am trying to create a backup script for 10s of gigs of data my previous method would just call gzip and make a file then I would download the file. I want to find a way to send the files directly out to the download and not store them in a file. I was thinking about the output buffer like gzip but not exactly sure if that would work because from my point of view the data is uncompressed at the client side. I also had tar pop into my mind i know its not compressed but it would be all files in one place atleast. Anyways can someone help me get in the right direction thanks.

Link to comment
https://forums.phpfreaks.com/topic/244160-direct-backup-compression-output/
Share on other sites

This is easiest done via bash (which can be executed through php if need be). Something like....

 

tar zcvf - /www | ssh user@backupserver "cat > /backup/www-bkp.tar.gz"

 

This tars the /www and sends the output directly to stdout which is then piped to ssh and cat'd into the new location.

 

Thank you im going to write a script around this to do what i need ill upload it when done.

 

I have another problem with this though since there isnt a set content size what happens if say the wireless disconnects for a second or something happens while taring wouldnt it look like the download finished but really it just dies or lost connection? Is there a way to fix that?

Here is what i ended up with it seems to work ok.

 

<?php

// Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=backup.tar");
header("Content-Type: application/x-tar");
header("Content-Transfer-Encoding: binary");


$handle=popen("tar zcvf - /www","r");
echo fread($handle, 2096);
while (!feof($handle)) {
echo fread($handle, 2096);
ob_flush(); flush();
}
pclose($handle);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.