Introduction
The workshop's live schedule has been cancelled accidentally and its contact file is missing. Two native snapshots remain, but the newer one contains an unapproved draft. The team needs the approved programme back while retaining a later Paper Folding session and the unchanged access note.
This independent environment contains all required data; it does not use files from the previous lab. You should know the snapshot paths and ordinary HDFS operations practiced there. You will choose a business-appropriate version, restore two named objects, and test real shared consumption. Use Terminal throughout. The author estimates 45 minutes, including reading and ordinary corrections.
Choose the Approved Version and Restore the Schedule
In this step, you will compare two recovery points and restore only the schedule that matches the public programme. Open Terminal and start in the local workspace:
cd /home/labex/project
The public programme requires room A to offer Printmaking and room B to offer Bookbinding. Its visitor contact is visitors@example.test. A draft is not approved merely because it is newer. The later live file late-session.csv adds room C, Paper Folding, and must remain. Keep notes.txt, all supplied snapshots, ordinary ownership, and read-only sharing too. Do not rebuild the whole directory.
List the live files and native recovery points:
hdfs dfs -ls /user/labex/snapshot-workshop/team
hdfs dfs -ls /user/labex/snapshot-workshop/team/.snapshot
The live schedule exists, but contacts.csv is missing. The snapshot names are morning-approved and afternoon-draft. Compare their actual schedules; a name alone is not enough evidence:
hdfs dfs -cat /user/labex/snapshot-workshop/team/.snapshot/morning-approved/schedule.csv
hdfs dfs -cat /user/labex/snapshot-workshop/team/.snapshot/afternoon-draft/schedule.csv
The morning version has Printmaking and Bookbinding. The afternoon version changes room A to Draft Planning. Read the live schedule:
hdfs dfs -cat /user/labex/snapshot-workshop/team/schedule.csv
It contains A,CANCELLED. The correct recovery point is therefore the approved morning version, rather than the newest snapshot. The missing file can be recovered separately; there is no reason to replace the entire tree.
HDFS -cp copies between HDFS paths. The -p option preserves the source's timestamps, owner, group, and permission mode; -f allows replacing the existing named destination. Here both paths stay inside the course folder, and you own the destination:
hdfs dfs -cp -p -f /user/labex/snapshot-workshop/team/.snapshot/morning-approved/schedule.csv /user/labex/snapshot-workshop/team/schedule.csv
Read the recovered schedule through the actual analyst identity:
sudo -u analyst /usr/local/bin/hdfs dfs -cat /user/labex/snapshot-workshop/team/schedule.csv
It now lists Printmaking and Bookbinding. Confirm that the later live addition is still available:
hdfs dfs -cat /user/labex/snapshot-workshop/team/late-session.csv
It still lists Paper Folding. If a copy reports a missing source, list that exact snapshot directory and correct the source path; do not create an empty replacement. If you accidentally copy the draft schedule, compare both historical versions again and repeat only the correct named-file copy. The -f copy can safely replace that one wrong version without touching the new session.
Restore the Missing Contact and Keep Sharing Read-Only
In this step, you will recover the deleted contact, consume the complete programme, and test the access boundaries. Continue in the same Terminal.
Compare both historical contact files before selecting one:
hdfs dfs -cat /user/labex/snapshot-workshop/team/.snapshot/morning-approved/contacts.csv
hdfs dfs -cat /user/labex/snapshot-workshop/team/.snapshot/afternoon-draft/contacts.csv
The morning version contains the required visitors@example.test; the draft uses a temporary address. Copy the approved historical file back into its missing live path. No overwrite option is needed for a missing destination:
hdfs dfs -cp -p /user/labex/snapshot-workshop/team/.snapshot/morning-approved/contacts.csv /user/labex/snapshot-workshop/team/contacts.csv
If that destination already exists after a completed copy, read it first. When its contents are wrong, use the same narrowly scoped -cp -p -f pattern from Step 1 with the approved contact source and that one destination. Do not delete the whole folder to resolve an existing-file error.
Read the recovered contact as the shared analyst:
sudo -u analyst /usr/local/bin/hdfs dfs -cat /user/labex/snapshot-workshop/team/contacts.csv
Read the unchanged note and the later session with the same real identity:
sudo -u analyst /usr/local/bin/hdfs dfs -cat /user/labex/snapshot-workshop/team/notes.txt
sudo -u analyst /usr/local/bin/hdfs dfs -cat /user/labex/snapshot-workshop/team/late-session.csv
The note keeps the quiet room open, and the later session is Paper Folding. These actual reads consume the retained data; a local download alone would not repair this HDFS programme.
Inspect ownership and modes on the directory and every live file. -ls -d displays the directory entry itself; quoting the * lets HDFS, rather than your local shell, select its file paths:
hdfs dfs -ls -d /user/labex/snapshot-workshop/team '/user/labex/snapshot-workshop/team/*'
The supplied directory uses 750, and its files use 640, owned by labex and grouped as bigdata. Those modes allow group reading and traversal without group writing. The directory matters too: a group that could write it could remove or replace files even if each file were read-only.
Use the prepared HDFS -test -w operation to ask whether an identity has write access. It does not attempt a write. The next command is expected to return nonzero with no output because the analyst must not modify the team directory:
sudo -u analyst /usr/local/bin/hdfs dfs -test -w /user/labex/snapshot-workshop/team
This intentional nonzero result is success for the boundary test; continue. An unrelated identity must not be able to read private shared files. Both of the next commands are expected to fail with Permission denied:
sudo -u nobody /usr/local/bin/hdfs dfs -cat /user/labex/snapshot-workshop/team/schedule.csv
sudo -u nobody /usr/local/bin/hdfs dfs -cat /user/labex/snapshot-workshop/team/contacts.csv
If an unintended permission change caused a denial for the analyst, restore only the affected course object: -chgrp bigdata assigns the sharing group, -chmod 750 applies to the team directory, and -chmod 640 applies to a named live file. For example, the following complete commands repair just the contact and team directory:
hdfs dfs -chgrp bigdata /user/labex/snapshot-workshop/team/contacts.csv
hdfs dfs -chmod 640 /user/labex/snapshot-workshop/team/contacts.csv
hdfs dfs -chmod 750 /user/labex/snapshot-workshop/team
Finally list the complete live programme and the retained recovery points:
hdfs dfs -ls /user/labex/snapshot-workshop/team
hdfs dfs -ls /user/labex/snapshot-workshop/team/.snapshot
All four live files and both original snapshots remain. You recovered the two affected objects without discarding newer work. A valid alternative can remove one known damaged live file and copy its historical version back, provided it preserves the same contents and sharing. The task does not require a particular command spelling or editor.
Summary
You chose the approved historical version by its business contents, restored a changed file and a missing file, and retained both later work and original snapshots. Actual analyst reads and unrelated-user denials demonstrated the shared result. A snapshot on the same HDFS remains a recovery aid, not an independent backup or a whole-storage disaster-recovery guarantee.



