### **Overview**
In this guide, we will walk through the setup and configuration of **Snapper** on a system using **BTRFS** as the filesystem, specifically for **Garuda Linux KDE**. This will include configuring automatic snapshots for both the root and home subvolumes, understanding how Snapper works, and ensuring that the system takes snapshots as intended, while performing cleanups based on space and time limits.
By default, Garuda KDE uses **Snapper** for managing snapshots on the root (`@`) subvolume, but snapshots may not be configured for the home subvolume (`@home`). This guide will help you configure Snapper for both subvolumes and ensure it works properly.
---
### **1. System and Environment Details**
- **Operating System**: Garuda KDE (Calamares installer used BTRFS by default)
- **Subvolumes**:
- `@`: Root subvolume.
- `@home`: Home subvolume.
- `@cache`, `@log`, `@srv`, etc.: Additional subvolumes.
Garuda KDE uses **BTRFS snapshots** for recovery, managed by **Snapper**.
---
### **2. Checking Existing Subvolumes and Snapshots**
First, let's check what subvolumes exist on your system:
```bash
sudo btrfs subvolume list /
```
Example output:
```bash
ID 256 gen 8741 top level 5 path @
ID 257 gen 8742 top level 5 path @home
ID 263 gen 8727 top level 256 path .snapshots
```
Here:
- `@`: The root subvolume.
- `@home`: The home subvolume.
- `.snapshots`: The directory used by Snapper for storing snapshots of the root subvolume.
**Key Insight**:
From this output, it's clear that snapshots are only being taken for the root subvolume (`@`). There are no snapshots for the home subvolume (`@home`).
---
### **3. Setting Up Snapper for Home Subvolume**
Since there are no snapshots for the `@home` subvolume, we need to configure Snapper to take snapshots for it.
### **Step 1: Create Snapper Configuration for Home Subvolume**
Use Snapper’s `create-config` command to set up configuration for the home subvolume:
```bash
sudo snapper -c home create-config /home
```
This creates the necessary Snapper configuration for managing `/home`.
### **Step 2: Review the Snapper Configuration for Home**
The configuration file for the home subvolume will be created at `/etc/snapper/configs/home`. You can edit this file to fine-tune your snapshot management.
Here’s an example Snapper configuration for `/home`:
```bash
# subvolume to snapshot
SUBVOLUME="/home"
# filesystem type
FSTYPE="btrfs"
# btrfs qgroup for space-aware cleanup algorithms
QGROUP=""
# fraction or absolute size of the filesystem space the snapshots may use
SPACE_LIMIT="0.5"
# fraction or absolute size of the filesystem space that should be free
FREE_LIMIT="0.2"
# users and groups allowed to work with config
ALLOW_USERS=""
ALLOW_GROUPS=""
# sync users and groups from ALLOW_USERS and ALLOW_GROUPS to .snapshots
# directory
SYNC_ACL="no"
# start comparing pre- and post-snapshot in background after creating
# post-snapshot
BACKGROUND_COMPARISON="yes"
# run daily number cleanup
NUMBER_CLEANUP="yes"
# limit for number cleanup
NUMBER_MIN_AGE="3600"
NUMBER_LIMIT="50"
NUMBER_LIMIT_IMPORTANT="10"
# create hourly snapshots
TIMELINE_CREATE="yes"
# cleanup hourly snapshots after some time
TIMELINE_CLEANUP="yes"
# limits for timeline cleanup
TIMELINE_MIN_AGE="3600"
TIMELINE_LIMIT_HOURLY="10"
TIMELINE_LIMIT_DAILY="10"
TIMELINE_LIMIT_WEEKLY="0"
TIMELINE_LIMIT_MONTHLY="10"
TIMELINE_LIMIT_YEARLY="10"
# cleanup empty pre-post pairs
EMPTY_PRE_POST_CLEANUP="yes"
# limits for empty pre-post pair cleanup
EMPTY_PRE_POST_MIN_AGE="3600"
```
**Explanation of Key Fields**:
- **SUBVOLUME**: Specifies the subvolume Snapper will snapshot (`/home`).
- **TIMELINE_CREATE**: Enables automatic hourly snapshots.
- **NUMBER_LIMIT**: Maximum number of normal snapshots to retain (50).
- **TIMELINE_LIMIT_HOURLY**: Retain 10 hourly snapshots.
- **TIMELINE_LIMIT_DAILY**: Retain 10 daily snapshots.
- **TIMELINE_LIMIT_YEARLY**: Retain 10 yearly snapshots.
### **Step 3: Enable Timers for Automated Snapshots**
Enable Snapper’s systemd timers to automatically create snapshots and clean them up based on your configuration:
```bash
sudo systemctl enable --now snapper-timeline.timer
sudo systemctl enable --now snapper-cleanup.timer
```
These timers ensure that Snapper:
- Takes snapshots hourly.
- Performs daily cleanup of old snapshots.
---
### **4. Verifying Snapper’s Operation**
### **Check Current Snapshots**:
You can view the list of snapshots created by Snapper for both the root and home subvolumes:
```bash
# Check root subvolume snapshots
sudo snapper -c root list
# Check home subvolume snapshots
sudo snapper -c home list
```
This will show you all the snapshots along with details such as creation time, description, and type (timeline, pre, post).
### **Check Timer Status**:
Ensure that the Snapper timers are active and running as expected:
```bash
systemctl list-timers | grep snapper
```
---
### **5. Detailed Explanation of Snapper Configuration Options**
Below is a detailed breakdown of the key configuration options used in Snapper’s config file:
|**Option**|**Description**|
|---|---|
|`SUBVOLUME`|The path to the subvolume Snapper will manage. In this case, `/home` for the home subvolume.|
|`FSTYPE`|Specifies the filesystem type (`btrfs` in this case).|
|`SPACE_LIMIT`|Defines the maximum space Snapper snapshots can occupy. Here, it's 50% of the filesystem's space.|
|`FREE_LIMIT`|Ensures that at least 20% of the filesystem space remains free, triggering cleanup if this threshold is breached.|
|`NUMBER_CLEANUP`|Enables daily cleanup of snapshots based on the defined limits.|
|`NUMBER_LIMIT`|Sets the maximum number of snapshots Snapper will keep. Here, it retains up to 50 normal snapshots.|
|`TIMELINE_CREATE`|Enables automatic creation of hourly snapshots.|
|`TIMELINE_LIMIT_HOURLY`|Retains up to 10 hourly snapshots.|
|`TIMELINE_LIMIT_DAILY`|Retains up to 10 daily snapshots.|
|`TIMELINE_LIMIT_YEARLY`|Retains up to 10 yearly snapshots.|
|`EMPTY_PRE_POST_CLEANUP`|Automatically cleans up empty pre-post snapshot pairs (where no changes were detected).|
|`BACKGROUND_COMPARISON`|Compares snapshots in the background to track changes between pre- and post-snapshots.|
---
### **6. Monitoring and Troubleshooting Snapper**
### **Monitor Snapshots**:
- You can use the `snapper list` command to view snapshots taken for either the root or home subvolumes.
- Example:
```bash
sudo snapper -c home list
```
### **Checking Logs**:
- Check the Snapper logs if any issues arise during snapshot creation or cleanup:
```bash
journalctl -u snapper-timeline
journalctl -u snapper-cleanup
```
### **Manual Snapshot Creation**:
- You can manually create snapshots for any subvolume using:
```bash
sudo snapper -c home create -d "Manual Snapshot for testing"
```
---
### **7. Snapper with BTRFS Quotas (Optional)**
If you want to limit the space used by Snapper even more precisely, you can enable BTRFS quota groups (qgroups). This feature allows Snapper to track and limit space usage for snapshots. However, using qgroups can increase system overhead.
To enable quota groups:
```bash
sudo btrfs quota enable /
```
Once enabled, you can configure Snapper to use `QGROUP` in the configuration file.
---
### **8. Conclusion**
In this guide, we’ve walked through setting up and configuring Snapper for both the root and home subvolumes on Garuda KDE. By setting up Snapper with automatic snapshots and cleanup, you ensure that your system remains protected with frequent recovery points without consuming excessive space.
This solution is ideal for both system administrators and users who want to maintain a robust and manageable backup system using the features of BTRFS.
### **Key Takeaways**:
- Snapper automatically creates snapshots of the root and home subvolumes at regular intervals.
- Timers ensure snapshots are taken and cleaned up according to user-defined rules.
- Snapper can manage space efficiently through automatic snapshot retention policies.
---
This concludes the guide. By following the steps outlined above, you will have a reliable and automated snapshot management system using Snapper on Garuda Linux.