Apache Hadoop 2.9.2 的快照管理

              Apache Hadoop 2.9.2 的快照管理

                                        作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

  快照相当于对目录做一个备份。并不会立即复制所有文件,而是指向同一个文件。当写入发生时,才会产生新文件。换句话说,快照可以迅速对文件(夹)进行备份,不产生新文件,使用差值存储,默认是禁用状态。因此,想要使用快照功能的话得先启用该功能!我们可以通过“hdfs dfsadmin” 命令来启动或者禁止快照管理。

一.快照的作用

  Hadoop从2.1.0版开始提供了HDFS SnapShot的功能。一个snapshot(快照)是一个全部文件系统、或者某个目录在某一时刻的镜像。快照在下面场景下是非常有用:
1>.防止用户的错误操作:

  管理员可以通过以滚动的方式周期性设置一个只读的快照,这样就可以在文件系统上有若干份只读快照。如果用户意外地删除了一个文件,就可以使用包含该文件的最新只读快照来进行回复。
2>.备份:

  管理员可以根据需求来备份整个文件系统,一个目录或者单一一个文件。管理员设置一个只读快照,并使用这个快照作为整个全量备份的开始点。增量备份可以通过比较两个快照的差异来产生。
3>.试验/测试:

  一个用户当想要在数据集上测试一个应用程序。一般情况下,如果不做该数据集的全量拷贝,测试应用程序会覆盖/损坏原来的生产数据集,这是非常危险的。管理员可以为用户设置一个生产数据集的快照(Read write)用于用户测试使用。在快照上的改变不会影响原有数据集。
4>.灾难恢复:

  只读快照可以被用于创建一个一致的时间点镜像用于拷贝到远程站点作灾备冗余。
  

二.基本语法

1>.hdfs dfsadmin -allowSnapshot <path> 

  功能描述:开启指定目录的快照功能。通过开启快照功能,那么该目录就成为了一个snapshottable的目录。snapshottable下存储的snapshots 最多为65535个,保存在该目录的.snapshot下。

2>.hdfs dfsadmin -disallowSnapshot <path> 

  功能描述:禁用指定目录的快照功能,默认所有的目录都是禁用状态。

3>.hdfs dfs -createSnapshot <path> 

  功能描述:对目录创建快照。

4>.hdfs dfs -createSnapshot <path>   <snapshotName>

  功能描述:对目录创建时指定快照名称。

5>.hdfs dfs -renameSnapshot <path>  <oldName>  <newName> 

  功能描述:重命名快照。

6>.hdfs lsSnapshottableDir

  功能描述:列出当前用户所有快照目录。

7>.hdfs snapshotDiff <path1>  <path2> 

  功能描述:比较两个快照目录的不同之处。

8>.hdfs dfs -deleteSnapshot  <path>  <snapshotName>

  功能描述:删除快照。

二.快照的基本用法

1>.开启指定目录的快照功能

[root@node101.yinzhengjie.org.cn ~]# hdfs dfsadmin -allowSnapshot /yinzhengjie
Allowing snaphot on /yinzhengjie succeeded
[root@node101.yinzhengjie.org.cn ~]# 

2>.禁用指定目录的快照功能

[root@node101.yinzhengjie.org.cn ~]# hdfs dfsadmin -disallowSnapshot /yinzhengjie         
Disallowing snaphot on /yinzhengjie succeeded
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfsadmin -disallowSnapshot /yinzhengjie
disallowSnapshot: The directory /yinzhengjie has snapshot(s). Please redo the operation after removing all the snapshots.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfsadmin -disallowSnapshot /yinzhengjie          #注意,你已经在开启快照功能的目录创建了快照,是无法禁用的哟!需要先删除快照!

3>.对目录创建快照(创建快照必须得提前开启快照功能)

