ZFS - how to retrieve accidentally removed files
(please note that we just started to roll out this feature in 2021-04
and your /work
directory may not yet allow this!)
Imagine, you accidentally deleted a few files in your /work
directory and would like to restore these.
If this happened just recently and the files have been present in your
/work
directory for some time, chances are quite high, that the
storage servers in the background created a read-only snapshot of your
data and you can simply copy these files back. To do so, please
investigate the “hidden” directory ~/.zfs/snapshot
!
For example, imagine you deleted the project directory
~/projects/phd
by accident. You can then go into said directory by
issuing cd ~/.zfs/snapshot
and check what directories there are via
ls -l
:
total 0
drwxrwxrwx 1 root root 0 Apr 7 08:53 autosnap_2021-04-07_01:00:08_daily
drwxrwxrwx 1 root root 0 Apr 7 08:53 autosnap_2021-04-07_03:00:07_hourly
drwxrwxrwx 1 root root 0 Apr 7 08:53 autosnap_2021-04-07_04:30:07_hourly
drwxrwxrwx 1 root root 0 Apr 7 08:53 autosnap_2021-04-07_06:00:07_hourly
In each of these directories, you will find your whole /work
directory how it looked like when the snapshot was taken (time stamp
in the directory name).
You can look everywhere in there and simply copy any file you want to
have back into your current /work
, e.g. if you decided you want to
have the most recent state recovered, you could simply use cp -a
autosnap_2021-04-07_06:00:07_hourly/projects/phd ~/projects/phd
.
A few notes of caution:
- Files you just created and deleted again are most likely not present in any snapshot as these are only taken every few hours!
- Snapshots will be renamed or removed periodically as they require space to record any changes between the states of the file system when the snapshot was taken and the current one. Thus, if you want to act, act early!
- If these snapshots are too recent and your accident happened some
time back, please speak send an email to
atlas_admin@aei.mpg.de
as soon as possible, as we may have those files still on a backup machine you cannot access. But as backup space is also limited they are not kept indefinitely, thus please act fast!