Difference between revisions of "Snapshots:ZFS"

From UMIACS
Jump to navigation Jump to search
 
Line 8: Line 8:
  
 
<pre>
 
<pre>
[derek@chimerasub00 ~]$ ls
+
[username@chimerasub00 ~]$ ls
 
f90  gpucomputingsdk_3.2.16_linux.run  NVIDIA_GPU_Computing_SDK
 
f90  gpucomputingsdk_3.2.16_linux.run  NVIDIA_GPU_Computing_SDK
 
</pre>
 
</pre>
I now remove the '''gpucomputingsdk_3.2.16_linux.run''' file.
+
We now remove the '''gpucomputingsdk_3.2.16_linux.run''' file.
 
<pre>
 
<pre>
[derek@chimerasub00 ~]$ rm gpucomputingsdk_3.2.16_linux.run
+
[username@chimerasub00 ~]$ rm gpucomputingsdk_3.2.16_linux.run
 
</pre>
 
</pre>
 
It is now gone.
 
It is now gone.
 
<pre>
 
<pre>
[derek@chimerasub00 ~]$ ls
+
[username@chimerasub00 ~]$ ls
 
f90  NVIDIA_GPU_Computing_SDK
 
f90  NVIDIA_GPU_Computing_SDK
 
</pre>
 
</pre>
  
Find out what file system you are in and then cd to the base file system, in this case <tt>/chimerahomes/derek</tt>.
+
Find out what file system you are in and then cd to the base file system, in this case <tt>/chimerahomes/username</tt>.
 
<pre>
 
<pre>
[derek@chimerasub00 ~]$ df .
+
[username@chimerasub00 ~]$ df .
 
Filesystem          1K-blocks      Used Available Use% Mounted on
 
Filesystem          1K-blocks      Used Available Use% Mounted on
chimeranexenta01:/volumes/zvol01/chimerahomes/derek
+
chimeranexenta01:/volumes/zvol01/chimerahomes/username
                       10485760  1680384  8805376  17% /chimerahomes/derek
+
                       10485760  1680384  8805376  17% /chimerahomes/username
[derek@chimerasub00 ~]$ cd /chimerahomes/derek
+
[username@chimerasub00 ~]$ cd /chimerahomes/username
 
</pre>
 
</pre>
  
I can change my directory into the <tt>.zfs/snapshot</tt> directory.
+
Change your directory into the <tt>.zfs/snapshot</tt> directory.
 
<pre>
 
<pre>
[derek@chimerasub00 ~]$ cd .zfs/snapshot/
+
[username@chimerasub00 ~]$ cd .zfs/snapshot/
 
</pre>
 
</pre>
Doing a directory listing will show all the snapshots available.
+
Perform a directory listing to show all the snapshots available.
 
<pre>
 
<pre>
[derek@chimerasub00 snapshot]$ ls
+
[username@chimerasub00 snapshot]$ ls
 
snap-daily-1-2011-06-20-0300  snap-hourly-4-2011-06-23-0800
 
snap-daily-1-2011-06-20-0300  snap-hourly-4-2011-06-23-0800
 
snap-daily-1-2011-06-21-0300  snap-hourly-4-2011-06-23-1200
 
snap-daily-1-2011-06-21-0300  snap-hourly-4-2011-06-23-1200
Line 46: Line 46:
 
snap-hourly-4-2011-06-23-0400
 
snap-hourly-4-2011-06-23-0400
 
</pre>
 
</pre>
I choose the '''snap-hourly-4-latest''' directory and change directory into it.  
+
In this example, we choose the '''snap-hourly-4-latest''' directory and change directory into it.  
 
<pre>
 
<pre>
[derek@chimerasub00 snapshot]$ cd snap-hourly-4-latest/
+
[username@chimerasub00 snapshot]$ cd snap-hourly-4-latest/
 
</pre>
 
</pre>
This directory is exactly like the volume when the snapshot was taken, you may need to continue to change directories until you get to the level of the file you need to restore.
+
This directory is exactly like the volume when the snapshot was taken; you may need to continue to change directories until you get to the level of the file you need to restore.
 
<pre>
 
<pre>
[derek@chimerasub00 snap-hourly-4-latest]$ ls
+
[username@chimerasub00 snap-hourly-4-latest]$ ls
 
f90  gpucomputingsdk_3.2.16_linux.run  NVIDIA_GPU_Computing_SDK
 
f90  gpucomputingsdk_3.2.16_linux.run  NVIDIA_GPU_Computing_SDK
 
</pre>
 
