Guest Posted August 7, 2011 Share Posted August 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/244160-direct-backup-compression-output/ Share on other sites More sharing options...
trq Posted August 8, 2011 Share Posted August 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/244160-direct-backup-compression-output/#findComment-1253949 Share on other sites More sharing options...
Guest Posted August 8, 2011 Share Posted August 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/244160-direct-backup-compression-output/#findComment-1253959 Share on other sites More sharing options...
Guest Posted August 8, 2011 Share Posted August 8, 2011 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244160-direct-backup-compression-output/#findComment-1254110 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.