一、迁移数据至逻辑卷1.首先创建一个逻辑卷
[[email protected] ~]# pvcreate /dev/sd{b,c} Physical volume "/dev/sdb" successfully created. Physical volume "/dev/sdc" successfully created.[[email protected] ~]# vgcreate testvg /dev/sd{b,c} Volume group "testvg" successfully created[[email protected] ~]# lvcreate -n testlv -L 5G testvg Logical volume "testlv" created.2.将磁盘格式化为ext4分区格式
[[email protected] ~]# mkfs.ext4 /dev/testvg/testlv mke2fs 1.42.9 (28-Dec-2013)filesystem label=OS type: linuxBlock size=4096 (log=2)Fragment size=4096 (log=2)StrIDe=0 blocks,Stripe wIDth=0 blocks327680 inodes,1310720 blocks65536 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=134217728040 block groups32768 blocks per group,32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768,98304,163840,229376,294912,819200,884736Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done3.挂载逻辑卷设备至临时目录,并复制需要迁移的数据。(以下以home家目录为例进行数据迁移)
[[email protected] ~]# mkdir /testdir[[email protected] ~]# mount /dev/testvg/testlv /testdir/[[email protected] ~]# cp -a /home/. /testdir/[[email protected] ~]# ls /testdirlost+found masuri4.卸载设备,移除原家目录下的内容。
[[email protected] home]# mv /home/* /tmp/[[email protected] testdir]# umount /testdir/5.将lvm设备挂载至/home完成数据迁移,由于用户家目录再启动时需要开机时挂载所以此处需要将其写入配置文件,并挂载
[[email protected] home]# vim /etc/fstab## /etc/fstab# Created by anaconda on Tue Mar 5 21:07:19 2019## Accessible filesystems,by reference,are maintained under ‘/dev/disk‘# See man pages fstab(5),findfs(8),mount(8) and/or blkID(8) for more info#UUID=45490aa4-cf29-420d-a606-af32688b6707 / xfs defaults 0 0UUID=15dcd896-b7cf-48d0-b8bd-4c0b0f2c62b2 /boot xfs defaults 0 0UUID=4b6e1813-2c46-402a-869a-02cbbcb76ade /data xfs defaults 0 0UUID=0995b444-48c1-4423-92bc-2deda0d3c082 swap swap defaults 0 0UUID=a3fa2d53-91c4-4af5-9ee4-c63500dbaaf2 /home ext4 defaults 0 0~~#挂载设备[[email protected] home]# mount -a#查看设备是否挂载[[email protected] home]# lsblkname MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP]sdb 8:16 0 20G 0 disk └─testvg-testlv 253:0 0 5G 0 lvm /homesdc 8:32 0 20G 0 disk sr0 11:0 1 10G 0 rom #查看lvm中的数据是否存在[[email protected] home]# cd /home[[email protected] home]# lslost+found masuri
二、lvm快照
lvm快照的原理是在和需要拍摄快照的逻辑卷的同一卷组上创建一个空白逻辑卷并标识当前的时间,当原逻辑卷内的某数据发生改变时,首先会在此数据未发生改变前复制一份至快照卷。当需要用到快照时,系统会将快照卷内的数据全部复制回逻辑卷,并将逻辑卷内拍摄快后建立的数据全部删除。快照卷的大小一般为逻辑卷内数据的大小,过大无意义,过小可能会造成数据的丢失。
1.创建快照卷此处以刚才创建的逻辑卷/dev/testvg/testlv为例,创建快照
[[email protected] home]# lvcreate -n home_snap -s -L 100M /dev/testvg/testlv Logical volume "home_snap" created.#查看快照卷是否创建[[email protected] home]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log cpy%sync Convert home_snap testvg swi-a-s--- 100.00m testlv 0.01 testlv testvg owi-aos--- 5.00g2.使用快照对逻辑卷恢复
在对逻辑卷恢复之前先将逻辑卷内的数据进行一些修改
[[email protected] ~]# cd /home[[email protected] home]# lslost+found masuri[[email protected] home]# touch file{1..5}[[email protected] home]# lsfile1 file2 file3 file4 file5 lost+found masuri
恢复快照,恢复快照前需要将逻辑卷卸载
[[email protected] ~]# umount /home/[[email protected] ~]# lvconvert --merge /dev/testvg/home_snap Merging of volume testvg/home_snap started. testvg/testlv: Merged: 100.00%
挂载逻辑卷查看数据是否恢复
[[email protected] ~]# mount -a[[email protected] ~]# cd /home[[email protected] home]# lslost+found masuri总结
以上是内存溢出为你收集整理的迁移数据至逻辑卷和LVM快照全部内容,希望文章能够帮你解决迁移数据至逻辑卷和LVM快照所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)