InterviewSolution
| 1. |
What is HDFS Snapshot how it helps you to recover |
|
Answer» FUNDAMENTALLY snapshot means taking a Xerox copy of the content from the entire file-level or subtree of the file system until a certain time and its read-only. Snapshot is handling data corruption of user or application and accidental delete. It is always quicker to recovery from snapshot as compared to restore of the whole FSImage and it is easy to create a snapshot of the important directory before changing anything to it. Snapshot can be taken on any directory once you can be marked as "snapshot table", to doing the same you have to PROVIDE the command as "Hdfs dfsadmin -allowSnapshot <Path>".Once the snapshot table directory has been created than under that, subdirectory has been created as .snapshot, It is the place where snapshots are stored. There is no limit on the number of snapshot table directories, any number of a directory can create and snapshot table directory can contain 65536 snapshots simultaneously. We can change the name of a snapshot or we can use the default one (based on timestamp: "s'yyyyMMdd-HHmmss.SSS"). If there are any snapshots in the snapshot table directory then neither you can delete the directory nor rename the directory. deleting the snapshot table directory you have to delete all the snapshots under that directory. during the upgrading version of HDFS, ".snapshot" need to first be renamed or deleted to avoid conflicting with the reserved path. Snapshots are easily created with hdfs dfsadmin command, Please find the few commands related to snapshot. a. # Create directory structure hdfs dfs -mkdir /my_dir_bibhu b. # Allow snapshots creation for /my_dir_bibhu hdfs dfsadmin -allowSnapshot /my_dir_bibhu Allowing snaphot on /my_dir_bibhu SUCCEEDED c. # Create the first snapshot hdfs dfs -createSnapshot /my_dir_bibhu snaptest1 Created snapshot /my_dir_bibhu/.snapshot/snaptest1 d. # .snapshot can be read directly using below command hdfs dfs -ls /my_dir_bibhu/.snapshot Found 1 items drwxr-xr-x - bibhu supergroup 0 2016-12-03 09:52 /my_dir/.snapshot/snaptest1 e. # Create new snapshot - this time for directory containing a file hdfs dfs -createSnapshot /my_dir_bibhu snaptest2 Created snapshot /my_dir_bibhu/.snapshot/snaptest2 f. # This command serves to COMPARE snapshots hdfs snapshotDiff /my_dir_bibhu .snapshot/snaptest1 .snapshot/snaptest2 g. # Restore snapshot directory to a temporary place and check if file is there or not hdfs dfs -cp /my_dir_bibhu/.snapshot/snaptest2 /tmp/dir_from_snapshot hdfs dfs -ls /dir_from_snapshot |
|