Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Database auto backup

Discussion in 'Database Discussion' started by faizrashid, Mar 27, 2014.

  1. faizrashid

    faizrashid Registered

    Joined:
    Mar 27, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi guys, I'm kinda a newbie here in database.
    Anyone here know the coding to make the auto backup database for a php system?
     
  2. LostNerd

    LostNerd Well-Known Member

    Joined:
    Mar 12, 2014
    Messages:
    258
    Likes Received:
    11
    Trophy Points:
    18
    Location:
    Hastings, East Sussex, UK
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    Just to clarify... Are you attempting to backup a single database or every database on your cPanel/WHM server?

    If you are trying to backup your databases in one account only, the Backup Manager is very helpful.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. faizrashid

    faizrashid Registered

    Joined:
    Mar 27, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I wanted to backup a single database only. Can it be done by using a .php code?
     
  4. LostNerd

    LostNerd Well-Known Member

    Joined:
    Mar 12, 2014
    Messages:
    258
    Likes Received:
    11
    Trophy Points:
    18
    Location:
    Hastings, East Sussex, UK
    cPanel Access Level:
    Root Administrator
    Twitter:
    Code:
    <?php
    $dbhost = 'localhost:3036';
    $dbuser = 'root';
    $dbpass = 'rootpassword';
    
    $backup_file = $dbname . date("Y-m-d-H-i-s") . '.gz';
    $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass ".
               "test_db | gzip > $backup_file";
    
    system($command);
    ?>
    Something like this may work. Change it to your needs. However, I personally prefer using a program such as Navicat to perform backups for me.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,129
    Likes Received:
    1,932
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello :)

    Note that you can also backup a database through the cPanel interface or using "mysqldump" from the command line.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice