[深入理解文件系统之十三] 基于快照的文件系统备份

在实际生产系统上存储的数据,都是基于某种文件系统的形式组织、存放起来的。对一些关键的数据,就需要备份。通常,有两种方式:

1.基于Linux/unix下的tar/cpio等工具

虽然它也能实现备份,但不足之处在于有IO写入的情况下,可能无法保证文件系统的integrity
(完整性).

2.
frozen-image

虽然备份的时候停下业务、卸载
文件系统就可以了,但是系统管理员一般不愿意停下业务、或者卸载文件系统,因此stable
snapshot技术出现了。(snapshot/frozen-image/point-in-time都是指文件系统中的stable
image).根据重启之后,数据是否还一直,snapshot可以分为non
persistent snapshot  和persistent
snapshot。

下面基于VxFS文件想,介绍一下snapshot的使用示例:

#vxassist
make fs1 100m

#mkfs
-F vxfs /dev/vx/rdsk/fs1 100m

version
4 layout

204800
sectors, 102400 blocks of size 1024, log size 1024 blocks

unlimited
inodes, largefiles not supported

102400
data blocks, 101280 free data blocks

4
allocation units of 32768 blocks, 32768 data blocks

last
allocation unit has 4096 data blocks

#mount
-F vxfs /dev/vx/dsk/fs1 /fs1

#echo
hello > /fs1/fileA

#echo
goodbye > /fs1/fileB

#mkdir
/snap

#vxassist
make snap 10m

#mount
-F vxfs -osnapof=/fs1,snapsize=20480 /dev/vx/dsk/snap /snap  #建立快照

#df
-k

...

/dev/vx/dsk/fs1
102400 1135 94943 2% /fs1

/dev/vx/dsk/snap
102400 1135 94936 2% /snap

...

#ls
-l /fs1

total
4

-rw-r--r--
1 root other 6 Jun 7 11:17 fileA

-rw-r--r--
1 root other 8 Jun 7 11:17 fileB

drwxr-xr-x
2 root root 96 Jun 7 11:15 lost+found

#ls
-l /snap

total
4

-rw-r--r--
1 root other 6 Jun 7 11:17 fileA

-rw-r--r--
1 root other 8 Jun 7 11:17 fileB

drwxr-xr-x
2 root root 96 Jun 7 11:15 lost+found

#cat
/fs1/fileA

hello

#cat
/snap/fileA

hello

#rm
/fs1/fileA

#
cat /snap/fileA

hello

#df
-k

...

/dev/vx/dsk/fs1
102400 1134 94944 2% /fs1

/dev/vx/dsk/snap
102400 1135 94936 2% /snap

然后,用户可以利用快照进行备份,在VxFS中可以利用fscat(类似于linux中的dd命令):

#vxassist
make fs1 10m

#vxassist
make fs1-copy 10m

#vxassist
make snap 5m

#mkfs
-F vxfs /dev/vx/rdsk/fs1 10m

version
4 layout

20480
sectors, 10240 blocks of size 1024, log size 1024 blocks

unlimited
inodes, largefiles not supported

10240
data blocks, 9144 free data blocks

1
allocation units of 32768 blocks, 32768 data blocks

last
allocation unit has 10240 data blocks

#mount
-F vxfs /dev/vx/dsk/fs1 /fs1

#echo
hello > /fs1/hello

#echo
goodbye > /fs1/goodbye

#mount
-F vxfs -osnapof=/fs1,snapsize=10240 /dev/vx/dsk/snap /snap

#rm
/fs1/hello

#rm
/fs1/goodbye

#fscat
/dev/vx/dsk/snap > /dev/vx/rdsk/fs1-copy
#场景快照snap的备份,文件系统名称是fs1-copy

删除fs1/hello和fs1/goodbye之后,snap文件中的super
block中的dirty位被设置起来,因此后面他的备份文件系统fs1-copy中的dirty-bit也处于置位状态,在fs1-copy被挂载的时候就会重放出之前的文件:

#
fsck -F vxfs /dev/vx/rdsk/fs1-copy

log
replay in progress

replay
complete - marking super-block as CLEAN

#mount
-F vxfs /dev/vx/dsk/fs1-copy /fs2

#ls
-l /fs2

total
4

-rw-r--r--
1 root other 8 Jun 7 11:37 goodbye

-rw-r--r--
1 root other 6 Jun 7 11:37 hello

drwxr-xr-x
2 root root 96 Jun 7 11:37 lost+found

#cat
/fs2/hello

hello

#cat
/fs2/goodbye

goodbye

VxFS中snapshot的实现

在VxFS里,这些snapshot只是在文件系统被挂载或运行的时候,里面的数据才会存在,因此是non-persistent的。为了改进这个问题,VxFS引入了checkpoints的概念。两者的区别如下表:

Non-persistent
snapshot 只有只读属性的原因是,它的bitmap只记录了变化的block,如果读的话,现有的数据结构(设计)无法支持。

VxFS中checkpoints的用法示例:

#mkfs
-F vxfs /dev/vx/rdsk/fs1 100m

version
4 layout

204800
sectors, 102400 blocks of size 1024, log size 1024 blocks

unlimited
inodes, largefiles not supported

102400
data blocks, 101280 free data blocks

4
allocation units of 32768 blocks, 32768 data blocks

last
allocation unit has 4096 data blocks

#mount
-F vxfs /dev/vx/dsk/fs1 /fs1

#echo
hello > /fs1/hello

#echo
goodbye > /fs1/goodbye

#ls
-l /fs1

total
4

-rw-r--r--
1 root other 8 Jun 9 11:05 goodbye

-rw-r--r--
1 root other 6 Jun 9 11:05 hello

drwxr-xr-x
2 root root 96 Jun 9 11:04 lost+found

#fsckptadm
create ckpt1 /fs1   #创建checkponts1

#rm
/fs1/goodbye

#echo
"hello again" > /fs1/hello

#fsckptadm
create ckpt2 /fs1 #创建checkponts2

#fsckptadm
list /fs1

/fs1

ckpt2:

ctime
= Sun Jun 9 11:06:55 2002

mtme
= Sun Jun 9 11:06:55 2002

flags
= none

ckpt1:

ctime
= Sun Jun 9 11:05:48 2002

mtime
= Sun Jun 9 11:05:48 2002

flags
= none

#mkdir
/ckpt1

#mkdir
/ckpt2

#mount
-F vxfs -ockpt=ckpt1 /dev/vx/dsk/fs1:ckpt1 /ckpt1

#mount
-F vxfs -ockpt=ckpt2 /dev/vx/dsk/fs1:ckpt2 /ckpt2

#ls
-l /fs1

total
2

-rw-r--r--
1 root other 12 Jun 9 11:06 hello

drwxr-xr-x
2 root root 96 Jun 9 11:04 lost+found

#ls
-l /ckpt1

total
4

-rw-r--r--
1 root other 8 Jun 9 11:05 goodbye

-rw-r--r--
1 root other 6 Jun 9 11:05 hello

drwxr-xr-x
2 root root 96 Jun 9 11:04 lost+found

#ls
-l /ckpt2

total
0

-rw-r--r--
1 root other 12 Jun 9 11:06 hello

drwxr-xr-x
2 root root 96 Jun 9 11:04 lost+found

VxFS中checkpoints的实现:(复制indoe/file
descriptor)

VxFS
storage checkpoints are heavily tied to the implementation of VxFS.
The

sectionVxFS
Disk Layout Version 5,
in Chapter 9, describes the various

components
of the VxFS disk layout. VxFS mountable entities are called filesets.

Each
fileset has its own inode list including an inode for the root of the
fileset,

allowing
it to be mounted separately from other filesets. By providing linkage

between
the two filesets, VxFS uses this mechanism to construct a chain of

checkpoints,
as shown in Figure 12.4.

This
linkage is called a clone
chain.
At the head of the clone chain is the primary

fileset.
When a filesystem is created with mkfs,
only the primary fileset is created.

When
a checkpoint is created, the following events occur:

■ A
new fileset header entry is created and linked into the clone chain.
The

primary
fileset will point downstream to the new checkpoint, and the new

checkpoint
will point downstream to the next most recent checkpoint.

Upstream
linkages will be set in the reverse direction. The downstream

pointer
of the oldest checkpoint will be NULL to indicate that it is the

oldest
fileset in the clone chain.

■ An
inode list is created. Each inode in the new checkpoint is an exact
copy

of
the inode in the primary fileset with the exception of the block map.

When
the checkpoint is created, inodes are said to be fully
overlayed.
In

order
to read any data from the inode, the filesystem must walk up the

clone
chain to read the blocks from the inode upstream.

■ The
in-core fileset structures are modified to take into account the new

checkpoint.
This is mainly to link the new fileset into the clone chain.

下面是主要的数据结构关联图:

时间: 2024-08-30 02:19:07

[深入理解文件系统之十三] 基于快照的文件系统备份的相关文章

HDFS的快照原理和Hbase基于快照的表修复

前一篇文章<HDFS和Hbase误删数据恢复>主要讲了hdfs的回收站机制和Hbase的删除策略.根据hbase的删除策略进行hbase的数据表恢复.本文主要介绍了hdfs的快照原理和根据快照进行的数据恢复. 1.Hdfs的快照原理 1.1 快照原理 Hdfs的快照(snapshot)是在某一时间点对指定文件系统拷贝,快照采用只读模式,可以对重要数据进行恢复.防止用户错误性的操作. 快照分两种:一种是建立文件系统的索引,每次更新文件不会真正的改变文件,而是新开辟一个空间用来保存更改的文件,一种

tmpfs:一种基于内存的文件系统

