From cc4daee18c7bc146eefd08fdff65e617d6c663e1 Mon Sep 17 00:00:00 2001 From: garethgeorge Date: Mon, 18 Nov 2024 00:35:43 -0800 Subject: [PATCH] docs: add btrfs snapshot sample to commands cookbook --- .../3.cookbooks/1.command-hook-examples.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/content/3.cookbooks/1.command-hook-examples.md b/docs/content/3.cookbooks/1.command-hook-examples.md index b29cbc6..5da9cd7 100644 --- a/docs/content/3.cookbooks/1.command-hook-examples.md +++ b/docs/content/3.cookbooks/1.command-hook-examples.md @@ -96,6 +96,35 @@ fi **Error Behavior:** `ON_ERROR_CANCEL` + +#### Create a BTRFS filesystem snapshot before running a backup + +Add a hook that creates a btrfs snapshot prior to each backup (overwriting any prior snapshot). This is useful for creating a point in time consistent copy of the filesystem for restic to read from. It eliminates the possibility of inconsistency due to the time it takes restic to scan your files during a backup. + +**Condition** `CONDITION_SNAPSHOT_START` + +**Script** + +```bash +#!/bin/bash +btrfs subvolume snapshot -r /your-btrfs-filesystem /your-btrfs-filesystem/.backrest-snapshot +``` + +**Error Behavior:** `ON_ERROR_FATAL` (if the snapshot fails, the backup should fail) + +Note: you may also add a hook to delete the snapshot after the backup is complete e.g. + +**Condition** `CONDITION_SNAPSHOT_END` + +**Script** + +```bash +#!/bin/bash +btrfs subvolume delete /your-btrfs-filesystem/.backrest-snapshot +``` + +**Error Behavior:** `ON_ERROR_IGNORE` (even if the snapshot deletion fails, the backup was already successful) + #### Check that the battery is above a certain level Add a hook to check that the battery is above a certain level before running a backup.