HowTos:Restore files from snapshots on Linux from home directory on Math file server

From CompudocWiki
Revision as of 21:18, 16 October 2005 by Plazonic (talk | contribs) (language tweak)
Jump to navigation Jump to search

These directions describe how to restore recently deleted files or older copies of recently modified files located on the Math/PACM fileserver, e.g. in your home directory. These instructions do not apply if you are trying to restore files located on your own laptop or desktop.

Snapshot description

In order to restore files deleted or changed within last few days you can use snapshots, as long as the file you are looking for is located somewhere under your home directory. A snapshot is a read-only image of the entire file system (home directories) that reflects the state of the file system at the time the snapshot was created.

Currently, there are four daily and eleven hourly snapshots. Daily snapshots are created at midnight of every day and four of them are kept, e.g. if you are looking at snapshots at 3pm of Friday you will find daily snapshots created at midnight of previous Monday, Tuesday, Wednesday and Thursday - called, respectively, nightly.3, nightly.2, nightly.1 and nightly.0.

Hourly snapshots are created every two hours, except at midnight, and up to 11 are kept. Hourly snapshots are taken at 2am, 4am, 6am, 8am, 10am, 12pm, 2pm, 4pm, 6pm, 8pm and 10pm. E.g. if you are looking at hourly snapshots at 3pm of Friday you will find hourly snapshots from 2pm Friday, 12pm Friday, 10am Friday, 8am Friday, 6am Friday, 4am Friday, 2am Friday, 10pm Thursday, 8pm Thursday, 6pm Thursday and 4pm Thursday (called hourly.0, hourly.1, ..., hourly.10 respectively).

Note that your deleted or changed file will be in one of the snapshots only if it was on the file system at one of the times when snapshots were taken. E.g. if you create a file at 2:15pm but delete it at 3:40pm then you will not be able to find it and restore it from any of the snapshots (as they were created at 2pm and 4pm and file was not there at either of those times).

Restore File From Snapshots on Linux

These instructions describe how to restore a deleted or older copy of a file from your home directory on a Linux machine.

First, change directories to where the file was/is located - open a terminal (either on a linux desktop or ssh to one of login servers) and cd to that directory. For example, if the deleted file was thesis/1st_draft/chapter1.tex then make sure you are in the directory thesis/1st_draft:

cd thesis/1st_draft

Proceed by changing into .snapshot directory. This is a hidden subdirectory that exists in every directory (in your home dir) and that contains all snapshots:

cd .snapshot

In there you will find directories like: nightly.0, nightly.1, ..., nightly.2, hourly.0, hourly.1, ..., hourly.10 (just type ls to see them). Change to the directory that still contains your file and copy it back to where it was. E.g.

cd nightly.0
cp chapter1.tex ../.. or cp chapter1.tex ~/thesis/1st_draft

An even better way to restore files is to look at all copies of our missing file in all of the snapshots. In our example you could do ls -l */chapter1.tex (after changing the directory to .snapshot) which will result in an output that resembles:

-rw------- 1 mathuser grad 20323 Jul 5 16:44 hourly.0/chapter1.tex
-rw------- 1 mathuser grad 19800 Jul 5 15:32 hourly.1/chapter1.tex
-rw------- 1 mathuser grad 19543 Jul 5 13:20 hourly.2/chapter1.tex
-rw------- 1 mathuser grad 18702 Jul 5 09:16 hourly.3/chapter1.tex
-rw------- 1 mathuser grad 18702 Jul 5 09:16 hourly.4/chapter1.tex

Then you can pick the precise versio of the file you want to restore. This is particularly useful if you need to retrieve an older copy of the file, e.g. in case you made changes that you want to revert or if you have overwritten it by mistake.