GIT – As those who own dedicated servers know that they have the possibility to enter in their crashed servers using rescue console they have to know that lots of things can be done on including the recover of databases and much more. I will explain how a database can be recovered using resque console.

When rescue console is started you are asked to choose an operating system to work with. Usually there are 2 or more OS to chose but one of the is the OS that the crashed server used to run. Check that and start console.

Once the rescue console is started just log in with user and given on control panel , pay attention since this is not your password but is just a random password set by console.

After the console has been started there is 1 thing people should know , rescue console is working on RAM and many hosters are limiting the console to work with 1GB or ram and after start is already consuming 8-900M so you can’t do much with the rest of them.

Let’s see how a mysql database can be started in rescue console.

First of all we have to mount old system to work with.

root@rescue~# mkdir /tmp/oldsystem
root@rescue~# mount /dev/sda1 /tmp/oldsystem/
root@rescue~#

So we have mounted old system
A new mysql server must be installed on RAM
Debian/Ubuntu

root@rescue~# apt-get  mysql-server

CentOS

root@rescue~#  -y install mysql-server

You will be asked to set root password but you can set any since there is no need of it.
After the mysql server is installed a file must be edited

/etc/mysql/my.cnf

And change

datadir = /var/lib/mysql

to

datadir = /tmp/oldsystem/var/lib/mysql

Now just restart mySQL server , login with your OLD user and password.

root@rescue~# /etc/init.d/mysql restart
Stopping MySQL database server: mysqld.
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..
root@rescue~#mysql -u user -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 32310
Server version: 5.1.63-0+squeeze1 (Debian)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test_database      |
+--------------------+
2 rows in set (0.00 sec)

mysql> use test_database;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>show tables;
+-----------------------------+
| Tables_in_test_database     |
+-----------------------------+
| table_1                     |
| table_2                     |
| table_3                     |
+-----------------------------+
3 rows in set (0.00 sec)

mysql>quit
Bye
root@rescue~#

Now let’s export database
We have database *test_database*

root@rescue~# mysqldump -uUSER -pPASSWORD -h localhost test_database > test_database_export.sql
root@rescue~#

Now let’s put it back on remote server (if exists) directly from rescue console
Ensure that on remote server a new database is created else :
login to mySQL with you info

mysql> create database test_database;

Ensure that on new server port 3306 is opened for public else :

root@remoteserver~#  -I INPUT -p tcp --dport 3306 -j ACCEPT

You can close this port later
Ensure that database user on remote server can login from external hosts
When all these have been done import database

root@rescue~# mysql -uUSER -p -h REMOTE_SERVER test_database < test_database_export.sql
Enter password:
root@rescue~#

That’s all

Print Friendly

Comments

comments

Bài viết liên quan