mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Translated:20140818 How to Take 'Snapshot of Logical Volume and Restore' in LVM--Part III.md
This commit is contained in:
parent
fffb2187f8
commit
7a03bcd66c
@ -1,201 +0,0 @@
|
||||
Translating by GOLinux ...
|
||||
How to Take ‘Snapshot of Logical Volume and Restore’ in LVM – Part III
|
||||
================================================================================
|
||||
**LVM Snapshots** are space efficient pointing time copies of lvm volumes. It works only with lvm and consume the space only when changes are made to the source logical volume to snapshot volume. If source volume has a huge changes made to sum of 1GB the same changes will be made to the snapshot volume. Its best to always have a small size of changes for space efficient. Incase the snapshot runs out of storage, we can use lvextend to grow. And if we need to shrink the snapshot we can use lvreduce.
|
||||
|
||||
![Take Snapshot in LVM](http://www.tecmint.com/wp-content/uploads/2014/08/Take-Snapshot-in-LVM.jpg)
|
||||
Take Snapshot in LVM
|
||||
|
||||
If we have accidentally deleted any file after creating a Snapshot we don’t have to worry because the snapshot have the original file which we have deleted. It is possible if the file was there when the snapshot was created. Don’t alter the snapshot volume, keep as it while snapshot used to do a fast recovery.
|
||||
|
||||
Snapshots can’t be use for backup option. Backups are Primary Copy of some data’s, so we cant use snapshot as a backup option.
|
||||
|
||||
#### Requirements ####
|
||||
|
||||
注:此两篇文章如果发布后可换成发布后链接,原文在前几天更新中
|
||||
|
||||
- [Create Disk Storage with LVM in Linux – PART 1][1]
|
||||
- [How to Extend/Reduce LVM’s in Linux – Part II][2]
|
||||
|
||||
### My Server Setup ###
|
||||
|
||||
- Operating System – CentOS 6.5 with LVM Installation
|
||||
- Server IP – 192.168.0.200
|
||||
|
||||
#### Step 1: Creating LVM Snapshot ####
|
||||
|
||||
First, check for free space in volume group to create a new snapshot using following ‘**vgs**‘ command.
|
||||
|
||||
# vgs
|
||||
# lvs
|
||||
|
||||
![Check LVM Disk Space](http://www.tecmint.com/wp-content/uploads/2014/08/Check-LVM-Disk-Space.jpg)
|
||||
Check LVM Disk Space
|
||||
|
||||
You see, there is 8GB of free space left in above **vgs** output. So, let’s create a snapshot for one of my volume named **tecmint_datas**. For demonstration purpose, I am going to create only 1GB snapshot volume using following commands.
|
||||
|
||||
# lvcreate -L 1GB -s -n tecmint_datas_snap /dev/vg_tecmint_extra/tecmint_datas
|
||||
|
||||
OR
|
||||
|
||||
# lvcreate --size 1G --snapshot --name tecmint_datas_snap /dev/vg_tecmint_extra/tecmint_datas
|
||||
|
||||
Both the above commands does the same thing:
|
||||
|
||||
- **-s** – Creates Snapshot
|
||||
- **-n** – Name for snapshot
|
||||
|
||||
![Create LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Create-LVM-Snapshot.jpg)
|
||||
Create LVM Snapshot
|
||||
|
||||
Here, is the explanation of each point highlighted above.
|
||||
|
||||
- Size of snapshot Iam creating here.
|
||||
- Creates snapshot.
|
||||
- Creates name for the snapshot.
|
||||
- New snapshots name.
|
||||
- Volume which we are going to create a snapshot.
|
||||
|
||||
If you want to remove a snapshot, you can use ‘**lvremove**‘ command.
|
||||
|
||||
# lvremove /dev/vg_tecmint_extra/tecmint_datas_snap
|
||||
|
||||
![Remove LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Remove-LVM-Snapshot.jpg)
|
||||
Remove LVM Snapshot
|
||||
|
||||
Now, list the newly created snapshot using following command.
|
||||
|
||||
# lvs
|
||||
|
||||
![Verify LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Verify-LVM-Snapshot.jpg)
|
||||
Verify LVM Snapshot
|
||||
|
||||
You see above, a snapshot was created successfully. I have marked with an arrow where snapshots origin from where its created, Its **tecmint_datas**. Yes, because we have created a snapshot for **tecmint_datas l-volume**.
|
||||
|
||||
![Check LVM Snapshot Space](http://www.tecmint.com/wp-content/uploads/2014/08/Check-LVM-Snapshot-Space.jpg)
|
||||
Check LVM Snapshot Space
|
||||
|
||||
Let’s add some new files into **tecmint_datas**. Now volume has some data’s around 650MB and our snapshot size is 1GB. So there is enough space to backup our changes in snap volume. Here we can see, what is the status of our snapshot using below command.
|
||||
|
||||
# lvs
|
||||
|
||||
![Check Snapshot Status](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Snapshot-Status.jpg)
|
||||
Check Snapshot Status
|
||||
|
||||
You see, **51%** of snapshot volume was used now, no issue for more modification in your files. For more detailed information use command.
|
||||
|
||||
# lvdisplay vg_tecmint_extra/tecmint_data_snap
|
||||
|
||||
![View Snapshot Information](http://www.tecmint.com/wp-content/uploads/2014/08/Snapshot-Information.jpg)
|
||||
View Snapshot Information
|
||||
|
||||
Again, here is the clear explanation of each point highlighted in the above picture.
|
||||
|
||||
- Name of Snapshot Logical Volume.
|
||||
- Volume group name currently under use.
|
||||
- Snapshot volume in read and write mode, we can even mount the volume and use it.
|
||||
- Time when the snapshot was created. This is very important because snapshot will look for every changes after this time.
|
||||
- This snapshot belongs to tecmint_datas logical volume.
|
||||
- Logical volume is online and available to use.
|
||||
- Size of Source volume which we took snapshot.
|
||||
- Cow-table size = copy on Write, that means whatever changes was made to the tecmint_data volume will be written to this snapshot.
|
||||
- Currently snapshot size used, our tecmint_datas was 10G but our snapshot size was 1GB that means our file is around 650 MB. So what its now in 51% if the file grow to 2GB size in tecmint_datas size will increase more than snapshot allocated size, sure we will be in trouble with snapshot. That means we need to extend the size of logical volume (snapshot volume).
|
||||
- Gives the size of chunk for snapshot.
|
||||
|
||||
Now, let’s copy more than 1GB of files in **tecmint_datas**, let’s see what will happen. If you do, you will get error message saying ‘**Input/output error**‘, it means out of space in snapshot.
|
||||
|
||||
![Add Files to Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Add-Files-to-Snapshot.jpg)
|
||||
Add Files to Snapshot
|
||||
|
||||
If the logical volume become full it will get dropped automatically and we can’t use it any more, even if we extend the size of snapshot volume. It is the best idea to have the same size of Source while creating a snapshot, **tecmint_datas** size was 10G, if I create a snapshot size of 10GB it will never over flow like above because it has enough space to take snap of your volume.
|
||||
|
||||
#### Step 2: Extend Snapshot in LVM ####
|
||||
|
||||
If we need to extend the snapshot size before overflow we can do it using.
|
||||
|
||||
# lvextend -L +1G /dev/vg_tecmint_extra/tecmint_data_snap
|
||||
|
||||
Now there was totally 2GB size for snapshot.
|
||||
|
||||
![Extend LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Extend-LVM-Snapshot.jpg)
|
||||
Extend LVM Snapshot
|
||||
|
||||
Next, verify the new size and COW table using following command.
|
||||
|
||||
# lvdisplay /dev/vg_tecmint_extra/tecmint_data_snap
|
||||
|
||||
To know the size of snap volume and usage **%**.
|
||||
|
||||
# lvs
|
||||
|
||||
![Check Size of Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Size-of-Snapshot.jpg)
|
||||
Check Size of Snapshot
|
||||
|
||||
But if, you have snapshot volume with the same size of Source volume we don’t need to worry about these issues.
|
||||
|
||||
#### Step 3: Restoring Snapshot or Merging ####
|
||||
|
||||
To restore the snapshot, we need to un-mount the file system first.
|
||||
|
||||
# unmount /mnt/tecmint_datas/
|
||||
|
||||
![Un-mount File System](http://www.tecmint.com/wp-content/uploads/2014/08/Unmount-File-System.jpg)
|
||||
Un-mount File System
|
||||
|
||||
Just check for the mount point whether its unmounted or not.
|
||||
|
||||
# df -h
|
||||
|
||||
![Check File System Mount Points](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Mount-Points.jpg)
|
||||
Check File System Mount Points
|
||||
|
||||
Here our mount has been unmounted, so we can continue to restore the snapshot. To restore the snap using command **lvconvert**.
|
||||
|
||||
# lvconvert --merge /dev/vg_tecmint_extra/tecmint_data_snap
|
||||
|
||||
![Restore LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Restore-Snapshot.jpg)
|
||||
Restore LVM Snapshot
|
||||
|
||||
After the merge is completed, snapshot volume will be removed automatically. Now we can see the space of our partition using **df** command.
|
||||
|
||||
# df -Th
|
||||
|
||||
![Check Size of Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Snapshot-Space.jpg)
|
||||
|
||||
After the snapshot volume removed automatically. You can see the size of logical volume.
|
||||
|
||||
# lvs
|
||||
|
||||
![Check Size of Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Size-of-LV.jpg)
|
||||
Check Size of Logical Volume
|
||||
|
||||
**Important**: To Extend the Snapshots automatically, we can do it using some modification in conf file. For manual we can extend using lvextend.
|
||||
|
||||
Open the lvm configuration file using your choice of editor.
|
||||
|
||||
# vim /etc/lvm/lvm.conf
|
||||
|
||||
Search for word autoextend. By Default the value will be similar to below.
|
||||
|
||||
![LVM Configuration](http://www.tecmint.com/wp-content/uploads/2014/08/LVM-Configuration.jpg)
|
||||
LVM Configuration
|
||||
|
||||
Change the **100** to **75** here, if so auto extend threshold is **75** and auto extend percent is 20, it will expand the size more by **20 Percent**
|
||||
|
||||
If the snapshot volume reach **75%** it will automatically expand the size of snap volume by **20%** more. Thus,we can expand automatically. Save and exit the file using **wq!**.
|
||||
|
||||
This will save snapshot from overflow drop. This will also help you to save more time. LVM is the only Partition method in which we can expand more and have many features as thin Provisioning, Striping, Virtual volume and more Using thin-pool, let us see them in the next topic.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in-lvm/
|
||||
|
||||
作者:[Babin Lonston][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/babinlonston/
|
||||
[1]:http://www.tecmint.com/create-lvm-storage-in-linux/
|
||||
[2]:http://www.tecmint.com/extend-and-reduce-lvms-in-linux/
|
@ -0,0 +1,200 @@
|
||||
在LVM中“录制逻辑卷快照并恢复”——第三部分
|
||||
================================================================================
|
||||
**LVM快照**是空间有效指向时间的lvm卷副本。它只在lvm中工作,并只在源逻辑卷发生改变时消耗快照卷的空间。如果源卷的变化达到1GB这么大,快照卷同样也会产生这样大的改变。因而,对于空间有效利用的最佳途径,就是总是进行小的修改。如果快照将存储空间消耗殆尽,我们可以使用lvextend来扩容。而如果我们需要缩减快照,可以使用lvreduce。
|
||||
|
||||
![Take Snapshot in LVM](http://www.tecmint.com/wp-content/uploads/2014/08/Take-Snapshot-in-LVM.jpg)
|
||||
在LVM中录制快照
|
||||
|
||||
如果我们在创建快照后意外地删除了无论什么文件,我们没有必要担心,因为快照里包含了我们所删除的文件的原始文件。创建快照时,很有可能文件每次都在那。不要改变快照卷,保持创建时的样子,因为它用于快速恢复。
|
||||
|
||||
快照不可以用于备份选项。备份是某些数据的基础副本,因此我们不能使用快照作为备份的一个选择。
|
||||
|
||||
#### 需求 ####
|
||||
|
||||
注:此两篇文章如果发布后可换成发布后链接,原文在前几天更新中
|
||||
|
||||
- [在Linux中使用LVM创建磁盘存储 — 第一部分][1]
|
||||
- [在Linux中扩展/缩减LVM — 第二部分][2]
|
||||
|
||||
### 我的服务器设置 ###
|
||||
|
||||
- 操作系统 — 安装有LVM的CentOS 6.5
|
||||
- 服务器IP — 192.168.0.200
|
||||
|
||||
#### 步骤1: 创建LVM快照 ####
|
||||
|
||||
首先,使用‘**vgs**’命令检查卷组中的空闲空间以创建新的快照。
|
||||
|
||||
# vgs
|
||||
# lvs
|
||||
|
||||
![Check LVM Disk Space](http://www.tecmint.com/wp-content/uploads/2014/08/Check-LVM-Disk-Space.jpg)
|
||||
检查LVM磁盘空间
|
||||
|
||||
正如你所见,在**vgs**命令输出中,我们可以看到有8GB的剩余空闲空间。所以,让我们为我的名为**tecmint_datas**的卷之一创建快照。处于演示的目的,我将会使用以下命令来创建1GB的快照卷。
|
||||
|
||||
# lvcreate -L 1GB -s -n tecmint_datas_snap /dev/vg_tecmint_extra/tecmint_datas
|
||||
|
||||
或者
|
||||
|
||||
# lvcreate --size 1G --snapshot --name tecmint_datas_snap /dev/vg_tecmint_extra/tecmint_datas
|
||||
|
||||
上面的两个命令都是干得同一件事:
|
||||
|
||||
- **-s** – 创建快照
|
||||
- **-n** – 为快照命名
|
||||
|
||||
![Create LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Create-LVM-Snapshot.jpg)
|
||||
创建LVM快照
|
||||
|
||||
此处,是对上面高亮要点的说明。
|
||||
|
||||
- 我在此创建的快照的大小。
|
||||
- 创建快照。
|
||||
- 创建快照名。
|
||||
- 新的快照名。
|
||||
- 要创建快照的卷。
|
||||
|
||||
如果你想要移除快照,可以使用‘**lvremove**’命令。
|
||||
|
||||
# lvremove /dev/vg_tecmint_extra/tecmint_datas_snap
|
||||
|
||||
![Remove LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Remove-LVM-Snapshot.jpg)
|
||||
移除LVM快照
|
||||
|
||||
现在,使用以下命令列出新创建的快照。
|
||||
|
||||
# lvs
|
||||
|
||||
![Verify LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Verify-LVM-Snapshot.jpg)
|
||||
验证LVM快照
|
||||
|
||||
上面的你看到了吧,成功创建了一个快照。上面我用箭头标出了快照创建的源,它就是**tecmint_datas**。是的,因为我已经为**tecmint_datas l-volume**创建了一个快照。
|
||||
|
||||
![Check LVM Snapshot Space](http://www.tecmint.com/wp-content/uploads/2014/08/Check-LVM-Snapshot-Space.jpg)
|
||||
检查LVM快照空间
|
||||
|
||||
让我们添加一些新文件到**tecmint_datas**里头。现在卷里大概有650MB左右的数据,而我我们的快照有1GB大。因此,有足够的空间在快照卷里备份我们的修改。这里我们可以使用下面的命令来查看到,我们的快照当前的状态。
|
||||
|
||||
# lvs
|
||||
|
||||
![Check Snapshot Status](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Snapshot-Status.jpg)
|
||||
检查快照状态
|
||||
|
||||
你看到了,现在已经用掉了**51%**的快照卷,你要对你的文件作更多的修改都没有问题。使用下面的命令来查看更多详细信息。
|
||||
|
||||
# lvdisplay vg_tecmint_extra/tecmint_data_snap
|
||||
|
||||
![View Snapshot Information](http://www.tecmint.com/wp-content/uploads/2014/08/Snapshot-Information.jpg)
|
||||
查看快照信息
|
||||
|
||||
再来对上面图片中高亮的要点作个清楚的说明。
|
||||
|
||||
- 快照逻辑卷名称。
|
||||
- 当前使用的卷组名。
|
||||
- 读写模式下的快照卷,我们甚至可以挂载并使用该卷。
|
||||
- 快照创建时间。这个很重要,因为快照将跟踪此时间之后的每个改变。
|
||||
- 该快照属于tecmint_datas逻辑卷。
|
||||
- 逻辑卷在线并可用。
|
||||
- 我们录制快照的源卷大小。
|
||||
- 写时复制表大小,Cow = copy on Write,这是说对tecmint_data卷所作的任何改变都会写入此快照。
|
||||
- 当前使用的快照大小,我们的tecmint_data有10GB,而我们的快照大小是1GB,这就意味着我们的数据大概有650MB。所以,如果tecmint_datas中的文件增长到2GB,现在的51%中的内容将增加到超过所分配的快照的大小,当然,我们在创建快照时会出现问题。这就意味着我们需要扩展逻辑卷大小(快照逻辑卷)
|
||||
- 给出快照组块的大小。
|
||||
|
||||
现在,让我们复制超过1GB的文件到**tecmint_datas**。让我们看看会发生什么。如果你那么做了,你将会见到‘**Input/output error**’这样的错误信息,它告诉你快照超出空间大小了。
|
||||
|
||||
![Add Files to Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Add-Files-to-Snapshot.jpg)
|
||||
添加文件到快照
|
||||
|
||||
如果逻辑卷满了,它就会自动下线,我们就不能再使用了,就算我们去扩展快照卷的大小也不行。最好的方法就是在创建快照时,创建一个和源一样大小的快照卷。**tecmint_datas**的大小是10GB,如果我们创建一个10GB大小的快照,它就永远都不会像上面那样超载,因为它有足够的空间来录制你的逻辑卷的快照。
|
||||
|
||||
#### 步骤2: 在LVM中扩展快照 ####
|
||||
|
||||
如果我们需要在超载前扩展快照大小,我们可以使用以下命令来完成此项任务。
|
||||
|
||||
# lvextend -L +1G /dev/vg_tecmint_extra/tecmint_data_snap
|
||||
|
||||
现在,那里有总计2GB大小的快照空间。
|
||||
|
||||
![Extend LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Extend-LVM-Snapshot.jpg)
|
||||
扩展LVM快照
|
||||
|
||||
接下来,使用以下命令来验证新的大小和写时复制表。
|
||||
|
||||
# lvdisplay /dev/vg_tecmint_extra/tecmint_data_snap
|
||||
|
||||
要知道快照卷的大小使用**%**。
|
||||
|
||||
# lvs
|
||||
|
||||
![Check Size of Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Size-of-Snapshot.jpg)
|
||||
检查快照大小
|
||||
|
||||
然而,如果你的快照大小和源卷一样,我们就没有必要担心这些问题了。
|
||||
|
||||
#### 步骤3: 恢复快照或合并 ####
|
||||
|
||||
要恢复快照,我们首先需要卸载文件系统。
|
||||
|
||||
# unmount /mnt/tecmint_datas/
|
||||
|
||||
![Un-mount File System](http://www.tecmint.com/wp-content/uploads/2014/08/Unmount-File-System.jpg)
|
||||
卸载文件系统
|
||||
|
||||
只想检查挂载点是否卸载,可以使用下面的命令。
|
||||
|
||||
# df -h
|
||||
|
||||
![Check File System Mount Points](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Mount-Points.jpg)
|
||||
检查文件系统挂载点
|
||||
|
||||
这里,我们的挂载已经被卸载,所以我们可以继续恢复快照。要恢复快照,可以使用**lvconvert**命令。
|
||||
|
||||
# lvconvert --merge /dev/vg_tecmint_extra/tecmint_data_snap
|
||||
|
||||
![Restore LVM Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Restore-Snapshot.jpg)
|
||||
恢复LVM快照
|
||||
|
||||
在合并完成后,快照卷将被自动移除。现在我们可以使用**df**命令来查看分区大小。
|
||||
|
||||
# df -Th
|
||||
|
||||
![Check Size of Snapshot](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Snapshot-Space.jpg)
|
||||
|
||||
在快照卷自动移除后,你可以用下面的命令查看逻辑卷大小。
|
||||
|
||||
# lvs
|
||||
|
||||
![Check Size of Logical Volume](http://www.tecmint.com/wp-content/uploads/2014/08/Check-Size-of-LV.jpg)
|
||||
检查逻辑卷大小
|
||||
|
||||
**重要**:要自动扩展快照,我们可以通过修改配置文件来进行。对于手动扩展,我们可以使用lvextend。
|
||||
|
||||
使用你喜欢的编辑器打开lvm配置文件。
|
||||
|
||||
# vim /etc/lvm/lvm.conf
|
||||
|
||||
搜索单词autoextend。默认情况下,该值和下图中的类似。
|
||||
|
||||
![LVM Configuration](http://www.tecmint.com/wp-content/uploads/2014/08/LVM-Configuration.jpg)
|
||||
LVM配置
|
||||
|
||||
修改此处的**100**为**75**,这样自动扩展的起始点就是**75**,而自动扩展百分比为20,它将自动扩容**百分之20**。
|
||||
|
||||
如果快照卷达到**75%**,它会自动为快照卷扩容**20%**。这样,我们可以自动扩容了。使用**wq!**来保存并退出。
|
||||
|
||||
这将把快照从超载下线中拯救出来,这也会帮助你节省更多时间。LVM是我们扩容以及获得其它众多特性如精简资源调配、拆卸、虚拟卷和使用精简池的唯一方法,让我们在下一个话题中来讨论吧。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in-lvm/
|
||||
|
||||
作者:[Babin Lonston][a]
|
||||
译者:[GOLinux](https://github.com/GOLinux)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/babinlonston/
|
||||
[1]:http://www.tecmint.com/create-lvm-storage-in-linux/
|
||||
[2]:http://www.tecmint.com/extend-and-reduce-lvms-in-linux/
|
Loading…
Reference in New Issue
Block a user