Restoring Lost Files

Unix does not automatically backup files for you as you work. However, if you accidently delete a file, there are a few things you can do.

  1. If you are editing a file using emacs, emacs keeps a previous copy of the file in a file named filename.c~. If you accidentally delete filename.c, you can at least restore filename.c from the previous copy of the file (filename.c~):
            % cp filename.c~ filename.c
    
  2. We also take snapshots of the filesystem periodically during the day. You can grab a copy of your file from one of these snapshots.
            % cd /snapshots         # cd to the snapshots directory         
            % ls -l                 # long listing of contents of snapshots
    
            drwxr-xr-x    5 root     root         4096 Feb  8 12:42 daily.0/
            drwxr-xr-x    5 root     root         4096 Feb  7 12:41 daily.1/
            drwxr-xr-x    5 root     root         4096 Feb  6 12:41 daily.2/
            drwxr-xr-x    5 root     root         4096 Feb  9 00:30 hourly.0/
            drwxr-xr-x    5 root     root         4096 Feb  8 20:32 hourly.1/
            drwxr-xr-x    5 root     root         4096 Feb  8 16:33 hourly.2/
            drwxr-xr-x    5 root     root         4096 Feb  8 12:42 hourly.3/
    
            # find the most recent snapshot (in this example it is
            # hourly.0 taken at 00:30 on Feb 9), and cd into the snapshot 
            # of your user directory in the hourly.0 subdirectory 
    
            % cd hourly.0
            % ls
            staff/          users1/         users2/
    
            # your user directory is either located in subdirectory users1
            # or users2...cd into one directory and ls to see if it is
            # there, if not, it is in the other one.  Here I'm showing you
            # how user tnas would locate her lost 5.6.c file and copy it back
            # to her ~tnas/cs21/hw4 subdirectory  (only tnas can access her
            # cs21 subdirectory in the snapshot, since she has permissions
            # correctly set on her cs21 in her home directory to 700)
            # 
    
            % cd users2
            % ls tnas
            ls: tnas: No such file or directory     # tnas is not in users2
            % cd ../users1                          # cd to users1
            % ls tnas                               # tnas is in users1
            mail/   cs21/
            % cd tnas/cs21/hw4/                     # cd into tnas's snapshot  
            % cp 5.6.c ~tnas/cs21/hw4/.             # copy snapshot of file 
                                                    # 5.6.c back to tnas's
                                                    # cs21/hw4 subdirectory
                                                    # of her home directory
    
            % cd                                    # cd back to your home dir
            % cd cs21/hw4                           # file 5.6.c restored
            % ls                                    # from the snapshot
            5.6.c ...                               # should be in cs21/hw4/ 
    
    If your deleted file isn't in the latest snapshot subdirectory, try looking in earlier snapshots.

  3. If you deleted the file much earlier than the oldest snapshot, then send email local-staff requesting a backup from tape. Include the name of the file you deleted, and the date that you deleted it (as close as you can remember). The longer you wait to restore a deleted file, the less likely it will be that you will get back a version of it that is close to the one you lost.