{"id":164,"date":"2015-05-18T16:54:17","date_gmt":"2015-05-18T16:54:17","guid":{"rendered":"https:\/\/www.prolimehost.com\/blogs\/?p=164"},"modified":"2022-06-09T21:39:39","modified_gmt":"2022-06-09T21:39:39","slug":"how-to-backup-mysql-databases-in-rescue-mode","status":"publish","type":"post","link":"https:\/\/www.prolimehost.com\/blogs\/how-to-backup-mysql-databases-in-rescue-mode\/","title":{"rendered":"How to Backup MySQL Databases in Rescue mode."},"content":{"rendered":"

Nothing is certain and permanent in this world and so is true for the technology. Every single object has a\u00a0lifetime<\/u> and it is vulnerable to fail several times while it exists. No matter how strongly built\u00a0server<\/a> you\u00a0have, the failures will\u00a0knock\u00a0your door. Today we will focus the uncertain part of the online world, and we will discuss the database recovery method during a server crash.<\/p>\n

\"How<\/a>The importance of database in business<\/u><\/strong><\/p>\n

The online databases are to store the important information in the form of bits. The information is always vital to the businesses. The data stored in the databases are further used to sort,\u00a0filter\u00a0and display information to run the business in\u00a0appropriate\u00a0manners.<\/p>\n

What if the data disk fails, what if the hard disk is about to die. Simple, you can go out of the business if there is no recovery or backups of your important business data. Data loss is no less than the death of the business.<\/p>\n

What is\u00a0Mysq<\/u><\/strong>l<\/strong><\/p>\n

Mysql<\/a>\u00a0is widely used database solution for the businesses. It\u00a0is an open source relational<\/u>\u00a0database management system that uses SQL (structured query language) architecture.\u00a0Mysql\u00a0is\u00a0well-known\u00a0for its stability, speed and flexibility.<\/p>\n

Rescue mode<\/u><\/strong><\/p>\n

In normal operations the operating system loads from the hard disk residing in the serve. However, if something goes wrong servers can not load the OS properly . They may report the error or completely go broke. At times if you fail to fix the problem, it may further harm your data.<\/p>\n

Rescue mode is\u00a0to built\u00a0fix the technology problems in the server machines. The OS\u00a0can be\u00a0loaded from a tiny disk,\u00a0CD<\/u>\u00a0or with\u00a0the minimal OS environment<\/u>. The rescue mode is just like the\u00a0operating <\/u>theater to fix the complex problems. Let’s say you are getting the disk failure warnings and it can die\u00a0anytime<\/u>. Rescue mode is the safest option to backup your data and replace the faulty disk.<\/p>\n

How to boot into the Rescue mode<\/u><\/strong><\/p>\n

There are two common methods to boot into rescue mode:<\/p>\n

1-\u00a0Cd Rom<\/p>\n

2-\u00a0USB Flash<\/p>\n

attach the cd rom or flash device to the server having the same OS image on it. Boot the server from cd rom or\u00a0usb\u00a0flash and not the hard disk. You\u00a0can setup\u00a0the first boot device in the bios of the server or you can select at the start of the server by pressing the function keys (F1,\u00a0F8) depending upon the model of your server machine.<\/p>\n

After booting the machine you will\u00a0land<\/u>\u00a0to the command prompt.
\nTo go into the rescue mode write the below command on the prompt:
\nLinux<\/u>\u00a0rescue now the system will ask you\u00a0a few basic questions<\/u>\u00a0to\u00a0prepare the environment for you. The simple questions would be like what language you want to use, where the OS image located (CD,<\/u>\u00a0USB<\/u>,\u00a0nfs, https,\u00a0FTP<\/u>) and which keyboard to load. Now the rescue mode will find the installation partition\u00a0on<\/u>\u00a0your server to mount it under\u00a0the\u00a0directory \/mnt\/sysimage.<\/p>\n

The rescue mode further asks you to load your installation disk as read-only version or write version so that you can make the necessary changes to fix the problem.<\/p>\n

Mount the File System<\/u><\/strong><\/p>\n

Here you go, you have landed to the rescue mode. Now\u00a0to reach\u00a0our hard disk partition we will write the below command at the prompt.<\/p>\n

sh-2.05b# chroot \/mnt\/sysimage<\/em><\/strong><\/p>\n

now you\u00a0can access\u00a0the disk partitions for the necessary changes. Now we will list the directory structure using the \u201cls\u201d command.<\/p>\n

# ls<\/em><\/strong><\/p>\n

we can backup\u00a0our important files , fix the file system, change the configurations to fix the\u00a0root cause of the server crash. Since our focus is the database backup and recovery method ,we will now discuss the mysql\u00a0database backup and recovery strategy.<\/p>\n

Backup\u00a0mysql\u00a0in rescue mode<\/u><\/strong><\/a><\/p>\n

The system is in rescue mode with\u00a0mysql\u00a0service turned off. We need to take the file system backup by locating the\u00a0mysql\u00a0data directory and archive the\u00a0mysql\u00a0files.<\/p>\n

Finding the data directory<\/u><\/strong><\/p>\n

it is important to find\u00a0the location of\u00a0the database files. You can find the path by looking into the\u00a0mysql configuration file named as my.cnf. The my.cnf file is usually\u00a0located in ”\u00a0\/etc” directory you can find theconf\u00a0file by using the below command.<\/p>\n

locate\u00a0my.cnf<\/em><\/strong><\/p>\n

Execute the below command to check\u00a0the location of\u00a0the mysql\u00a0data directory within the my.cnf file.<\/p>\n

grep\u00a0datadir\u00a0etc\/mysql\/my.cnf<\/em><\/strong>\u00a0<\/em><\/strong>(assuming that my.cnf is in the etc\/mysql\/ directory)<\/p>\n

usually the directory path is:<\/p>\n

\/var\/lib\/mysql<\/p>\n

Make the files archive<\/u><\/strong><\/p>\n

Now we will execute the below command to make the mysql directory archive with database files in it.<\/p>\n

tar <\/strong>–<\/strong>czvf mysql-file-backup<\/strong>.<\/strong>tar<\/strong>.<\/strong>gz <\/strong>var<\/strong>\/<\/strong>lib<\/strong>\/<\/strong>mysql<\/strong><\/p>\n

explanation\u00a0of the command:<\/p>\n

tar – is the command line archive tool<\/p>\n

c – create<\/p>\n

v – display the results :\u00a0Verbose<\/p>\n

z – pack the files at .gz<\/p>\n

f \u2013 archive file name<\/p>\n

it will take some time depending upon the size of your database to archive the data.<\/p>\n

At the end you will get the single backup file as\u00a0mysql-file-backup<\/strong>.<\/strong>tar<\/strong>.<\/strong>gz\u00a0<\/strong>in the current working directory.<\/p>\n

The file backup of your database is complete, you can restore it to the remote server or the same server unzipping\u00a0the archive.<\/p>\n

You can\u00a0unzip\u00a0the gz archive with below command.<\/p>\n

tar\u00a0-zxvf\u00a0mysql-file-backup.tar.gz<\/em><\/strong><\/p>\n

You\u00a0can back up\u00a0the other directories and important files using the same method.<\/p>\n","protected":false},"excerpt":{"rendered":"Nothing is certain and permanent in this world and so is true for the technology. Every single object…","protected":false},"author":2,"featured_media":166,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":"","footnotes":""},"categories":[1,10],"tags":[],"class_list":{"0":"post-164","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-geneal","8":"category-tutorials-tips","9":"cs-entry"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/posts\/164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":0,"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/media\/166"}],"wp:attachment":[{"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.prolimehost.com\/blogs\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}