Backup of MySQL to a USB Pendrive

Backup de MySQL para o USB pendrive
MySQL

Last Friday, I received a call from a former student, who was in authentic fetal despair. I tried to calm him down, already imagining that MySQL had crashed, wouldn’t start anymore, and that the backup was completely lost. To my surprise, he said: “Master, my USB is burned, and I use it to make backups via USB HDD.” I thought to myself: burned? All burned?

After much conversation, to understand what a “burned” USB meant from the perspective of my eager padawan, I discovered that there was no reason for panic or despair. The OS just didn’t mount the external HDD.

Since this has happened to me a few times, it’s only fair to report the heroic feat of mounting a simple device! Of course, I don’t have an external USB HDD here with me, but for our explanation, a phallic-drive will do :-0, also known as a pendrive, thumb drive, among others.

For this, I will use my powerful 32 GB pendrive!

The first step, and the most important and difficult of all: plug the mentioned pendrive / USB HDD into the USB port of your server, desktop, laptop, or any other device, as long as it’s running Linux.

After overcoming this crucial step (NOTE: it won’t work if you don’t insert the pendrive into your computer), let’s discover what your device is. For that, we will use the dmesg command:

#rootao> dmesg

device eth0 entered promiscuous mode
type=1700 audit(1344004603.093:3): dev=eth0 prom=256 old_prom=0 auid=4294967295 ses=4294967295
device eth0 left promiscuous mode
type=1700 audit(1344004603.096:4): dev=eth0 prom=0 old_prom=256 auid=4294967295 ses=4294967295
device ppp0 entered promiscuous mode
type=1700 audit(1344004615.317:5): dev=ppp0 prom=256 old_prom=0 auid=4294967295 ses=4294967295
device ppp0 left promiscuous mode
type=1700 audit(1344004628.948:6): dev=ppp0 prom=0 old_prom=256 auid=4294967295 ses=4294967295
usb 2-1.1: new high-speed USB device using ehci_hcd and address 4
usb 2-1.1: configuration #1 chosen from 1 choice
Initializing USB Mass Storage driver…
scsi6 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 4
usb-storage: waiting for device to settle before scanning
usbcore: registered new driver usb-storage
USB Mass Storage support registered.
Vendor: SanDisk Model: Cruzer Edge Rev: 1.20
Type: Direct-Access ANSI SCSI revision: 05
SCSI device sdb: 62530624 512-byte hdwr sectors (32016 MB)
sdb: Write Protect is off
sdb: Mode Sense: 43 00 00 00
sdb: assuming drive cache: write through
SCSI device sdb: 62530624 512-byte hdwr sectors (32016 MB)
sdb: Write Protect is off
sdb: Mode Sense: 43 00 00 00
sdb: assuming drive cache: write through
sdb: sdb1
sd 6:0:0:0: Attached scsi removable disk sdb
sd 6:0:0:0: Attached scsi generic sg2 type 0
usb-storage: device scan complete

MySQL

The dmesg command might show much more information than we need. Look for something like USB, sdb, your device name, etc., in the output. In my case, notice the bold SanDisk (vendor) and the assigned device sdb1. We will need this device to create our mount point.

Now, let’s create a directory inside /mnt that will receive and be our mount point:

#rootao> mkdir /mnt/my_usb

#rootao> mount /dev/sdb1 /mnt/my_usb

Done! Now just refer to the directory /mnt/my_usb to use your device.

Don’t forget to unmount the volume before removing it or stopping its use, with:

#rootao> umount /dev/sdb1

Schedule a meeting here

Visit our Blog

Learn more about databases

Learn about monitoring with advanced tools

MySQL

Have questions about our services? Visit our FAQ

Want to see how we’ve helped other companies? Check out what our clients say in these testimonials!

Discover the History of HTI Tecnologia

Compartilhar: