Based backup of lvm2

Because the default data file location mariadb is / var / lib / mysql directory, not a file system, so here with the newly added disk to create a file system tests

Create a file system test

1. Add Disk

2. Reboot the server to recognize the hard disk

3. Partition

[root@localhost ~]#fdisk /dev/sdb

4. Create pv

[root@localhost ~]#pvcreate /dev/sdb1

5. Create vg

[root@localhost ~]# vgcreate test3vg /dev/sdb1

6. Create lv

[root@localhost ~]# lvcreate -L 2G -n testlv3 test3vg 

7. Format lv

[root@localhost ~]# mkfs.ext4 /dev/test3vg/testlv3 

8. Create a file in the root directory

[root@localhost ~]# mkdir /test3

9. mount directory

[root@localhost ~]# mount /dev/test3vg/testlv3 /test3/

If yum install the default data directory in / var / lib / mysql, if you need to change

Open vim etc / my.cnf.d / server.cnf profile

10.

[mysqld]
datadir=/test3/
pid_file=/test3/localhost.pid
socket=/test3/mysql.sock
wsrep_data_home_dir=/test3/
log_bin=mysql-bin
[client]
socket=/test3/mysql.sock

11. The / var / lib / mysql all files in the file is copied to the mount

[root@localhost ~]#cp -a /var/lib/mysql/* /test3/ 

12. Modify the file permissions in the directory, you must MySQL, or else get up database

[root@localhost ~]#chown -R mysql.mysql /test3

13. Restart the database

[root@localhost ~]#systectl restart mariadb

14. The access to the database will lock all the tables

MariaDB [(none)]> flush tables with read lock;

15. lv create a snapshot

[root@localhost ~]# lvcreate -L 2G -s -p r -n snap_test3 /dev/test3vg/testlv3

16. unlock access to the database

[root@localhost ~]#MariaDB [(none)]> unlock tables;

17. Create snapshot directory

[root@localhost testvg]# mkdir /snap_test3

18. lv snapshot mount

[root@localhost ~]# mount /dev/testvg/snap_test3 /snap_test3/ 

At this time you can see the contents of the source file with exactly the same system in the snapshot directory, then you can use the cp copy!  

  

  

  

  

  

  

  

  

  

 

  

  

  

  

  

 

Guess you like

Origin www.cnblogs.com/sudan5/p/11278834.html