Home ZFS Mirror, Snapshots, Recovery
Post
Cancel

ZFS Mirror, Snapshots, Recovery

ZFS Configuration and Management Guide

This document outlines essential steps and considerations for configuring and managing ZFS storage pools, including creating a mirrored pool, setting properties, monitoring, and utilizing snapshots for data protection.

Creating a ZFS Pool

To create a mirrored ZFS pool named new-pool with two disks (/dev/sdb and /dev/sdc), use the following command:

1
sudo zpool create new-pool mirror /dev/sdb /dev/sdc

Creating ZFS Filesystems

Create a ZFS filesystem within your pool for organized data management:

1
sudo zfs create new-pool/myfilesystem

Setting ZFS Properties

ZFS supports various properties for optimizing storage. Examples include:

  • Compression To save space, you can enable compression on your pool or on individual filesystems within the pool.

    1
    
    sudo zfs set compression=on new-pool
    
  • Deduplication If you expect to store a lot of duplicate data, enabling deduplication can save space, but be cautious as it can be very memory intensive.

    1
    
    sudo zfs set dedup=on new-pool
    

Snapshots

Utilize snapshots for data protection and point-in-time recovery:

1
sudo zfs snapshot new-pool/myfilesystem@mySnapshot

Monitoring Pool Health

Regularly check your ZFS pool’s health:

1
sudo zpool status new-pool

Autmating Scrubs

Scheduling regular scrubs of the pool can help detect and correct any data integrity issues. Scrubs can be scheduled using cron jobs

1
2
# Example cron job to scrub on the first day of every month at midnight
0 0 1 * * /usr/sbin/zpool scrub new-pool

Automating Snapshots with zfs-auto-snapshot

Install zfs-auto-snapshot for automatic snapshot management:

1
sudo apt-get install zfs-auto-snapshot

After installation, it automatically schedules snapshots and manages their retention.

Customizing Snapshot Policies

Edit cron jobs in /etc/cron.d to customize snapshot frequencies and retention policies.

Manual Snapshot Creation

Create and manage snapshots manually:

1
sudo zfs-auto-snapshot --keep=7 daily

Excluding Filesystems from Snapshots

Exclude specific filesystems from automatic snapshots:

1
sudo zfs set com.sun:auto-snapshot=false new-pool/myfilesystem

Recovering from a Drive Failure

When a drive fails in a ZFS pool, it’s crucial to replace it as soon as possible to maintain data redundancy and pool health. Here’s a step-by-step guide to recover from a drive failure:

  1. Identify the Failed Drive

    Use zpool status to identify the failed drive in your pool:

    1
    
    sudo zpool status new-pool
    
  2. Offline the Failed Drive

    If the drive is still online but faulty, offline it manually:

    1
    
    sudo zpool offline new-pool /dev/sdx
    

    Replace /dev/sdx with the actual device identifier of the failed drive.

  3. Replace the Drive

    Physically replace the failed drive with a new one. Ensure the new drive is of equal or greater capacity.

  4. Add the New Drive to the Pool

    Use the zpool replace command to replace the failed drive with the new one in your pool:

    1
    
    sudo zpool replace new-pool /dev/sdx /dev/sdy
    

    Replace /dev/sdx with the failed drive and /dev/sdy with the new drive.

  5. Monitor Resilvering Process

    ZFS will begin the resilvering process to restore data redundancy. Monitor the progress with:

    1
    
    sudo zpool status new-pool
    
  6. Verify Pool Health

    Once resilvering is complete, verify the pool’s health:

    1
    
    sudo zpool status new-pool
    

    Ensure the pool status is ONLINE and there are no remaining errors.


Setting Up RAID-Z (Equivalent to RAID 5)

RAID-Z is ZFS’s equivalent to RAID 5, offering a balance between storage capacity, fault tolerance, and performance. Here’s how to set up a RAID-Z pool:

  1. Creating a RAID-Z Pool

    To create a RAID-Z pool, you need at least three disks. Here’s the command to create a RAID-Z pool named raidz-pool with three disks:

    1
    
    sudo zpool create raidz-pool raidz /dev/sda /dev/sdb /dev/sdc
    

    Replace /dev/sda, /dev/sdb, and /dev/sdc with your actual disk identifiers.

  2. Checking Pool Status

    After creation, check the status of your pool to ensure it’s online and no errors are reported:

    1
    
    sudo zpool status raidz-pool
    
  3. Expanding a RAID-Z Pool

    Expanding a RAID-Z pool can be done by adding another set of disks in a RAID-Z configuration. For example, to add another three disks to the pool:

    1
    
    sudo zpool add raidz-pool raidz /dev/sdd /dev/sde /dev/sdf
    

    Note: ZFS does not support expanding an existing RAID-Z by adding a single disk to the vdev. Expansion typically involves adding a new vdev of the same type to the pool.

  4. Monitoring and Managing the Pool

    Use zpool status, zfs list, and other ZFS commands to monitor and manage your RAID-Z pool.


Summary

  1. Creating a ZFS Pool: The guide starts with instructions on creating a mirrored ZFS pool using zpool create, demonstrating how to mirror two devices for redundancy.

  2. Setting Pool Properties: It explains how to adjust ZFS pool properties, such as setting the auto-snapshot feature using zfs set to automatically manage snapshots for backup and recovery purposes.

  3. Snapshot Management: The guide covers creating, listing, and rolling back snapshots, providing a foundation for efficient data management and recovery strategies.

  4. ZFS Auto-Snapshot: It introduces the zfs-auto-snapshot feature, which automates the snapshot process, and briefly touches on its configuration options for tailoring snapshot frequency and retention.

  5. Recovering from a Drive Failure: This section details the steps to identify and replace a failed drive in a ZFS pool, including offlining the failed drive, physically replacing it, and the subsequent resilvering process to restore data redundancy.

  6. Setting Up RAID-Z: Finally, the guide discusses setting up RAID-Z, ZFS’s equivalent to RAID 5, including creating a RAID-Z pool for improved fault tolerance and storage efficiency, and expanding a RAID-Z pool by adding additional sets of disks.

Throughout, the guide emphasizes commands and procedures critical for managing ZFS pools and datasets, offering practical advice for ensuring data integrity, managing storage efficiently, and recovering from hardware failures.

This post is licensed under CC BY 4.0 by the author.