2 replies
Hi,

I am trying to create a small script that will backup a MySQL database. I can successfully create the backup file at the root of my Website using:

Code:
<?php

  // This PHP Script will backup the content of a MySQL database in a GZip file

  // Enter Database access details
  $host= 'HOSTNAME';
  $user= 'USERNAME';
  $pass= 'PASSWRD';
  $db=   'DBNAME';
  
  // Instructing the system to zip and store the database
  system(sprintf(

    'mysqldump --opt -h%s -u%s -p%s %s | gzip > $s/dumpDB.sql.gz',
    $host,
    $user,
    $pass,
    $db,
    getenv('DOCUMENT_ROOT')
  ));
  echo '+DONE';
?>
However, I would like the script to save the file to a FTP server elsewhere. I have added the variables for the FTP server, like so:

Code:
<?php

  // This PHP Script will backup the content of a MySQL database in a GZip file

  // Enter Database access details
  $host= 'HOSTNAME';
  $user= 'USERNAME';
  $pass= 'PASSWRD';
  $db=   'DBNAME';
  
  // FTP Server access details
  $ftphost= 'FTPHOSTHAME';
  $ftpdir= 'FTPDIR';
  $ftpuser= 'FTPUSERNAME';
  $ftppass= 'FTPPASSWRD';

  // Instructing the system to zip and store the database
  system(sprintf(

    'mysqldump --opt -h%s -u%s -p%s %s | gzip > $s/dumpDB.sql.gz',
    $host,
    $user,
    $pass,
    $db,
    getenv('DOCUMENT_ROOT')
  ));
  echo '+DONE';
?>
But what do I need to add to mysqldump for the file to be sent to the FTP server?

I've been searching for hours and can't find a solution that works. Any help will be much appreciated.

Many thanks,

T
#back #file #mysql
  • Profile picture of the author mywebwork
    Could you just do the dump to the local directory as you're currently doing and then run another PHP function to FTP it to the remote server? Not sure if its useful to you but there is a good post here about using PHP to send files via FTP.

    PHP's FTP functions*tutorial

    Hope that helps.

    Bill
    {{ DiscussionBoard.errors[575583].message }}
  • Profile picture of the author Amsterdam
    Yes, I think that will be the way to go. Thanks for the link

    T
    {{ DiscussionBoard.errors[575893].message }}

Trending Topics