tmpfs是一种基于内存的文件系统, tmpfs有时候使用rm(物理内存),有时候使用swap(磁盘一块区域).根据实际情况进行分配. rm:物理内存.real memery的简称? 真实内存就是电脑主板上那块内存条,叫做真实内存不为过. swap:交换分区.是硬盘上一块区域 tmpfs最大可使用的大小为什么是rm+swap. SWAP就是LINUX下的虚拟内存分区,它的作用是在物理内存使用完之后,将磁盘空间(也就是SWAP分区)虚拟成内存来使用. 它和Windows系统的交换文件作用类似,但是

17.文件系统——逻辑卷、快照以及如何创建逻辑卷(pv、vg、lv)

一.逻辑卷管理器LVM概述 前面我们在Linux系统上模拟软RAID,使用的是md模块,事实上,还有一个模块dm--device mapper,也可以实现软RAID的模拟.md模块的管理工具是mdadm,它专门用来管理RAID设备:dm模块则更为强大,它的管理工具不再是一个单一的工具,而是一组工具,根据不同的规则进行管理(如物理卷的创建.删除.修改:卷组的大小调整.扫描.显示等:逻辑卷的创建.删除和修改等),为dm提供设备映射法则:它支持将多个物理设备以多种不同的方式组合起来,其中包含但不仅限于

mysqldump 和 基于快照的备份

mysqldump 和 基于快照的备份 Table of Contents mysqldump: 仅适用于数据集较小 lvm-snapshot: 基于 LVM 快照的备份 相关阅读 mysqldump: 仅适用于数据集较小 mysqldump DB_NAME [tbname1] [tbname2] # mysqldump -uroot -pYOUR_PASSWORD DB_NAME > test.sql mysql> create database test2; mysqldump -uroo

LVM中对基于xfs的文件系统进行扩容

以前没接触过CentsOS 7 ,对其所改变的特性不了解,偶然在centos 7中接触到LVM,创建LVM的方法和6中没有区别,但是对LVM进行扩容就有点不一样了,使用以前的方法进行扩容后始终没有生效,折腾了半天才搞清楚其扩容的方法.Xfs是CentOS7的默认文件系统类型,而不同文件系统类型对应的创建.检查.调整命令不同. Xfs是CentOS7的默认文件系统类型,而不同文件系统类型对应的创建.检查.调整命令不同. 在xfs文件系统中,只能增大分区而不能减小. [[email protecte

ext3是对ext2文件系统的一个扩展高性能日志文件系统

嵌入式开发者所做的最重要的决定之一就是部署哪种文件系统.有些文件系统性能比较高有些文件系统空间利用率比较高,还有一些文件系统设备故障或者意外断电后恢复数据比较方便. linux文件系统概念 分区 分区是对物理设备的逻辑划分,而文件系统就存在于这个设备上.一个物理设备可以只包含一个分区,占据所有可用空间,或者,它可以被分成多个分区,以适合某个特定任务的要求.一个分区可以被看成一个逻辑盘,它上面可以存储一个完整的文件系统.一个分区就是物理媒介的一个逻辑部分,这个分区中数据的组织形式遵循此分区类型的相

嵌入式 Linux根文件系统移植(二)——根文件系统简介

嵌入式 Linux根文件系统移植(二)--根文件系统简介 根文件系统是内核启动时挂载的第一个文件系统,内核代码映像文件保存在根文件系统中,而系统引导启动程序会在根文件系统挂载之后从中把一些基本的初始化脚本和服务等加载到内存中去运行. 一.嵌入式设备文件系统 在嵌入式Linux应用中,主要的存储设备为 RAM(DRAM, SDRAM)和ROM(常采用FLASH存储器),常用的基于存储设备的文件系统类型包括:jffs2, yaffs, cramfs, romfs, ramdisk, ramfs/tm

嵌入式 Linux根文件系统移植(一)——Linux文件系统简介

嵌入式 Linux根文件系统移植(一)--Linux文件系统简介 本文对文件系统分析的代码来源于linux 2.6.35.7版本. 一.文件系统的体系结构 文件系统是对存储设备上的数据和元数据进行组织的机制,便于用户和操作系统的交互.Linux支持多种文件系统,文件系统接口实现为分层的体系结构,将用户接口层.文件系统实现和操作存储设备的驱动程序分隔开.Linux文件系统的体系结构如下: 用户空间包含一些应用程序(例如,文件系统的使用者)和 GNU C库(glibc),为文件系统调用(打开.读取.

使用LVM快照进行数据库备份

使用mysqldump备份时,如果存储引擎为MyISAM,则只能实现温备份,并需使用选项--lock-all-tables锁定所有表.如果存储引擎为InnoDB,则加上--single-transaction选项,可以实现热备.使用mysqldump进行逻辑备份,还存在如下问题:浮点数据丢失精度: 备份出的数据更占用空间:不过可压缩后以大大节省空间 不适合对大数据库(如一个库超过10G)做完全备份 另外对InnoDB而言,需要使用mysql> FLUSH TABLES WITH READ LOC