在2.x 终于实现了快照
设置一个目录为可快照:
hdfs dfsadmin -allowSnapshot <path>
取消目录可快照
hdfs dfsadmin -disallowSnapshot <path>
生成快照
hdfs dfs -createSnapshot <path> [<snapshotName>]
删除快照
hdfs dfs -deleteSnapshot <path> <snapshotName>
[hadoop@hadoop1 hadoop-2.5.0]$ ./bin/hdfs dfsadmin -allowSnapshot / Allowing snaphot on / succeeded [hadoop@hadoop1 hadoop-2.5.0]$ ./bin/hdfs dfs -put ../test1.txt /test1.txt [hadoop@hadoop1 hadoop-2.5.0]$ ./bin/hdfs dfs -ls / Found 1 items -rw-r--r-- 1 hadoop supergroup 12 2014-08-31 23:26 /test1.txt [hadoop@hadoop1 hadoop-2.5.0]$ ./bin/hdfs dfs -createSnapshot / Created snapshot /.snapshot/s20140831-232654.464 [hadoop@hadoop1 hadoop-2.5.0]$ ./bin/hdfs dfs -ls /.snapshot Found 2 items drwxr-xr-x - hadoop supergroup 0 2014-08-31 23:24 /.snapshot/s20140831-232445.185 drwxr-xr-x - hadoop supergroup 0 2014-08-31 23:26 /.snapshot/s20140831-232654.464 #恢复快照 [hadoop@hadoop1 hadoop-2.5.0]$ ./bin/hdfs dfs -mkdir /tmp [hadoop@hadoop1 hadoop-2.5.0]$ ./bin/hdfs dfs -cp /.snapshot/s20140831-232654.464 /tmp [hadoop@hadoop1 hadoop-2.5.0]$ ./bin/hdfs dfs -cat /tmp/s20140831-232654.464/test1.txt hello world
其他快照操作
列出所有可快照目录
hdfs lsSnapshottableDir
比较快照直接的差异
hdfs snapshotDiff <path> <fromSnapshot> <toSnapshot>