Re: how do I compress large files? was Re: can this backup script work?



Lawrence Krubner wrote:
Lawrence Krubner wrote:

Being sane, rational people, we of course want to create a backup of our database everyday. Since the mysqldump produces a file that is over a gig in size, we want to compress the file. I'm worried that I may have just written the worst backup script ever. I glanced at www.php.net and saw that I could use gzcompress() for compression. However, the function takes a string as an argument. So I'm using file_get_contents to load the backup database info as a string.

Is PHP actually using a gig of memory to hold this giant string?

Is there a smarter way to do this?

Cron script, called once a day:


#!/usr/bin/php
<?php

$date = date("Y F d H i s");
$date = str_replace(" ", "_", $date);
$filename = "alb_" . $date . ".sql";
$filepath = "/mnt/krypton_data_backup/$filename";
echo system("mysqldump -uxxxxx -pxxxxx alb > $filepath");
$dataAsString = file_get_contents($filepath);
$compressed = gzcompress($dataAsString);
file_put_contents($filepath, $compressed);

?>


The path is "/mnt/krypton_data_backup/" because it is actually being saved to another server, linked to the current server using NFS.

okay this solved problems with the memory:

system("gzip $filepath");

But now chmod won't work. Is this because the PHP is saving the file to another server? Perhaps PHP doesn't have permission to chmod on another server, even if that server has a directory mounted via NFS? I only gave read/write permissions, on the NFS export, perhaps I can could fix the problem by changing this?

The next problem I face is being able to delete older backups. For that, I'd like to chmod the backups 0777, so PHP will be able to delete the files later on.




.



Relevant Pages

  • Gzip component, module, or code?
    ... create truly Apache/PHP 4.x compatible gzip'ed text. ... compress text on my local PC using Delphi 6.x. ... The text will be fetched by a PHP ... program running on the server and uncompressed using the relevant PHP ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: rsync and compressed data.
    ... situation so you may have any suggestions, I use rsync to backup my mail ... server data, And I have a limited space on the backup server. ... You could compress the mail server data to temporary fileon the mail ...
    (alt.os.linux)
  • Re: backup the entire server
    ... > | a script that backs up the entire server to hard drive. ... I need to compress the files ... We use it to backup both Linux ...
    (Fedora)
  • Re: cpio files to remote server
    ... | Hey Everybody, ... | on the same LAN, but the backup server is going to be moved offsite, ... which can compress if you tell it do do so. ...
    (comp.unix.sco.misc)
  • Re: cpio files to remote server
    ... "John DuBois" wrote in message ... >>on the same LAN, but the backup server is going to be moved offsite, ... >>gzip into the command to compress the data before sending it to the ...
    (comp.unix.sco.misc)