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
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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.