As i have already discussed in my previous post zfs filesystem and MySQL about zfs overview and two most important command zpool and zfs. I am going to continue with usage of zfs snapshots. It includes create a pool, Create file system, Taking a snapshot, Renaming Snapshots, Listing all snapshots, restoring from snapshot and Moving the snapshot to other location.
A snapshot is a read-only copy of a file system or volume. Snapshots can be created almost instantly, and initially consume no additional disk space within the pool. However, as data within the active dataset changes, the snapshot consumes disk space by continuing to reference the old data and so prevents the space from being freed. Snapshots of volumes cannot be accessed directly, but they can be cloned, backed up, rolled back to.
Creating a Pool:
# zpool create zpool1 c2t0d0
List pool:
# zpool list
Create file system under above create pool:
Once you have a storage pool, you can build file systems on it:
# zfs create zpool1/data # zfs create zpool1/logs
Here we have built “/data” file system on pool zpool1
List all zfs file systems:
# zfs list
Taking a Snapshot:
# zfs snapshot < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs snapshot zpool1/data01@Snapshot1
Remove/Destroy a Snapshot:
# zfs destroy < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs destroy zpool1/data01@Snapshot1
Rename Snapshots:
You can rename snapshots but they must be renamed within the pool and dataset from which they were created.
# zfs rename < pool name>/<filesystem name>@<snapshot name> < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs rename zpool1/data01@Snapshot1 zpool1/data01@Snapshot2
Below snapshot rename operation is not supported because the target pool and file system name are different from the pool and file system where the snapshot was created.
# zfs rename zpool1/data01@Snapshot1 zpool3/data01@Snapshot2
Displaying zfs Snapshots:
# zfs list
# zfs list -t snapshot
You can also list snapshots that were created for a particular file system:
# zfs list -r -t snapshot -o <name>,<creation> <pool>/<home>
Restore/Rolling Back zfs snapshots:
# zfs rollback < pool name>/<filesystem name>@<snapshot name>
Example:
# zfs rollback zpool1/data01@Snapshot1
This will restore the entire file system with snapshot.
Restoring individual files:
It is possible to copy individual file from a snapshot by changing into the hidden “.zfs” directory of the pool that has been snapped.
cd /<pool name>/<file system name>
cd .zfs
cp <required file source location> <destination>
Example:
cd /zpool1/data01
cd .zfs
cp <required file source location> <destination>
Moving a Snapshot to another system:
Wecan move the snapshot to another system and install it there as a usable file system. But at first we need to create a pool to receive the snapshot on the target system.
Step1: Create Pool on another system.
# zpool create -f zpool11 c2t0d0
Step2: Send the snapshot over the network and receive it into the pool using a combination of zfs send/receive command and a netwolrk pipe.
# zfs send zpool1/data01@snapshot1 | ssh <destination host> “usr/sbin/zfs receive zpool11/<myfilesystem>
Here zpool11 is the name of pool on another system which we have created above and myfilesystem is the name of filesystem you wish to put.