Copy-on-write and snapshots
0 Liked

    ZFS Essentials – Copy-on-write & Snapshots

    This article provides information about concepts that stand behind the copy-on-write mechanism as well as snapshots and clones used in the ZFS system.

    Copy-on-write

    On a predominant number of file systems, the data is irreversibly lost during the overwrite operation. On ZFS, however, the data changes are performed on the copy of the data instead of the original data blocks. In other words, the changes are stored on a different location on a disk and then the metadata is updated in that place on the disk.

    This mechanism guarantees that the old data is safely preserved in case of power loss or system crash that in other cases would result in loss of data. On other file systems, the data would be left in an inconsistent state and the Linux and Unix fsck commands would have to be run to ensure that data is not corrupted. Moreover, this mechanism used for storing data is used by snapshots that are described in the next section.

    Snapshots

    A snapshot is an unchangeable copy of a file system made at a particular point in time. You are able to create snapshots of entire datasets or volumes.

    Complete snapshots can be restored thus allowing to retrieve the snapshot’s directories and files. The snapshot contains information about the original version of the file system to be retained. Snapshots do not require additional disk space within the pool. Once the data rendered in a snapshot is modified, the snapshot will take the disk space since it will now be pointing to the old data. This prohibits releasing the data back to Zpool.

    It is also possible to return to a particular point in time when the snapshot was made by performing the rollback operation. In this case, all modifications that were made after the snapshot was taken will be irreversibly lost. Snapshots are presented in the figure below.

     

     

    Clones

    To create a writeable version of a snapshot, a clone has to be made. In the beginning, it does not require additional disk space. Once new blocks are allocated and new data is being written to the clone, its size grows. Overwriting the blocks in the cloned volume or file system results in decrementing the reference count on the previous block. Since the clone is dependable on the snapshot that was used to create the clone, you are unable to delete the original snapshot. The following figure presents the concept of a clone.

    diagram_snapshot-clones2 (2)

    Rollback and Promote

    As indicated in one of the sections above, a rollback command has to be used if there is a need to go back to a previous version of a dataset or a volume. In such a case, all changes made later than a given snapshot was made will be lost. The file or a volume will be restored to the state at which a particular snapshot was taken. Note that the rollback command cannot revert changes from other snapshots than the most recent one. If for some reason, you would like to retrieve changes from an earlier snapshot than the most recent one, then all intermediate snapshots will be automatically destroyed. The process of a snapshot rollback is presented in the image below:

    ZFS also allows you to replace an existing volume with its clone if you were using clones, as described in the previous section, and now want to use the clone instead of an original volume. This can be done by using the promote command. The process of a snapshot promotion is presented in the image below.

    The promote function, for instance, will be required to execute when a volume clone was created and assigned to production as a result of instant recovery from a snapshot of a production volume that has been destroyed. Then, to clean up, we need to remove the original destroyed volume but first, it must be replaced with the (working) clone.

    Learn more about the Open-E JovianDSS backup and Disaster Recovery features.

    Closing Notes

    The copy-on-write mechanism and snapshots together with clones included in ZFS offer unique capabilities that other file systems do not possess. An enhanced write mechanism that protects your data from being corrupted is solid protection against power losses or other harmful events. There is also a possibility to undo certain changes and restore, for example, the previous version by using the snapshot’s functionality. A clone can be used if there is a need for more advanced operations requiring snapshot modifications.

    That is the final part of the ZFS Essentials series. In case you missed other parts, you can catch up now:

    Rating: / 5.

    No votes yet

    Leave a Reply