LVM数据迁移

如果把LVM逻辑卷的数据做在线迁移
1.添加一块新硬盘,用来存放迁移后的数据,如下,把sdc的数据在线迁移的sdd中

[root@master mysql]# lsblk /dev/sdc /dev/sdd
NAME      MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdc         8:32   0  30G  0 disk 
└─myvo-vo 253:2    0  29G  0 lvm  /data
sdd         8:48   0  30G  0 disk 

2.给sdd磁盘创建PV并加入sdc对应的逻辑卷VG,实际上就是对myvo逻辑卷进行扩容

[root@master mysql]# vgextend myvo /dev/sdd
  Physical volume "/dev/sdd" successfully created.
  Volume group "myvo" successfully extended
[root@master mysql]# pvs
  PV         VG     Fmt  Attr PSize    PFree   
  /dev/sda2  centos lvm2 a--   <19.00g       0 
  /dev/sda3  centos lvm2 a--  <480.00g  <10.00g
  /dev/sdc   myvo   lvm2 a--   <30.00g 1020.00m
  /dev/sdd   myvo   lvm2 a--   <30.00g  <30.00g

3.迁移数据

[root@master mysql]# pvmove /dev/sdc /dev/sdd
  /dev/sdc: Moved: 7.75%
  /dev/sdc: Moved: 100.00%
[root@master mysql]# pvs
  PV         VG     Fmt  Attr PSize    PFree   
  /dev/sda2  centos lvm2 a--   <19.00g       0 
  /dev/sda3  centos lvm2 a--  <480.00g  <10.00g
  /dev/sdc   myvo   lvm2 a--   <30.00g  <30.00g
  /dev/sdd   myvo   lvm2 a--   <30.00g 1020.00m

可以查看PFree项,能看到数据已经迁移过去

4.把sdc移除逻辑卷

[root@master mysql]# vgreduce myvo /dev/sdc
  Removed "/dev/sdc" from volume group "myvo"
[root@master mysql]# pvs
  PV         VG     Fmt  Attr PSize    PFree   
  /dev/sda2  centos lvm2 a--   <19.00g       0 
  /dev/sda3  centos lvm2 a--  <480.00g  <10.00g
  /dev/sdc          lvm2 ---    30.00g   30.00g
  /dev/sdd   myvo   lvm2 a--   <30.00g 1020.00m
[root@master mysql]# pvremove /dev/sdc
  Labels on physical volume "/dev/sdc" successfully wiped.
[root@master mysql]# lsblk /dev/sdc /dev/sdd
NAME      MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdc         8:32   0  30G  0 disk 
sdd         8:48   0  30G  0 disk 
└─myvo-vo 253:2    0  29G  0 lvm  /data
[root@master mysql]# df -h | grep myvo   //查看是否影响原有挂载
/dev/mapper/myvo-vo       29G  3.1G   24G   12% /data

你可能感兴趣的:(linux,LVM)