1. Does cp just restore the inode? No. When you use the cp command, the system does not simply "re-link" the old metadata or inode. Instead, it creates brand-new files.
The cp command reads the data blocks from the snapshot and writes them to the target directory as new blocks.
The resulting files will have new Inode IDs, new timestamps, and your current user as the owner.
It is a heavy operation because it physically duplicates the data on the disk (until the background deduplication/hard-linking handles it, depending on the underlying filesystem).
2. What happens to unmodified files? By default, the hdfs dfs -cp command will overwrite the existing files in the target directory even if they haven't changed.
It does not perform a "diff" or a check to see if the content is identical.
It will read the file from the snapshot and overwrite the live file, resulting in unnecessary I/O and network traffic.
3. Are those files skipped? No. Using cp with a wildcard (*) will force the system to attempt to copy everything. If a file with the same name exists in the target, the command will fail with a "File exists" error unless you use specific flags (like -f in some environments) or delete the target first.
➤ The "Better" Way (Recommended Fix)
If the goal is to only restore metadata or only update files that actually changed, using cp is inefficient. Instead, suggest the following:
A. Use distcp with the -update flag
distcp is much smarter. It compares the source (snapshot) and the target (live) and only copies files that have different sizes or checksums.
hadoop distcp -update -ptag <snaproot>/.snapshot/<name>/ <target_dir>/
-update: Only copies files if the size/checksum differs.
-ptag: Preserves the original permissions, timestamps, and ACLs.
B. Manual "Restore" (Metadata only)
If you only changed permissions (chmod) and didn't touch the data, the most efficient "restore" isn't a copy at all—it’s simply running chmod again to set them back.
Snapshots are great for insurance, but they are most useful for data recovery, not metadata undoing.