</pre>
I can now copy the file back into place.
+
We can now copy the file back into place.
 
<pre>
 
<pre>
[derek@chimerasub00 snap-hourly-4-latest]$ cp gpucomputingsdk_3.2.16_linux.run ~
+
[username@chimerasub00 snap-hourly-4-latest]$ cp gpucomputingsdk_3.2.16_linux.run ~
 
</pre>
 
</pre>
 
And now it is back.
 
And now it is back.
 
<pre>
 
<pre>
[derek@chimerasub00 snap-hourly-4-latest]$ cd ~
+
[username@chimerasub00 snap-hourly-4-latest]$ cd ~
[derek@chimerasub00 ~]$ ls
+
[username@chimerasub00 ~]$ ls
 
f90  gpucomputingsdk_3.2.16_linux.run  NVIDIA_GPU_Computing_SDK
 
f90  gpucomputingsdk_3.2.16_linux.run  NVIDIA_GPU_Computing_SDK
 
</pre>
 
</pre>

Latest revision as of 16:49, 7 May 2021

Restoring from a Snapshot on ZFS

If you find that you have mistakenly deleted a file and it was created/written to before the last snapshot[1]. You can restore the file by going to the directory where the file was and changing into the .zfs/snapshot directory at the base of NFS file system mount. You can then use a normal copy operation to copy it back to the directory where you would like it. Please note that the .zfs directory is hidden and may not appear when you do a directory listing.

[1] - If a file was created or modified after the last snapshot then you can potentially lose up to 4 hours of work in a worse case scenario. Please make sure you save your work throughout the day.

Example:

[username@chimerasub00 ~]$ ls
f90  gpucomputingsdk_3.2.16_linux.run  NVIDIA_GPU_Computing_SDK

We now remove the gpucomputingsdk_3.2.16_linux.run file.

[username@chimerasub00 ~]$ rm gpucomputingsdk_3.2.16_linux.run

It is now gone.

[username@chimerasub00 ~]$ ls
f90  NVIDIA_GPU_Computing_SDK

Find out what file system you are in and then cd to the base file system, in this case /chimerahomes/username.

[username@chimerasub00 ~]$ df .
Filesystem           1K-blocks      Used Available Use% Mounted on
chimeranexenta01:/volumes/zvol01/chimerahomes/username
                      10485760   1680384   8805376  17% /chimerahomes/username
[username@chimerasub00 ~]$ cd /chimerahomes/username

Change your directory into the .zfs/snapshot directory.

[username@chimerasub00 ~]$ cd .zfs/snapshot/

Perform a directory listing to show all the snapshots available.

[username@chimerasub00 snapshot]$ ls
snap-daily-1-2011-06-20-0300   snap-hourly-4-2011-06-23-0800
snap-daily-1-2011-06-21-0300   snap-hourly-4-2011-06-23-1200
snap-daily-1-2011-06-22-0300   snap-hourly-4-2011-06-23-1600
snap-daily-1-2011-06-23-0300   snap-hourly-4-2011-06-23-2000
snap-daily-1-latest            snap-hourly-4-latest
snap-hourly-4-2011-06-22-2000  snap-weekly-1-2011-04-30-0300
snap-hourly-4-2011-06-23-0000  snap-weekly-1-latest
snap-hourly-4-2011-06-23-0400

In this example, we choose the snap-hourly-4-latest directory and change directory into it.

[username@chimerasub00 snapshot]$ cd snap-hourly-4-latest/

This directory is exactly like the volume when the snapshot was taken; you may need to continue to change directories until you get to the level of the file you need to restore.

[username@chimerasub00 snap-hourly-4-latest]$ ls
f90  gpucomputingsdk_3.2.16_linux.run  NVIDIA_GPU_Computing_SDK

We can now copy the file back into place.

[username@chimerasub00 snap-hourly-4-latest]$ cp gpucomputingsdk_3.2.16_linux.run ~

And now it is back.

[username@chimerasub00 snap-hourly-4-latest]$ cd ~
[username@chimerasub00 ~]$ ls
f90  gpucomputingsdk_3.2.16_linux.run  NVIDIA_GPU_Computing_SDK

ZFS Snapshots and Space Accounting

Due to the way ZFS does space accounting, data that has been rm'd from the volume but is still held in snapshots is counted against the "size" of the volume. In other words:

[volume quota] - [space occupied by snapshots] = ["size" as reported by df]

Instead of relying on the size of the volume as reported by df, you should note the "available" value reported by df. This value accurately represents the amount of space currently available for use in the volume. The snapshots eventually expire over the course of several days and the space becomes usable again.