How to configure ZFS for rdiff-backup
Tags: backup, zfs
Published: 2020-07-22 13:21:30

ZFS is a relatively new file system available for the Linux platform. Its popularity is gaining speed thanks to its great management flexibility and its resilience. To learn more about the benefits of ZFS, check out our previous article.


Further to our article on the [benefits of ZFS for rdiff-backup](https://www.ikus-soft.com/en/blog/2020-06-24-advantages-of-using-zfs-for-rdiff-backup/), you will find herewith more technical information which explains the best configuration practices for ZFS when used with rdiff-backup.

  

##For starters

It is highly recommended to create a specific *dataset* for storing rdiff-backup deposits. You will then be able to adjust the configuration settings of this *dataset* without affecting the configuration of the rest of the system.

To create a new *dataset*, run the following command where *rpool* is your *zfspool*.

```
sudo zfs create rpool/backups
```
  

This will create a default dataset configuration setting that you can adjust later.

##Activate compression

As mentioned in our previous article, one of the great advantages of ZFS is its ability to directly compress data. First, you will be surprised to find that lz4 compression improves reading and writing performance.<sup><a href="#sdfootnote1sym" id="sdfootnote1anc" class="sdfootnoteanc"><sup>1</sup></a><a href="#sdfootnote2sym" id="sdfootnote2anc" class="sdfootnoteanc"><sup>2</sup></a></sup>

To activate compression, you need to change *compression* properties.

```
zfs set compression=lz4 rpool/backups
```
  

Be sure to use lz4 compression mode to optimize performance since other compression modes are more draining on CPU resources.

Once activated, the new data written on the disk will then be compressed. Existing disk data will retain its original compression mode.

If you want ZFS to do all the compression work, it is recommended to deactivate rdiff-backup compression by changing your command line as follows:

```
rdiff-backup --no-compression ...
```
  
Implementing this strategy can be complex, as you will need to change the command on the client side or on the server side depending on the way you operate. Should you have any questions about this, please leave a message in the comments.

If you use Minarca, you can easily implement this strategy by changing the configuration setting to *RDIFFBACKUP\_ARGS=--no-compression* in */etc/minarca/minarca-shell.conf*.

##primarycache & secondarycache

ZFS is known for its high-performance cached system
called *Adaptive Replacement Cache (ARC)*. This system  provides great flexibility since it adjusts to different deployment needs. As part of rdiff-backup, it is best to set up the ZFS cache to only store metadata. To quickly activate this feature, the primarycache and secondarycache value must be changed as follows:

```
sudo zfs set primarycache=metadata rpool/backups
sudo zfs set secondarycache=metadata rpool/backups
```

##Deduplication

ZFS also allows you to enable an interesting data deduplication feature. Should two blocks of data be identical, ZFS can only store the same block of data on the disk one time, thus avoiding multiple storage of the same data. This feature is particularly interesting if you back up system files from multiple machines with similar operating systems.

However, ZFS uses much more RAM. It would be wise to measure the real impact of this feature in the lab for your type of  data backup.

```
sudo zfs set dedup=on rpool/backups
```

##utf8only

Although rdiff-backup supports the use of a UTF-8-character code restriction file system very well, it is highly recommended to enable non-UTF-8-character support in ZFS for compatibility purposes. This will allow you to safely copy your data from another file system. Moreover, this feature cannot be changed after the *dataset* is created. When you need to copy files with a non-UTF-8-character code, it will be too late to change this option.

```
sudo zfs create -o utf8only=off rpool/backups
```

##Conclusion

ZFS is definitely a file system that you need to
familiarize yourself with if you are a Linux platform manager. It will certainly change your management methodology. However, it is worth mentioning that that FreeBSD also offers advantages over the ZFS On Linux version. We encourage you to find out about this!

This article was originally posted on [ikus-soft.com](https://www.ikus-soft.com/en/blog/2020-07-22-configure-zfs-for-rdiff-backup/)