[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -createSnapshot /yinzhengjie
Created snapshot /yinzhengjie/.snapshot/s20190416-200926.754
[root@node101.yinzhengjie.org.cn ~]# 

4>.指定名称创建快照

[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -createSnapshot /yinzhengjie jason-snapshot
Created snapshot /yinzhengjie/.snapshot/jason-snapshot
[root@node101.yinzhengjie.org.cn ~]# 

5>.重命名快照

[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot                              #查看/yinzhengjie目录存在的快照信息
Found 2 items
drwxr-xr-x   - root supergroup          0 2019-04-16 20:11 /yinzhengjie/.snapshot/jason-snapshot
drwxr-xr-x   - root supergroup          0 2019-04-16 20:09 /yinzhengjie/.snapshot/s20190416-200926.754
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -renameSnapshot /yinzhengjie s20190416-200926.754 yzj.snapshot        #我们将/yinzhengjie目录下的s20190416-200926.754这个快照进行重命名为yzj.snapshot
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot                                            #再次查看/yinzhengjie目录存在的快照信息,我们观察到快照的确被我们重命名成功啦!
Found 2 items
drwxr-xr-x   - root supergroup          0 2019-04-16 20:11 /yinzhengjie/.snapshot/jason-snapshot
drwxr-xr-x   - root supergroup          0 2019-04-16 20:09 /yinzhengjie/.snapshot/yzj.snapshot
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

6>.列出当前用户所有可快照目录 

[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/output2019
Found 5 items
-rw-r--r--   2 root supergroup       2523 2019-04-16 18:49 /yinzhengjie/output2019/CentOS-Base.repo
drwxr-xr-x   - root supergroup          0 2019-04-16 18:49 /yinzhengjie/output2019/back
drwxr-xr-x   - root supergroup          0 2019-04-16 18:49 /yinzhengjie/output2019/default
-rw-r--r--   2 root supergroup       1050 2019-04-16 18:49 /yinzhengjie/output2019/epel-testing.repo
-rw-r--r--   2 root supergroup        951 2019-04-16 18:49 /yinzhengjie/output2019/epel.repo
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/output2019
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/output2019/default
Found 7 items
-rw-r--r--   2 root supergroup       1664 2019-04-16 18:49 /yinzhengjie/output2019/default/CentOS-Base.repo
-rw-r--r--   2 root supergroup       1309 2019-04-16 18:49 /yinzhengjie/output2019/default/CentOS-CR.repo
-rw-r--r--   2 root supergroup        649 2019-04-16 18:49 /yinzhengjie/output2019/default/CentOS-Debuginfo.repo
-rw-r--r--   2 root supergroup        630 2019-04-16 18:49 /yinzhengjie/output2019/default/CentOS-Media.repo
-rw-r--r--   2 root supergroup       1331 2019-04-16 18:49 /yinzhengjie/output2019/default/CentOS-Sources.repo
-rw-r--r--   2 root supergroup       5701 2019-04-16 18:49 /yinzhengjie/output2019/default/CentOS-Vault.repo
-rw-r--r--   2 root supergroup        314 2019-04-16 18:49 /yinzhengjie/output2019/default/CentOS-fasttrack.repo
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/output2019/default
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cp -d /yinzhengjie/output2019 /output2019 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2019-04-17 12:01 /output2019
drwx------   - root supergroup          0 2019-04-16 18:16 /tmp
drwxr-xr-x   - root supergroup          0 2019-04-16 20:11 /yinzhengjie
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /output2019 
Found 5 items
-rw-r--r--   2 root supergroup       2523 2019-04-17 12:01 /output2019/CentOS-Base.repo
drwxr-xr-x   - root supergroup          0 2019-04-17 12:01 /output2019/back
drwxr-xr-x   - root supergroup          0 2019-04-17 12:01 /output2019/default
-rw-r--r--   2 root supergroup       1050 2019-04-17 12:01 /output2019/epel-testing.repo
-rw-r--r--   2 root supergroup        951 2019-04-17 12:01 /output2019/epel.repo
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cp -d /yinzhengjie/output2019 /output2019
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /output2019/default
Found 7 items
-rw-r--r--   2 root supergroup       1664 2019-04-17 12:01 /output2019/default/CentOS-Base.repo
-rw-r--r--   2 root supergroup       1309 2019-04-17 12:01 /output2019/default/CentOS-CR.repo
-rw-r--r--   2 root supergroup        649 2019-04-17 12:01 /output2019/default/CentOS-Debuginfo.repo
-rw-r--r--   2 root supergroup        630 2019-04-17 12:01 /output2019/default/CentOS-Media.repo
-rw-r--r--   2 root supergroup       1331 2019-04-17 12:01 /output2019/default/CentOS-Sources.repo
-rw-r--r--   2 root supergroup       5701 2019-04-17 12:01 /output2019/default/CentOS-Vault.repo
-rw-r--r--   2 root supergroup        314 2019-04-17 12:01 /output2019/default/CentOS-fasttrack.repo
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /output2019/default
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2019-04-17 12:01 /output2019
drwx------   - root supergroup          0 2019-04-16 18:16 /tmp
drwxr-xr-x   - root supergroup          0 2019-04-16 20:11 /yinzhengjie
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
[root@node101.yinzhengjie.org.cn ~]# hdfs dfsadmin -allowSnapshot /output2019
Allowing snaphot on /output2019 succeeded
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfsadmin -allowSnapshot /output2019
[root@node101.yinzhengjie.org.cn ~]# hdfs lsSnapshottableDir 
drwxr-xr-x 0 root supergroup 0 2019-04-17 12:01 0 65536 /output2019
drwxr-xr-x 0 root supergroup 0 2019-04-16 20:11 2 65536 /yinzhengjie
[root@node101.yinzhengjie.org.cn ~]# 

7>.比较两个快照目录的不同之处

[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot 
Found 2 items
drwxr-xr-x   - root supergroup          0 2019-04-16 20:11 /yinzhengjie/.snapshot/jason-snapshot
drwxr-xr-x   - root supergroup          0 2019-04-16 20:09 /yinzhengjie/.snapshot/s20190416-200926.754
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot          #查看hdfs中的/yinzhengjie目录相爱存在的快照名称
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie
Found 7 items
-rw-r--r--   2 root supergroup       3124 2019-04-16 18:10 /yinzhengjie/edits.xml
-rw-r--r--   2 root supergroup       1264 2019-04-16 18:10 /yinzhengjie/fsimage.xml
drwxr-xr-x   - root supergroup          0 2019-04-16 18:10 /yinzhengjie/krb5.conf.d
drwxr-xr-x   - root supergroup          0 2019-04-16 18:43 /yinzhengjie/output
drwxr-xr-x   - root supergroup          0 2019-04-16 18:49 /yinzhengjie/output2019
-rw-r--r--   2 root supergroup          3 2019-04-16 18:10 /yinzhengjie/seen_txid
drwxr-xr-x   - root supergroup          0 2019-04-16 18:19 /yinzhengjie/yum.repos.d
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs snapshotDiff /yinzhengjie/ . .snapshot/jason-snapshot                #对比/yinzhengjie目录和对该目录做对快照jason-snapshot,很明显发现没有任何差异!
Difference between current directory and snapshot jason-snapshot under directory /yinzhengjie:

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -rm -R /yinzhengjie/krb5.conf.d  /yinzhengjie/output /yinzhengjie/output2019 /yinzhengjie/yum.repos.d      #我们删除/yinzhengjie这个目录的数据
Deleted /yinzhengjie/krb5.conf.d
Deleted /yinzhengjie/output
Deleted /yinzhengjie/output2019
Deleted /yinzhengjie/yum.repos.d
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/                                        #确认是否删除成功!
Found 3 items
-rw-r--r--   2 root supergroup       3124 2019-04-16 18:10 /yinzhengjie/edits.xml
-rw-r--r--   2 root supergroup       1264 2019-04-16 18:10 /yinzhengjie/fsimage.xml
-rw-r--r--   2 root supergroup          3 2019-04-16 18:10 /yinzhengjie/seen_txid
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot                                   #查看/yinzhengjie目录中一句存在的快照,以及创建快照的时间,名称等信息!
Found 2 items
drwxr-xr-x   - root supergroup          0 2019-04-16 20:11 /yinzhengjie/.snapshot/jason-snapshot
drwxr-xr-x   - root supergroup          0 2019-04-16 20:09 /yinzhengjie/.snapshot/s20190416-200926.754
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hdfs snapshotDiff /yinzhengjie/ . .snapshot/jason-snapshot                                   #再次对比/yinzhengjie目录和其对应的快照,发现这次有变化啦!
Difference between current directory and snapshot jason-snapshot under directory /yinzhengjie:
M       .
+       ./krb5.conf.d
+       ./output
+       ./output2019
+       ./yum.repos.d

[root@node101.yinzhengjie.org.cn ~]# 

 

8>.恢复快照

[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/
Found 3 items
-rw-r--r--   2 root supergroup       3124 2019-04-16 18:10 /yinzhengjie/edits.xml
-rw-r--r--   2 root supergroup       1264 2019-04-16 18:10 /yinzhengjie/fsimage.xml
-rw-r--r--   2 root supergroup          3 2019-04-16 18:10 /yinzhengjie/seen_txid
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/
[root@node101.yinzhengjie.org.cn ~]# hdfs snapshotDiff /yinzhengjie/ . .snapshot/jason-snapshot                      #先查看当前目录和快照之间的差距
Difference between current directory and snapshot jason-snapshot under directory /yinzhengjie:
M       .
+       ./krb5.conf.d
+       ./output
+       ./output2019
+       ./yum.repos.d

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cp -ptopax /yinzhengjie/.snapshot/jason-snapshot/krb5.conf.d /yinzhengjie/       #其实恢复快照的思路就是根据对比当前目录和之前快照的差异,对现有的目录进行相应的操作
[root@node101.yinzhengjie.org.cn ~]#  
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cp -ptopax /yinzhengjie/.snapshot/jason-snapshot/output /yinzhengjie/             
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cp -ptopax /yinzhengjie/.snapshot/jason-snapshot/output2019 /yinzhengjie/       
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cp -ptopax /yinzhengjie/.snapshot/jason-snapshot/yum.repos.d /yinzhengjie/           
[root@node101.yinzhengjie.org.cn ~]#  
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/
Found 7 items
-rw-r--r--   2 root supergroup       3124 2019-04-16 18:10 /yinzhengjie/edits.xml
-rw-r--r--   2 root supergroup       1264 2019-04-16 18:10 /yinzhengjie/fsimage.xml
drwxr-xr-x   - root supergroup          0 2019-04-16 18:10 /yinzhengjie/krb5.conf.d
drwxr-xr-x   - root supergroup          0 2019-04-16 18:43 /yinzhengjie/output
drwxr-xr-x   - root supergroup          0 2019-04-16 18:49 /yinzhengjie/output2019
-rw-r--r--   2 root supergroup          3 2019-04-16 18:10 /yinzhengjie/seen_txid
drwxr-xr-x   - root supergroup          0 2019-04-16 18:19 /yinzhengjie/yum.repos.d
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/

9>.快照的删除操作

[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot
Found 2 items
drwxr-xr-x   - root supergroup          0 2019-04-16 20:11 /yinzhengjie/.snapshot/jason-snapshot
drwxr-xr-x   - root supergroup          0 2019-04-16 20:09 /yinzhengjie/.snapshot/yzj.snapshot
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -deleteSnapshot /yinzhengjie/ jason-snapshot
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot                  
Found 1 items
drwxr-xr-x   - root supergroup          0 2019-04-16 20:09 /yinzhengjie/.snapshot/yzj.snapshot
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

三.验证创建快照后是否产生新的文件

1>.上传测试数据到hdfs集群中到指定目录并查看某文件到存储信息

[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/
Found 3 items
-rw-r--r--   2 root supergroup       3124 2019-04-17 16:51 /yinzhengjie/edits.xml
-rw-r--r--   2 root supergroup       1264 2019-04-17 16:51 /yinzhengjie/fsimage.xml
-rw-r--r--   2 root supergroup          3 2019-04-17 16:51 /yinzhengjie/seen_txid
[root@node101.yinzhengjie.org.cn ~]# 

2>.创建快照并查看快照中的文件存储信息(我们最好和上面查看到文件名称一致,这样相对来说更具有可比性) 

[root@node101.yinzhengjie.org.cn ~]# hdfs dfsadmin -allowSnapshot /yinzhengjie
Allowing snaphot on /yinzhengjie succeeded
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -createSnapshot /yinzhengjie yzj-snapshot  
Created snapshot /yinzhengjie/.snapshot/yzj-snapshot
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot               
Found 1 items
drwxr-xr-x   - root supergroup          0 2019-04-17 16:53 /yinzhengjie/.snapshot/yzj-snapshot
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot/yzj-snapshot
Found 3 items
-rw-r--r--   2 root supergroup       3124 2019-04-17 16:51 /yinzhengjie/.snapshot/yzj-snapshot/edits.xml
-rw-r--r--   2 root supergroup       1264 2019-04-17 16:51 /yinzhengjie/.snapshot/yzj-snapshot/fsimage.xml
-rw-r--r--   2 root supergroup          3 2019-04-17 16:51 /yinzhengjie/.snapshot/yzj-snapshot/seen_txid
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

3>.往存储的文件追加一些数据 

[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot/yzj-snapshot/seen_txid 
-rw-r--r--   2 root supergroup          3 2019-04-17 16:51 /yinzhengjie/.snapshot/yzj-snapshot/seen_txid
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/.snapshot/yzj-snapshot/
Found 3 items
-rw-r--r--   2 root supergroup       3124 2019-04-17 16:51 /yinzhengjie/.snapshot/yzj-snapshot/edits.xml
-rw-r--r--   2 root supergroup       1264 2019-04-17 16:51 /yinzhengjie/.snapshot/yzj-snapshot/fsimage.xml
-rw-r--r--   2 root supergroup          3 2019-04-17 16:51 /yinzhengjie/.snapshot/yzj-snapshot/seen_txid
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/
Found 3 items
-rw-r--r--   2 root supergroup       3124 2019-04-17 16:51 /yinzhengjie/edits.xml
-rw-r--r--   2 root supergroup       1264 2019-04-17 16:51 /yinzhengjie/fsimage.xml
-rw-r--r--   2 root supergroup          3 2019-04-17 16:51 /yinzhengjie/seen_txid
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cat /yinzhengjie/seen_txid
51
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cat /yinzhengjie/.snapshot/yzj-snapshot/seen_txid
51
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat blog.txt 
https://www.cnblogs.com/yinzhengjie/
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -appendToFile blog.txt  /yinzhengjie/seen_txid
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cat /yinzhengjie/.snapshot/yzj-snapshot/seen_txid
51
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# hdfs dfs -cat /yinzhengjie/seen_txid
51
https://www.cnblogs.com/yinzhengjie/
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

  我们发现被快照的文件的内容并没有变化,而实际存储的块却在发生变化哟!但是由于文件较小,还未达到128M,因此存储ID并没有发生变化!

4>.小结快照的特点

.生成隐藏目录(“.snapshot”)
    创建快照时,会在床快快照的目录下生成一个“.snapshot”的隐藏目录,该目录下保存了一个子目录,这个子目录名称就是快照的名称,该目录下存放的都是创建快照时间节点的数据。

.快照并不产生新的文件
    这个不产生新的文件指的是不完全克隆一份数据出来,而是将数据都指向了同一个存储的ID啦,从上图我们可以很明显的看出来。

.修改源文件跟快照无关
    当我们源文件时,快照中保存的数据并不会受到影响,快照保存的诗句还是当时创建快照的时间节点数据。


原文地址:https://www.cnblogs.com/yinzhengjie/p/10714315.html