background
In the course of the project we often have to migrate the database, archive, etc. Split operation is now described under several schemes
- This command can specify mysqldump to export the database, when the command may be a long time
- cp mysql directly copy the data files, this will affect the business needs mysql offline
- Use innobackupex tools for backup, this does not affect business, slightly faster
- Hit lvm snapshot and backup data from the snapshot, save time
We need to migrate mysql on the physical disk to the ssd, to talk about production data have been generated, and the amount of data to reach 500G.
Option One: Use mysqldump, regardless of import and export are too time-consuming, not a day take no less than
Option II: the direct physical disk copy is also very time consuming copy process needs to stop service, which leads to stop the service too long.
Option Three: This program could have been a great advantage, but the actual situation of export and import also need to lock the lock table or library, but also the need to stop the service, we do not need to have been incremental copy, innobackupex advantage is reflected in the incremental copy.
Option 4: copy speed
integrated stop service time and ease of operation, the final choice of Option IV.
The following describes the steps
Preparing the Environment
1, create a physical volume
Excuting an order
pvcreate /dev/vdb
2, create a volume group
vgcreate vgssd /dev/vdb
3. Create mysql data partition
lvcreate --size280G -n mysql vgssd
4, remove the old mysql data, and mount
mv /var/lib/mysql /var/lib/mysql_bak
mount /dev/vgssd/mysql /var/lib/mysql
5, data is copied to a local line
cp -af remotepath /var/lib/mysql
chown mysql:mysql /var/lib/mysql
After performing the above step, and then begin archiving
Archive Procedure
1, stop mysql and other services
systemctl stop httpd
systemctl stop supervisord
systemctl stop mariadb
umount /var/lib/mysql
Need to ensure that each terminal exit the directory Execute umount
2, view disk case
3, create a snapshot volume
lvcreate -s --size 180G -n mysql_backup /dev/vgssd/mysql
4, rebind mysql, restart the service
mount /dev/vgssd/mysql /var/lib/mysql
systemctl start mariadb
systemctl start httpd
systemctl start supervisord
5, mounting the snapshot volume
mkdir -p /mnt/mysql_temp
mount -o ro,nouuid /dev/vgssd/mysql_backup /mnt/mysql_temp
ls /mnt/mysql_temp
6, copy data, copy data to the local
mkdir -p /mnt/backup/mysql
cp -a /mnt/mysql_temp /mnt/backup/mysql
7, unmounted, delete the snapshot volume
umount /mnt/mysql_temp
lvremove /dev/vgssd/mysql_backup
Timing Archive
Tentatively scheduled for 30 days, so as to back up all data.
Because of the need to prepare the hardware, so there can only manual operation
Data recovery
If you need to restore data disk data loss, perform the following operation
1, shut down mysql service
systemctl stop mariadb
2, modify /etc/my.conf
DATADIR = / mnt / Backup / MySQL
3, restart the service
systemctl start mariadb