The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

restore mysql only

Discussion in 'General Discussion' started by jester.ro, Sep 16, 2005.

  1. jester.ro

    jester.ro Well-Known Member
    PartnerNOC

    Joined:
    Feb 6, 2004
    Messages:
    304
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Bucharest, Romania
    cPanel Access Level:
    DataCenter Provider
    few days ago, one of my servers had a hdd crash.
    i had only the /var partition on that drrive, so the most important thing was restoring mysql

    i tried to look at what cpanel is providing for restoring backups, but it's a binary file, so i had no way to modify it to only restore mysql.

    so...what i did:

    first mysql_init_db (that re-created the test and mysql db's)
    changed the mysql root password from whm.

    and then i made a small script to restore only mysql.
    as you know, each backup tar.gz contains 2 things regarding mysql.

    first, there's a mysql.sql that contains the username and passwords of the users.
    second, there';s a mysql folder, that contains the dumps from all databases of the customer.


    this is the script i used, run it in the backup folder.
    change PASSWORD with your mysql root password.

    Code:
    for f in *.tar.gz ; do
    
    rm -r /tmp/sql/*
    g=`echo $f|cut -d. -f1`
    tar -C /tmp/sql/ -xzvf $f $g/mysql/ $g/mysql.sql
    for h in /tmp/sql/$g/mysql/*; do
            i=`basename $h`
            j=`echo $i|cut -d. -f1`
            echo CREATE DATABASE $j
            mysql -pPASSWORD -e "create database if not exists $j"
    done
    
    echo MERGING /tmp/sql/$g/mysql.sql
    mysql -pPASSWORD mysql </tmp/sql/$g/mysql.sql
    
    for h in /tmp/sql/$g/mysql/*; do
            i=`basename $h`
            j=`echo $i|cut -d. -f1`
            echo MERGING $h INTO $j
            mysql -pPASSWORD $j< $h
    done
    
    done
    

    probably someone with more time could make it a bit more portable.
    it served the purpose, it restored only the mysql part from the backup. i hope it will help someone.
     
  2. forlinuxsupport

    forlinuxsupport Well-Known Member
    PartnerNOC

    Joined:
    Dec 22, 2004
    Messages:
    386
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    hey

    great post. ;)

    Cpanel backup and restore seems to miss the mysql stuff. :mad:

    E.g. if you have a database NOT created in cpanel then cpanel WONT back it up or restore it.

    There is an option to backup the Entire mysql dir which is good. But cpanel DOESNT restore it :(

    I want to know how to add an existing database to cpanel so it will get backed up. It seems silly that cpanel misses this out !!

    If anyone else can shed some light... pleez do :)

    Cheers
    Andy
     
Loading...

Share This Page