user2467929
user2467929

Reputation:

Where are the MySQL databases stored (cPanel/WHM)?

I have cPanel & WHM installed on my server.

Is it safe to backup this directory (if I only care about backing up the MySQL databases): "/var/lib/mysql/"

I don't care about the other MySQL databases that cPanel provide by default. I only care about the MySQL databases that other cPanel users have created and currently own.

I know I could just back it up with other ways, but let's say due to a hard disk drive failure, I cannot access cPanel and WHM.

The only access to the server I have is via SSH (and SFTP).

Okay, so would it be my best interest to just download everything in "/var/lib/mysql/"?

If not, what other files would I need to back up? Let me guess, just the "/home/" directory?

I hope my description of my issue was made clear and was descriptive.

Basically, I need to transfer the MySQL databases from one HDD to another, but the HDD with the MySQL databases has lots of errors, is corrupted (I cannot access cPanel/WHM) and my server provider tells me my HDD has failed.

In advance, I would like to thank you very much for your help. Even if you did not help, thank you very much for taking your time reading this. It is much appreciated.

Upvotes: 1

Views: 12253

Answers (1)

consuela
consuela

Reputation: 1703

You mentioned that you can access the server via SSH but have no access to WHM or cPanel. I guess you have no access to phpMyAdmin(?). I am also guessing that the second HDD is on another server.

Instead of backing up a directory, I would suggest you connect via SSH to your server, then make remote backups with mysqldump, download them locally with SFTP and then import the database backups to the other HDD/server.

  1. Connect to your server with SSH

    ssh [email protected]
    

    Where xxx.xxx.xxx.xx1 is the IP address of your first server. Give your password when prompted.

  2. Use mysqldump to make a backup of your database(s) to the server.

    mysqldump -uroot -p mydatabase1 > mydatabase1.sql
    mysqldump -uroot -p mydatabase2 > mydatabase2.sql
    ...
    

    Type your MySQL password when prompted and then the sql files (backups of your databases) will be created. I would suggest you don't make the backups on a publicly available directory of your server.

  3. If you are on a Unix system you can type "ll" or "ls" to see that the .sql files have been created. Make a note of the directory in your server where the backups are located.

  4. Terminate the SSH session:

    exit
    
  5. Then use your favourite SFTP program to connect to your server or use terminal like this:

    sftp [email protected]
    

    Type your password when prompted.

  6. Navigate to the directory where the backups are located and download them by using the "GET" command:

    get mydatabase1.sql
    

    Your mydatabase1.sql backup file will be downloaded to your local machine.

  7. Don't forget to close the session:

    exit
    
  8. Now SFTP to your other HDD to upload the database backups:

    sftp [email protected]
    

    where xxx.xxx.xxx.xx2 is the IP address of your other machine. Give password when prompted.

  9. Don't forget to close the SFTP session:

    exit
    
  10. Now that you have uploaded the databases, you can connect again with SSH to the other HDD/server just like before:

    ssh [email protected]

  11. Once connected, create the new database:

    mysql -uroot -e "create database mydatabase1"
    
  12. Import the backup to the database:

    mysql -uroot -p mydatabase1 < mydatabase1.sql
    

Now the database backup should be imported in the new server/hdd. I hope this helps.

Upvotes: 1

Related Questions