Restoring a File

unrm

If the file was removed with the "rm" command, you may restore it with the "unrm" command:‎

cd directory_of_removed_file
 unrm file_name

the command "rm" is aliased to "mv" ("mv file_name ~/../TrashCan/user_mame"), so the file is not deleted but rather moved to the TrashCan folder. The "unrm" command moves it back.‎

snapshots

If the removed file is not there or you edited it and need a previous version, you will likely find it in one of the snapshots taken by the file server. A snapshot is an image of the file system that the file server is configured to take several times during the day, during the week and during the month.‎

In your home directory and in every sub-directory of it, there is a hidden directory .snapshot that you can enter and list:‎

cd .snapshot
ls
hourly.0 hourly.2 hourly.4 nightly.0 nightly.2 weekly.0 weekly.2
hourly.1 hourly.3 hourly.5 nightly.1 nightly.3 weekly.1 weekly.3

You will find there directories for each of the snapshots and inside them the files as they were at the time the snapshots were taken. The files there are read-only so you may need to copy them.‎‎

nrestore

The script "nrestore" makes listing and restoring files from .snapshot easy, usage:‎

nrestore [options] filename

 options:‎
 ‎-h or --help        Print help message
 l or --list        Only list the old versions‎-
 ‎-o or --override    Override an existing file

Examples

:List available versions of pine's saved-messages file

nrestore --list Mail/saved-messages
 ------------------ I n f o r m t i o n    s t a r t -------------------
Current version of Mail/saved-messages:‎
 Version 0: -rw------- 1 user1 grp 502 Sep 1 16:57 Mail/saved-messages
------------------ I n f o r m t i o n    e n d     -------------------
Can restore these versions:‎
 Version 1: -rw------- 1 user1 grp 150139 Aug 5 19:42 Mail/saved-messages
 Version 2: -rw------- 1 user1 grp 574607 Aug 26 21:50 Mail/saved-messages
 Version 3: -rw------- 1 user1 grp 579988 Aug 30 22:38 Mail/saved-messages
Version 4: -rw------- 1 user1 grp 502 Sep 1 16:57 Mail/saved-messages

Restore yesterday's version of saved-messages:‎

nrestore Mail/saved-messages
    ------------------ I n f o r m t i o n    s t a r t -------------------
    Current version of Mail/saved-messages:‎
    Version 0: -rw------- 1 user1 grp 502 Sep 1 16:57 Mail/saved-messages
    ------------------ I n f o r m t i o n    e n d     -------------------
    Can restore these versions:‎
    Version 1: -rw------- 1 user1 grp 150139 Aug 5 19:42 Mail/saved-messages
    Version 2: -rw------- 1 user1 grp 574607 Aug 26 21:50 Mail/saved-messages
    Version 3: -rw------- 1 user1 grp 579988 Aug 30 22:38 Mail/saved-messages
    Version 4: -rw------- 1 user1 grp 502 Sep 1 16:57 Mail/saved-messages
    Choose version:   3
    Mail/saved-messages: exists, Choose O)verride M)ove aside or C)ancel    M
    Moving Mail/saved-messages to Mail/saved-messages.save
    Restoring Mail/saved-messages...done

Note that the script asked for version number and also was careful not to clobber an existing file without notice. Nrestore moved aside the current version to .save before restoring:‎

ls -l saved-messages saved-messages.save
 ‎-rw------- 1 user1 grp 579988 Aug 30 22:38 saved-messages
 ‎-rw------- 1 user1 grp    502 Sep  1 16:57 saved-messages.save