Backup And Restore class Mysql Database Using PHP Script

back up restore with php class
Back up And Restore With PHP

Today I’m going to share with you a very useful script that can create backup of your mysql database and restore it any time you wanted, just as one click recovery of mysql using a php script .

I need to make it because one of my client need this feature in his admin panel So here are the steps to use it.

it take just 5 second for backup and 5 second to restore

Here are some steps you need to take

1. Create an object of class backup_restore

[php]$obj = new backup_restore(‘hostname’,’db_name’,’user’,’paswd’,’*’);[/php]

2. If you want to create backup of your mysql database ,call backup function

[php]$message = $obj–>backup();[/php]

3. If you want to restore your database,call restore function.

[php]$message = $obj–>restore();[/php]

4. That’s it rest of thing ,code will tell you.

Don’t forget to change argument

‘hostname‘ change to ‘your hostname‘.

‘db_name’ change to your database name.

‘username’ change to’ ‘ MySQL username‘.

‘password‘ change to ‘MySQL password‘.

‘path’ is an option argument if you want to store sql dump in a secure location otherwise sql dump will be generated in current directory [NEW ADDED]

‘*’ Change to table name whose backup you want. [ARGUMENT OMITTED]

New Added Feature

  1. You can store the sql dump at you secret location in the server.
  2. Added new formatting function

    private function remove_accents
    private function sql_backquote
    private function sql_addslashes

  3. generate pure sql dump. you can download dump file and import it by phpmyadmin.

Instruction and feature:

1. The file this script generate is pure sql file .so you can import it by phpmyadmin.

2. Can handle large db back and restore.

3. Support cms backup. wordpress, joomla, drupal and all others.

4. It does not use mysqldump command ,As many server do not enable shell_exec.

5. It gives 100% sql file.

6. 5-sec for backup and 5-sec for restoration

7.Open Source : Download –> Use –> Improve –> Share . No Warranty.:)

Download script below

zip contain class and example file

Download it free from github

Download

