|
| 1 | +--- |
| 2 | +title: "Retrieving databases in rescue mode" |
| 3 | +slug: dedicated-servers-retrieve-database |
| 4 | +excerpt: "Find out how to access and save your databases using rescue mode" |
| 5 | +section: Tutorials |
| 6 | +updated: 2023-04-13 |
| 7 | +--- |
| 8 | + |
| 9 | +**Last updated 13th April 2023** |
| 10 | + |
| 11 | +## Objective |
| 12 | + |
| 13 | +With rescue mode, you can always access your data, even if the server's OS or the software hosted on the server is no longer working. |
| 14 | + |
| 15 | +**This tutorial explains how to access a system in rescue mode and retrieve database files.** |
| 16 | + |
| 17 | +## Requirements |
| 18 | + |
| 19 | +- A [dedicated server](https://www.ovhcloud.com/en-gb/bare-metal/), a [VPS](https://www.ovhcloud.com/en-gb/vps/) or a [Public Cloud Instance](https://www.ovhcloud.com/en-gb/public-cloud/) in your OVHcloud account (excluding Windows systems) |
| 20 | +- Access to the [OVHcloud Control Panel](https://www.ovh.com/auth/?action=gotomanager&from=https://www.ovh.co.uk/&ovhSubsidiary=GB) |
| 21 | + |
| 22 | +> [!warning] |
| 23 | +>OVHcloud is providing you with services for which you are responsible, with regard to their configuration and management. It is therefore your responsibility to ensure that they function correctly. |
| 24 | +> |
| 25 | +>This tutorial is designed to assist you in common tasks as much as possible. Nevertheless, we recommend that you contact a [specialist service provider](https://partner.ovhcloud.com/en-gb/directory/) or reach out to [our community](https://community.ovh.com/en/) if you face difficulties or doubts concerning the administration, usage or implementation of services on a server. |
| 26 | +> |
| 27 | +
|
| 28 | +## Instructions |
| 29 | + |
| 30 | +### Rebooting your server into rescue mode |
| 31 | + |
| 32 | +Follow the respective guide to put your OVHcloud service into rescue mode: |
| 33 | + |
| 34 | +- [Dedicated server](https://docs.ovh.com/gb/en/dedicated/ovh-rescue/) |
| 35 | +- [VPS](https://docs.ovh.com/gb/en/vps/rescue/) |
| 36 | +- [Public Cloud instance](https://docs.ovh.com/gb/en/public-cloud/put_an_instance_in_rescue_mode/) |
| 37 | + |
| 38 | +Follow the instructions in [this section](#pci) for a **VPS** or a **Public Cloud instance**. Skip to the [subsequent section](#dedicated) for a **dedicated server**. |
| 39 | + |
| 40 | +### Accessing your data on a VPS or a Public Cloud instance <a name="pci"></a> |
| 41 | + |
| 42 | +First we need to identify the mount point containing the `/` of our system. |
| 43 | + |
| 44 | +To do this, you can use the commands `lsblk` and `fdisk -l`. |
| 45 | + |
| 46 | +- **lsblk** example output: |
| 47 | + |
| 48 | +```linuxconfig |
| 49 | +NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT |
| 50 | +sda 8:0 0 2.5G 0 disk |
| 51 | +└─sda1 8:1 0 2.5G 0 part / |
| 52 | +sdb 8:16 0 10G 0 disk |
| 53 | +└─sdb1 8:17 0 10G 0 part |
| 54 | +``` |
| 55 | + |
| 56 | +- **fdisk -l** example output: |
| 57 | + |
| 58 | +```unixconfig |
| 59 | +Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors |
| 60 | +Units: sectors of 1 * 512 = 512 bytes |
| 61 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 62 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 63 | +Disklabel type: dos |
| 64 | +Disk identifier: 0x961fcb1c |
| 65 | + |
| 66 | +Device Boot Start End Sectors Size Id Type |
| 67 | +/dev/sdb1 * 2048 20971486 20969439 10G 83 Linux |
| 68 | + |
| 69 | + |
| 70 | +Disk /dev/sda: 2.5 GiB, 2621440000 bytes, 5120000 sectors |
| 71 | +Units: sectors of 1 * 512 = 512 bytes |
| 72 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 73 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 74 | +Disklabel type: dos |
| 75 | +Disk identifier: 0xaf5119d2 |
| 76 | + |
| 77 | +Device Boot Start End Sectors Size Id Type |
| 78 | +/dev/sda1 * 2048 5117951 5115904 2.5G 83 Linux |
| 79 | +``` |
| 80 | + |
| 81 | +> [!primary] |
| 82 | +> |
| 83 | +> The following code sections are for the purpose of illustration only, based on the example output above. You will need to adjust the instructions according to your actual configuration by replacing the values in the commands with your disk and volume identifiers. |
| 84 | +> |
| 85 | +
|
| 86 | +In this example the primary disk (10 GB) is named "sdb". Our data in `/` is therefore located on the partition `/dev/sdb1`. (Whereas "sda" is the rescue mode disk and "sda1" is the primary rescue partition mounted on `/`.) |
| 87 | + |
| 88 | +We mount the system partition in the folder `/mnt` and then verify its content: |
| 89 | + |
| 90 | +```shell-session |
| 91 | +root@rescue:~# mount /dev/sdb1 /mnt |
| 92 | +root@rescue:~# ls /mnt |
| 93 | +bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var |
| 94 | +root@rescue:~# |
| 95 | +``` |
| 96 | + |
| 97 | +In order to launch services on the system from rescue mode, you will need to mount these partitions as well: |
| 98 | + |
| 99 | +```shell-session |
| 100 | +root@rescue:~# mount -o rbind /dev /mnt/dev |
| 101 | +root@rescue:~# mount -t proc proc /mnt/proc |
| 102 | +root@rescue:~# mount -t sysfs sys /mnt/sys |
| 103 | + |
| 104 | +root@rescue:~# mount | grep /mnt |
| 105 | +/dev/sdb1 on /mnt type ext4 (rw,relatime,data=ordered) |
| 106 | +udev on /mnt/dev type devtmpfs (rw,nosuid,relatime,size=990236k,nr_inodes=247559,mode=755) |
| 107 | +devpts on /mnt/dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) |
| 108 | +tmpfs on /mnt/dev/shm type tmpfs (rw,nosuid,nodev) |
| 109 | +hugetlbfs on /mnt/dev/hugepages type hugetlbfs (rw,relatime) |
| 110 | +mqueue on /mnt/dev/mqueue type mqueue (rw,relatime) |
| 111 | +proc on /mnt/proc type proc (rw,relatime) |
| 112 | +sys on /mnt/sys type sysfs (rw,relatime) |
| 113 | +``` |
| 114 | + |
| 115 | +Continue with the [database retrieval section below](#databases). |
| 116 | + |
| 117 | +### Accessing your data on a dedicated server (software RAID configuration) <a name="dedicated"></a> |
| 118 | + |
| 119 | +First we need to identify the mount point containing the `/` of our system. |
| 120 | + |
| 121 | +To do this, you can use the commands `lsblk` and `fdisk -l`. |
| 122 | + |
| 123 | +Example output: |
| 124 | + |
| 125 | +```shell-session |
| 126 | +root@rescue:~# fdisk -l |
| 127 | +``` |
| 128 | +```output |
| 129 | +Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors |
| 130 | +Units: sectors of 1 * 512 = 512 bytes |
| 131 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 132 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 133 | +Disklabel type: gpt |
| 134 | +Disk identifier: 5E158D46-2A45-42C9-8089-697BE070F669 |
| 135 | + |
| 136 | +Device Start End Sectors Size Type |
| 137 | +/dev/sda1 40 2048 2009 1004.5K BIOS boot |
| 138 | +/dev/sda2 4096 1050623 1046528 511M Linux RAID |
| 139 | +/dev/sda3 1050624 42008575 40957952 19.5G Linux RAID |
| 140 | +/dev/sda4 42008576 3905972223 3863963648 1.8T Linux RAID |
| 141 | +/dev/sda5 3905972224 3907018751 1046528 511M Linux swap |
| 142 | + |
| 143 | +Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors |
| 144 | +Units: sectors of 1 * 512 = 512 bytes |
| 145 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 146 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 147 | +Disklabel type: gpt |
| 148 | +Disk identifier: 8039EE93-AB98-4EA1-B316-74EE89EF5EB6 |
| 149 | + |
| 150 | +Device Start End Sectors Size Type |
| 151 | +/dev/sdb1 40 2048 2009 1004.5K BIOS boot |
| 152 | +/dev/sdb2 4096 1050623 1046528 511M Linux RAID |
| 153 | +/dev/sdb3 1050624 42008575 40957952 19.5G Linux RAID |
| 154 | +/dev/sdb4 42008576 3905972223 3863963648 1.8T Linux RAID |
| 155 | +/dev/sdb5 3905972224 3907018751 1046528 511M Linux swap |
| 156 | + |
| 157 | +Disk /dev/md4: 1.8 TiB, 1978349322240 bytes, 3863963520 sectors |
| 158 | +Units: sectors of 1 * 512 = 512 bytes |
| 159 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 160 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 161 | +Disk /dev/md3: 19.5 GiB, 20970405888 bytes, 40957824 sectors |
| 162 | +Units: sectors of 1 * 512 = 512 bytes |
| 163 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 164 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 165 | +Disk /dev/md2: 511 MiB, 535756800 bytes, 1046400 sectors |
| 166 | +Units: sectors of 1 * 512 = 512 bytes |
| 167 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 168 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 169 | +``` |
| 170 | + |
| 171 | +> [!primary] |
| 172 | +> |
| 173 | +> The following code sections are for the purpose of illustration only, based on the example output above. You will need to adjust the instructions according to your actual configuration by replacing the values in the commands with your disk and volume identifiers. |
| 174 | +> |
| 175 | +
|
| 176 | +In this example, our data in `/` is located on the volume `/dev/md3`. |
| 177 | + |
| 178 | +We mount the system partition in the folder `/mnt` and then verify its content: |
| 179 | + |
| 180 | +```shell-session |
| 181 | +root@rescue:~# mount /dev/md3 /mnt |
| 182 | +root@rescue:~# ls /mnt |
| 183 | +bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var |
| 184 | +root@rescue:~# |
| 185 | +``` |
| 186 | + |
| 187 | +In order to launch services on the system from rescue mode, you will need to mount these partitions as well: |
| 188 | + |
| 189 | +```shell-session |
| 190 | +root@rescue:~# mount -o rbind /dev /mnt/dev |
| 191 | +root@rescue:~# mount -t proc proc /mnt/proc |
| 192 | +root@rescue:~# mount -t sysfs sys /mnt/sys |
| 193 | + |
| 194 | +root@rescue:~# mount | grep /mnt |
| 195 | +/dev/md3 on /mnt type ext4 (rw,relatime,data=ordered) |
| 196 | +devtmpfs on /mnt/dev type devtmpfs (rw,relatime,size=16412720k,nr_inodes=4103180,mode=755) |
| 197 | +tmpfs on /mnt/dev/shm type tmpfs (rw,nosuid,nodev) |
| 198 | +devpts on /mnt/dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) |
| 199 | +hugetlbfs on /mnt/dev/hugepages type hugetlbfs (rw,relatime) |
| 200 | +mqueue on /mnt/dev/mqueue type mqueue (rw,relatime) |
| 201 | +proc on /mnt/proc type proc (rw,relatime) |
| 202 | +sys on /mnt/sys type sysfs (rw,relatime) |
| 203 | +``` |
| 204 | + |
| 205 | + |
| 206 | +### Retrieving the databases <a name="databases"></a> |
| 207 | + |
| 208 | +With all the necessary partitions mounted, we need to be able to execute commands on the actual system. You can do this by using the `chroot` command: |
| 209 | + |
| 210 | +```shell-session |
| 211 | +root@rescue:~# chroot /mnt/ |
| 212 | +root@rescue:/# |
| 213 | +``` |
| 214 | +From this point on, all commands that you enter will be applied to your system instead of the temporary rescue mode environment. |
| 215 | + |
| 216 | +We can now start the `mysql` service: |
| 217 | + |
| 218 | +```shell-session |
| 219 | +root@rescue:/# service mysql start |
| 220 | +[ ok ] Starting MariaDB database server: mysqld .. |
| 221 | +root@rescue:/# |
| 222 | +``` |
| 223 | + |
| 224 | +Use the command `mysqldump` to save the database as a file: |
| 225 | + |
| 226 | +```shell-session |
| 227 | +root@rescue:/# mysqldump -u root -p scarif > /home/dump.sql |
| 228 | +Enter password: |
| 229 | +root@rescue:/# |
| 230 | +``` |
| 231 | + |
| 232 | +In this case, the `mysql` user logging in to the database is `root`. The option `-p` allows you to enter the password of `root` and the recovered database is named `scarif`. |
| 233 | + |
| 234 | +The database file is then saved into the `/home` directory under the name `dump.sql`. |
| 235 | + |
| 236 | +You can also back up all databases at once: |
| 237 | + |
| 238 | +```shell-session |
| 239 | +root@rescue:/# mysqldump -u root -p --all-databases > alldb.sql |
| 240 | +Enter password: |
| 241 | +root@rescue:/# |
| 242 | +``` |
| 243 | + |
| 244 | +Listing the contents of `/home` shows both database files created by the previous commands: |
| 245 | + |
| 246 | +```shell-session |
| 247 | +root@rescue:/# ls /home |
| 248 | +alldb.sql dump.sql |
| 249 | +``` |
| 250 | + |
| 251 | +In case of corrupted tables, this command can be used for repair: |
| 252 | + |
| 253 | +```shell-session |
| 254 | +root@rescue:/# mysqlcheck -u root -p Password_Root_MySQL --auto-repair --optimize --all-databases |
| 255 | +``` |
| 256 | + |
| 257 | +From the `/home` folder, you can now send your backup files to a remote server. This example uses the file transfer utility `scp`: |
| 258 | + |
| 259 | +```shell-session |
| 260 | +root@rescue:/# scp -P SSH_Port_Number dump.sql user@IP_address:/home/backup |
| 261 | +``` |
| 262 | + |
| 263 | +## Go further |
| 264 | + |
| 265 | +Join our community of users on <https://community.ovh.com/en/>. |
0 commit comments