Saturday 2 January 2016

Hadoop: HDFS: snapshots

Hadoop provides a facility to take snap shot for a file/directory in HDFS. System administrators use snapshots, to perform data backup and recovery in case of system failures, use snapshots. You can take snapshot of a file system (or) sub tree of the file system.

Snapshot file records block list and file size, it won’t copy the data in blocks.

How to take snapshot of a directory
To take snapshot of a directory, first you have to make that directory as snapshottable.

How to make a directory snapshottable
Use following command to make a directory snapshottable. path represents the path of the snapshottable directory. A snapshottable directory is able to accommodate 65,536 simultaneous snapshots.

hdfs dfsadmin -allowSnapshot <path>  

$ hdfs dfsadmin -allowSnapshot /user/harikrishna_gurram
Allowing snaphot on /user/harikrishna_gurram succeeded

Is there any limit on Number of snapshottable directories?
There is no limit on number of snapshottable directories.

How to create a snapshot?
Use following command to create snapshot.

hdfs dfs -createSnapshot <path> [<snapshotName>]

$ hdfs dfs -createSnapshot /user/harikrishna_gurram snapshot1
Created snapshot /user/harikrishna_gurram/.snapshot/snapshot1

How to rename snapshot?
Use following command to rename snapshot.

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

path: The path of the snapshottable directory.
oldName: The old snapshot name.
newName: The new snapshot name.

$ hdfs dfs -renameSnapshot /user/harikrishna_gurram snapshot1 snapshot-new

Above command rename snapshot1 to snapshot-new.

How to get all snapshottable directories?
Use command ‘hdfs lsSnapshottableDir’ to get all snapshottable directories.

$ hdfs lsSnapshottableDir
drwxr-xr-x 0 harikrishna_gurram supergroup 0 2015-06-18 21:50 1 65536 /user/harikrishna_gurram

How to Delete snapshot?
Use command ‘hdfs dfs -deleteSnapshot <path> <snapshotName>
‘ to delete snapshot.

path: The path of the snapshottable directory.
snapshotName: The snapshot name.

$ hdfs dfs -deleteSnapshot /user/harikrishna_gurram snapshot-new

Above command delete snapshot snapshot-new.

How to disallow snapshots
Use following command to disallow snapshots on a directory. All snapshots of the directory must be deleted before disallowing snapshots.

hdfs dfsadmin -disallowSnapshot <path>

$ hdfs dfsadmin -disallowSnapshot /user/harikrishna_gurram
Disallowing snaphot on /user/harikrishna_gurram succeeded
$
$ hdfs dfs -createSnapshot /user/harikrishna_gurram snapshot1
createSnapshot: Directory is not a snapshottable directory: /user/harikrishna_gurram

Referred Articles



Previous                                                 Next                                                 Home

No comments:

Post a Comment