How do I gzip a mysqldump sql backup file?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • damezumari

    How do I gzip a mysqldump sql backup file?

    This is how I do a backup of a mysql database with php:

    $backupFile = '/home/owner/dbbackup/'.$dbname .'-' .$filename.
    '.sql';
    $command = "mysqldump --opt -h $dbhost -u $dbuser -p$dbpass $dbname>
    $backupFile";
    $dummy = system($command , $retval);

    It works OK and creates a .sql file, but how do I compress the file to
    a gzip file?

    Kind regards,

    Jan Nordgreen


  • Michael Fesser

    #2
    Re: How do I gzip a mysqldump sql backup file?

    ..oO(damezumari )
    >This is how I do a backup of a mysql database with php:
    >
    $backupFile = '/home/owner/dbbackup/'.$dbname .'-' .$filename.
    >'.sql';
    $command = "mysqldump --opt -h $dbhost -u $dbuser -p$dbpass $dbname>
    >$backupFile" ;
    $dummy = system($command , $retval);
    >
    >It works OK and creates a .sql file, but how do I compress the file to
    >a gzip file?
    Use the command line. Pass the result of mysqldump to gzip and then
    redirect it to a file:

    $command = "mysqldump --opt -h$dbhost
    -u$dbuser -p$dbpass $dbname | gzip $backupFile.gz" ;

    Micha

    Comment

    • Peter H. Coffin

      #3
      Re: How do I gzip a mysqldump sql backup file?

      On Thu, 24 Apr 2008 19:09:13 -0700 (PDT), damezumari wrote:
      This is how I do a backup of a mysql database with php:
      >
      $backupFile = '/home/owner/dbbackup/'.$dbname .'-' .$filename.
      '.sql';
      $command = "mysqldump --opt -h $dbhost -u $dbuser -p$dbpass $dbname>
      $backupFile";
      $dummy = system($command , $retval);
      >
      It works OK and creates a .sql file, but how do I compress the file to
      a gzip file?
      $command = "gzip $backupFile";
      $dummy = system($command , $retval);

      maybe? I can't imagine that you haven't thought of this, so there must
      be *something* wrong with it.

      --
      31. All naive, busty tavern wenches in my realm will be replaced with surly,
      world-weary waitresses who will provide no unexpected reinforcement and/or
      romantic subplot for the hero or his sidekick.
      --Peter Anspach's list of things to do as an Evil Overlord

      Comment

      • damezumari

        #4
        Re: How do I gzip a mysqldump sql backup file?

        Thank you for your answers!

        Kind regards,

        Jan Nordgreen

        Comment

        Working...