Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed implementation of backup and restore of MySQL and mariadb databases based on logical Volume LVM

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The premise is that the database data is placed on the logical volume; the database data and logs are stored separately; normally, the data and logs are placed on two separate disks, and if it is raid, then it doesn't matter.

Create a partition:

[root@mysql] $fdisk / dev/sda Command (m for help): n All primary partitions are in use Adding logical partition 6 First sector (153098240-419430399, default 153098240): Using default value 153098240 Last sector, + sectors or + size {K Magi Mpeng} (153098240-419430399, default 419430399): + 10G Partition 6 of type Linux and of size 10 GiB is set Command (m for help): t Partition number (1-6) Default 6): 6 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to' Linux LVM' Command (m for help): w The partition table has been altered! Calling ioctl () to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe (8) or kpartx (8) Syncing disks. [root@mysql] $partprobe Warning: Unable to open / dev/sr0 read-write (Read-only file system). / dev/sr0 has been opened read-only. [root@mysql ~] $lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0200G 0 disk ├─ sda1 8:1 01G 0 part / boot ├─ sda2 8:2 050G 0 part / ├─ sda3 8:3 020G 0 part / app ├─ sda4 8:4 0512B 0 part ├─ sda5 8:5 0 2G 0 part [SWAP] └─ sda6 8:6 0 10G 0 part sr0 11:0 1 8.1G 0 rom loop0 7:0 0 8.1G 1 loop / mnt/cdrom

Create a PV,vg,lv:

Join PV, VG and LV [root@mysql ~] $pvcreate / dev/sda6 Physical volume "/ dev/sda6" successfully created. [root@mysql ~] $pvs PV VG Fmt Attr PSize PFree / dev/sda6 lvm2-10.00g [root@mysql ~] $vgcreate vg0 / dev/sda6 Volume group "vg0" successfully created [root@mysql ~] $vgs VG # PV # LV # SN Attr VSize VFree vg0 100 wz--n- show master logs +-+-+ | Log_name | File_size | +-+-+ | mysql-bin.000001 | 30331 | | mysql-bin.000002 | 1038814 | mysql-bin.000003 | 7698 | mysql-bin.000004 | 442 | | mysql-bin.000005 | | 245 | +-+-+ 5 rows in set (0.00 sec) only part of the data has been recovered at this time | But not the latest, to restore to the latest state, you need to use the binary between mysql-bin.000004 245 and mysql-bin.000005 245 to complete the recovery. [root@mysql] $lsall_2018-02-24_21:46:13.sql anaconda-ks.cfg hellodb_InnoDB.sql mariadb-bin.000010 r7.shall.sql binlog.sql initial-setup-ks.cfg pos.log [root@mysql ~] $less pos.log Log_name File_sizemysql-bin.000001 30331mysql-bin.000002 1038814mysql-bin.000003 7698mysql-bin.000004 245 [ Root@mysql ~] $cd / data/binlogs/ [root@mysql binlogs] $lsmysql-bin.000001 mysql-bin.000002 mysql-bin.000003 mysql-bin.000004 mysql-bin.000005 mysql-bin.index [root@mysql binlogs] $cp-a mysql-bin.00000 {4pm 5} ~ MariaDB [(none)] > flush tables with read lock Query OK, 0 rows affected (0.00 sec) [root@mysql ~] $mysqlbinlog-- start-position=245 mysql-bin.000004 > binlog.sql [root@mysql ~] $mysqlbinlog mysql-bin.000005 > > binlog.sqlMariaDB [(none)] > set sql_log_bin=0;Query OK, 0 rows affected (0.00 sec) MariaDB [(none)] > unlock tables;Query OK, 0 rows affected (0.00 sec) MariaDB [(none)] > source binlog.sql finds students table empty at this time MariaDB [(none)] > select * from hellodb.students; Note: the backup of MySQLdump is warm; its efficiency is not particularly high, because its backup is equivalent to the result of query operation on MySQL database; if it is a T-level database, it takes a lot of time to query backup.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report