Import all mysql datbases for a cpanel user

A long time ago my cpanel server was a mysql slave - I had not "deconfigured" this and tonight upon restart wiped out about 15 databases - mostly mine, plus a couple others. I restored all of them from hour old backups I just made. If I had not just done the backups, I'd lost a day or so..

Again, importance of backups and for "this is just a minor tweak" and "just a quick restart" .. yeah. Backup first.

So, summary was to disable being a slave server, then tar -xzf the backups, re-create the DB's, restore the DB's, restore permissions..

  1. Disable the slave server - do this with mysql stopped.
    # mv master.info mcmaster.infooo
  2. Restart the server and verify the slave status - nothing...
    root@vps2 [//home/unpack/cpmove-user/mysql]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 396
    Server version: 5.0.77-community MySQL Community Edition (GPL)
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql> show slave status\G
    Empty set (0.00 sec)
    
    mysql> quit
    Bye
    

    Thanks to Sun MySQL Forum at the MySQL Forum

  3. Unpack your cpmove backup - using /scripts/pkgacct to backup clients - makes for very easy restore..
  4. cd to their unpack, for example /home/unpack/cpmove-user/mysql and I ran this command to blitz create all the user databases for the user:
    for sql in `ls user*`; do sql=`echo $sql | sed 's/\.sql//'`; echo "create database $sql; >> makedb.sql"; done; mysql < makedb.sql
  5. With the DB's created, import the data:
    for sql in `ls user*`; do sqldb=`echo $sql | sed 's/\.sql//'`; mysql $sqldb < $sql; done
  6. Now the DB's restored, restore the permissions from the file one directory up; mysql.sql
    # mysql < ../mysql.sql 

    This restored about 15 databases very quickly with original permissions, passwords and I was able to get right back to work.