TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-27-2009, 07:15 PM   #1 (permalink)
The Visitor
 
Join Date: Feb 2009
Posts: 4
Thanks: 2
digitak is on a distinguished road
Default How to create back up ?

Hi ,

i want to create script that create backup from my database !

i cannot use PHP my admin or other programs ! i need a little script

can you help me ?

(i cannot speak English very well)
digitak is offline  
Reply With Quote
Old 03-06-2009, 07:01 PM   #2 (permalink)
The Visitor
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Innocentus is on a distinguished road
Default

You could use the following OpenSource-Tools for PHP:
MySQLDumper
phpMyBackupPro

Good luck with your project.
With best regards
Innocentus
Innocentus is offline  
Reply With Quote
Old 03-07-2009, 12:44 PM   #3 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default

Could look something like this?!
!!! THIS CODE IS NOT TESTED !!!
(just written right out of my head - it could be filled with bugs )
PHP Code:
include("db_connection.php");

function 
CreateBackup($db,$table)
{
  
//select database where table is saved
  
$backup "USE $db;\n";
  
$result mysql_query(SHOW CREATE TABLE '$table') or die(mysql_error());
  while(
$row mysql_fetch_array($result))
  {
    for (
$i=1;$i<count($row)-1;$i++)
      {
         
$backup .= $row[$i];
      }
  }
    
$backup .= "\n;";
  
$result mysql_query("SELECT * FROM '$table'") or die (mysql_error());
 WHILE (
$row mysql_fetch_array($result))
  {
    
$backup .= "INSERT INTO $table VALUES(";
    for (
$i=0;$i<count($row);$i++)
      {
        
$cont $row[$i];
        
$backup .= "'$cont',";
      }
      
//we need 2 cut the last "," away
      
$backup substr($backup,0,strlen($backup)-1);
  }
  
$backup .= ");";
  return 
$backup;

Now you just need to write the backup to an file like:
PHP Code:
$content CreateBackup("mydatabase""mytable");
file_put_contents($filename$content); 
Hope this was helpfull

Edit: When anyone finds mistakes/errors - please drop a reply - I'm always willing to learn...
Sakakuchi is offline  
Reply With Quote
The Following 2 Users Say Thank You to Sakakuchi For This Useful Post:
digitak (03-07-2009), iflashlord (05-03-2009)
Old 03-07-2009, 06:18 PM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

If you have shell access to your server, you can issue a mysqldump command
Code:
  mysqldump database -u username -p password -h host > backup.sql
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 03-08-2009, 03:14 AM   #5 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
If you have shell access to your server, you can issue a mysqldump command
Code:
  mysqldump database -u username -p password -h host > backup.sql
Linux only for that. So if you have a ms server that would not work.
CoryMathews is offline  
Reply With Quote
Old 03-08-2009, 11:29 AM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by CoryMathews View Post
Linux only for that. So if you have a ms server that would not work.
That will work fine in Windows environment. I just ran mysqldump -h localhost -u backup -pbackup talkphp > w:/talkphp.sql on my WAMP test server (Virtualised Windows XP with WAMP 2.0f) without any problems.
Salathe is offline  
Reply With Quote
Old 03-08-2009, 10:52 PM   #7 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Should work fine in windows, if you set your paths right.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 03-16-2009, 06:26 PM   #8 (permalink)
The Visitor
 
Join Date: Feb 2009
Posts: 4
Thanks: 2
digitak is on a distinguished road
Default

and how about restore ?
digitak is offline  
Reply With Quote
Old 03-16-2009, 09:53 PM   #9 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

like thus:
Code:
mysql -u user -p password -D database < backup.sql
Not sure if mysqldump dumps the db create statement, so you may need to create that first:
Code:
mysql -u user -p password

mysql> create database databasename;
then you can run source:
Code:
mysql> use databasename;
mysql> source backup.sql;
should do it.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 03-23-2009, 01:08 AM   #10 (permalink)
The Contributor
 
Join Date: Mar 2008
Posts: 62
Thanks: 2
Seraskier is on a distinguished road
Default

The way I do it is backup my data server-side with a command prompt.

Of course, I am running Windows Server with root access, if you do have these requirements I will me more than happy to give you a command prompt in order to do it.

Jordan
Send a message via MSN to Seraskier
Seraskier is offline  
Reply With Quote
Old 05-03-2009, 02:03 PM   #11 (permalink)
The Wanderer
 
iflashlord's Avatar
 
Join Date: Apr 2009
Location: Web
Posts: 5
Thanks: 18
iflashlord is on a distinguished road
Box sample back up database

PHP Code:
//$conn = your connection handle
//$dbase = your database name
// back up save in file on server
// your backup folder must safe by .htaccess (for security)
// 100% tested ok
$Backup ="";
$Tbl mysql_list_tables($dbase ,$conn);
    while(
$R_t mysql_fetch_row($Tbl)){ 
    
        
$Create_tbl mysql_query("SHOW CREATE TABLE `$R_t[0]`");
        while(
$R_c_t mysql_fetch_array($Create_tbl)){
            
$Backup .= " ".$R_c_t['Create Table'];
        }
        
        
$Backup .= ";\r\n";

        
$Q_t mysql_query("SELECT * FROM `$R_t[0]`");

        while(
$R_c_f mysql_fetch_row($Q_t)) {
            
$Backup .= "INSERT INTO `$R_t[0]` VALUES('$R_c_f[0]' ";

            for(
$i=1;$i<sizeof($R_c_f);$i++){
                
$Backup .= ", '$R_c_f[$i]' ";
            }

        
$Backup .= ");\r\n";

        }

        
$Backup .= "\r\n";
    }
$file_name date('myd').time();
$H fopen("./backup/$file_name.sql","w+");

fwrite($H,$Backup);

fclose($H); 
__________________
Create your flash banner online - site powered by php
Send a message via Yahoo to iflashlord Send a message via Skype™ to iflashlord
iflashlord is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 22 06-23-2009 11:36 PM
I'm back! Rendair The Lounge 7 12-15-2008 02:08 AM
Create your own advanced WYSIWYG editor almsamim Javascript, AJAX, E4X 8 10-23-2008 06:41 PM
Back to Basics: File uploading delayedinsanity Absolute Beginners 12 10-03-2008 10:14 AM
Need your feedback Tanax Absolute Beginners 29 10-11-2007 04:50 PM


All times are GMT. The time now is 04:16 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design