Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 03-04-2009, 07:20 AM   #1
Advanced Warrior
 
Amsterdam's Avatar
 
Join Date: Jun 2005
Location: Wirral, UK
Posts: 691
Thanks: 2
Thanked 4 Times in 3 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile  View Member's YouTube Profile
Default Back up MySQL file?

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

Web Design Wirral - Web Design, Hosting & Development from TDL Web Developments
Amsterdam is offline   Reply With Quote
Old 03-05-2009, 12:52 AM   #2
Senior Warrior Member
War Room Member
 
mywebwork's Avatar
 
Join Date: Sep 2008
Location: Honolulu, Hawaii, USA & Montreal Canada
Posts: 2,218
Blog Entries: 1
Thanks: 759
Thanked 724 Times in 505 Posts
Default Re: Back up MySQL file?

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
mywebwork is offline   Reply With Quote
Old 03-05-2009, 04:21 AM   #3
Advanced Warrior
 
Amsterdam's Avatar
 
Join Date: Jun 2005
Location: Wirral, UK
Posts: 691
Thanks: 2
Thanked 4 Times in 3 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile  View Member's YouTube Profile
Default Re: Back up MySQL file?

Yes, I think that will be the way to go. Thanks for the link

T

Web Design Wirral - Web Design, Hosting & Development from TDL Web Developments
Amsterdam is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
back, file, mysql

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 09:33 PM.