CodeIgniter Forums
backup to variable don't work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: backup to variable don't work (/showthread.php?tid=8676)



backup to variable don't work - El Forum - 05-27-2008

[eluser]Chalda Pnuzig[/eluser]
Hi all,
I have this code:
Code:
function backup(){
    $this->CI =& get_instance();
    $this->CI->load->dbutil();
    $this->CI->load->helper('file');
    $backup = & $this->CI->dbutil->backup();
    $filename='backup/db.'.date("YmdHi").'.sql.gz';
    write_file($filename, $backup);
}

The problem is the function don't create the file, but do a "force download" to a empty file called like the url...
Why?

This is the log:
Code:
DEBUG - 2008-05-26 01:57:32 --> Database Forge Class Initialized
DEBUG - 2008-05-26 01:57:32 --> Database Utility Class Initialized
DEBUG - 2008-05-26 01:57:32 --> Database Forge Class Initialized
DEBUG - 2008-05-26 01:57:32 --> Database Utility Class Initialized
DEBUG - 2008-05-26 01:57:32 --> Helpers loaded: file



backup to variable don't work - El Forum - 05-27-2008

[eluser]gtech[/eluser]
nevermind next post makes more sense.


backup to variable don't work - El Forum - 05-27-2008

[eluser]gtech[/eluser]
reading the code a bit more if the format is txt, all that dbutil->backup($prefs); returns is a string.. you could echo that string to see if you are getting anything back

Code:
$prefs = array(
                'format'      => 'txt',             // gzip, zip, txt
              );
  echo $this-CI->dbutil->backup($prefs);

if you are then the problem is with the write_file, you could do a check to see if you have write permissions to the folder..

The problem is the backup code does not appear to log anything so you will not see any error message, so its worth doing the check.


you could also check write_file as follows
Code:
...
    $this->CI->load->helper('file');
    $data = 'Some file data';
    $filename='backup/db.'.date("YmdHi").'.txt';

    if ( ! write_file($filename, $data))
    {
       echo 'Unable to write the file';
    }
    else
    {
       echo 'File written!';
    }



backup to variable don't work - El Forum - 05-27-2008

[eluser]Chalda Pnuzig[/eluser]
Uh...
I try it after lunch and it's working... :bug:
Mmm... Bizarre :exclaim:


backup to variable don't work - El Forum - 05-27-2008

[eluser]gtech[/eluser]
cool a self code fixing computer, I want one, where did you get it from?


backup to variable don't work - El Forum - 05-27-2008

[eluser]Chalda Pnuzig[/eluser]
Top secret Big Grin
Thanks anyway!


backup to variable don't work - El Forum - 06-26-2008

[eluser]Chalda Pnuzig[/eluser]
I found the problem: Too low memory! :roll:

I put this in the function and all works great
Code:
ini_set('memory_limit', '64M');