Thank you

  • Kevin Rauer

    Thx..

  • Kevin Rauer

    Thx..

  • buffernow

     Sorry Bro .

    Now its working 🙂

  • buffernow

     Sorry Bro .

    Now its working 🙂

  • jay

    Hey Bro …I don’t see the link to download

    • Rohit

      Please Like , Share Or Tweet
      After That if It still disappear
      then reload the page you will definitely get link.

  • Bhatnagar Shikhar

    Sorry Rohit, I am unable to see the download link.

    • buffernow

      Hello Bhatnagar
      i just Mailed you the Link

  • Bhatnagar Shikhar

    Sorry Rohit, I am unable to see the download link.

    • buffernow

      Hello Bhatnagar
      i just Mailed you the Link

  • Sharanyasaran

    Download link is not available

  • Sharanyasaran

    Download link is not available

  • Jitu Culdude

    I have download zip file, but what is password og zip file.

    • buffernow

      hi jitu
      password is : buffernow.com

  • Jitu Culdude

    I have download zip file, but what is password og zip file.

    • buffernow

      hi jitu
      password is : buffernow.com

  • vij

    hi ROHIT I AM getting this error Parse error: parse error, expecting `T_OLD_FUNCTION’ or `T_FUNCTION’ or `T_VAR’ or `’}” in e:program fileseasyphp1-8wwwtestdownloaddb_testbackup_restore.class.php on line 19

    • buffernow

      hey vijay
      i think you are using older version of php may be version 4
      __construct declaration feature is not available in older versions.
      so upgrade to PHP 5.

  • vij

    hi ROHIT I AM getting this error Parse error: parse error, expecting `T_OLD_FUNCTION’ or `T_FUNCTION’ or `T_VAR’ or `’}” in e:program fileseasyphp1-8wwwtestdownloaddb_testbackup_restore.class.php on line 19

    • buffernow

      hey vijay
      i think you are using older version of php may be version 4
      __construct declaration feature is not available in older versions.
      so upgrade to PHP 5.

  • suthan

    does this supports the Referencing?

  • suthan

    does this supports the Referencing?

  • pH

    Why put a password for your Zip archive.
    What is the purpose?

  • pH

    Why put a password for your Zip archive.
    What is the purpose?

  • Tani

    haven’t tested d code. but just want to commend your effort…..

  • Tani

    haven’t tested d code. but just want to commend your effort…..

  • Tani

    am getting this error…pls what can be the problem. tnk “Warning: mysql_connect() [function.mysql-connect]: Access denied for
    user ‘ODBC’@’localhost’ (using password: NO) in C:wampwwwUnnamed Site
    1backup_restore.class.php on line 20
    Access denied for user
    ‘ODBC’@’localhost’ (using password: NO)”

    • buffernow

      Hello Tani
      Sorry for this error
      i already told it will works 100% on live server.
      please update your php version if using old version
      or try to replace
      __construct to backup_restore in backup_restore.class.php

      and try again .

  • Tani

    am getting this error…pls what can be the problem. tnk “Warning: mysql_connect() [function.mysql-connect]: Access denied for
    user ‘ODBC’@’localhost’ (using password: NO) in C:wampwwwUnnamed Site
    1backup_restore.class.php on line 20
    Access denied for user
    ‘ODBC’@’localhost’ (using password: NO)”

    • buffernow

      Hello Tani
      Sorry for this error
      i already told it will works 100% on live server.
      please update your php version if using old version
      or try to replace
      __construct to backup_restore in backup_restore.class.php

      and try again .

  • Jack Soni

    if we take backup of any database and then create any new table, and then try to restore old database, then the new created table is not deleting , its still there … pls soul this

  • Jack Soni

    if we take backup of any database and then create any new table, and then try to restore old database, then the new created table is not deleting , its still there … pls soul this

  • Vic2r3

    Thanks bro! It works!

  • Vic2r3

    Thanks bro! It works!

  • Rajeev

    Thanks bro! backup script is working well bur Restore script is not working.

    It messages “Sucessfullly restored

    ” but database still unchanged.

    Please resolve this problem. thank you

  • Rajeev

    Thanks bro! backup script is working well bur Restore script is not working.

    It messages “Sucessfullly restored

    ” but database still unchanged.

    Please resolve this problem. thank you

  • Vinod

    http://adf.ly url not working

    Please enable Cookies in your browser. error occur

    • buffernow

      please press skip ad button after 5 second

  • Vinod

    http://adf.ly url not working

    Please enable Cookies in your browser. error occur

    • buffernow

      please press skip ad button after 5 second

  • ck

    how can i take backup to compressed form

    • buffernow

      can you please elaborate ..

  • ck

    how can i take backup to compressed form

    • buffernow

      can you please elaborate ..

  • Niharika

    How will I come to know where backup file is saved?????????
    Shall i give some path for storing the backup file?? if yes then how??

    • buffernow

      well it is in the current directory
      but it will be not pure sql dump
      so dont try to import it from phpmyadmin
      file name will be buffernow.com.phoenix

  • Niharika

    How will I come to know where backup file is saved?????????
    Shall i give some path for storing the backup file?? if yes then how??

    • buffernow

      well it is in the current directory
      but it will be not pure sql dump
      so dont try to import it from phpmyadmin
      file name will be buffernow.com.phoenix

  • haiku

    Thanks a lot. I’ve developed your work so that there could be different restore points per day ‘coz I need back-up everyday for security purposes, 😉

    • buffernow

      Good to hear from you.. 😉

  • haiku

    Thanks a lot. I’ve developed your work so that there could be different restore points per day ‘coz I need back-up everyday for security purposes, 😉

    • buffernow

      Good to hear from you.. 😉

  • sudhakar

    zip file not working

    • buffernow

      please enter zip password
      or just wait new version is comming in one or two days

  • sudhakar

    zip file not working

    • buffernow

      please enter zip password
      or just wait new version is comming in one or two days

  • Has an issue with PHP 5.4.13 giving the error below…

    Strict Standards: Non-static method backup_restore::untrailingslashit() should not be called statically in backup_restore.class.php on line 140

    • buffernow

      please change
      private function untrailingslashit
      to
      private static function untrailingslashit

  • Esch

    Has an issue with PHP 5.4.13 giving the error below…

    Strict Standards: Non-static method backup_restore::untrailingslashit() should not be called statically in backup_restore.class.php on line 140

    • buffernow

      please change
      private function untrailingslashit
      to
      private static function untrailingslashit

  • Muthu

    hi can u upload a code and tell me some other link to see
    “Incremental backup in PHP” i am searching a lot but i did not got any thing.. Ple write a blog for that

    • buffernow

      you can use the same script with cron job for incremental backup

  • Muthu

    hi can u upload a code and tell me some other link to see
    “Incremental backup in PHP” i am searching a lot but i did not got any thing.. Ple write a blog for that

    • buffernow

      you can use the same script with cron job for incremental backup