Files
bobbie-pkm/_Inbox/2026-05-17 1129 migrating to truenas, sanoid+syncoid config and script backup.md

5.3 KiB

category, type, title, created, date, tags
category type title created date tags
Journal
Log
migrating to truenas, sanoid+syncoid backup 2026-05-17T11:29:26 2026-05-17

So I'm going to try running TrueNAS on my backup machine rather than Proxmox with Sanoid and Syncoid.

here are my current config and scripts on the /etc/sanoid/sanoid.conf

########################

# stanleypool datasets #

########################

  

[stanleypool/archive]

    use_template = stanleypool-nightly

    recursive = zfs

    process_children_only = no

  

[stanleypool/bobbie]

    use_template = stanleypool-nightly

    recursive = zfs

    process_children_only = no

  

[stanleypool/music]

    use_template = stanleypool-nightly

    recursive = zfs

    process_children_only = no

  

[stanleypool/photos]

    use_template = stanleypool-nightly

    recursive = zfs

    process_children_only = no

  

[stanleypool/video]

    use_template = stanleypool-nightly

    recursive = zfs

    process_children_only = no

  

#############

# templates #

#############

  

[template_stanleypool-nightly]

    frequently = 0

    hourly = 0

    daily = 90

    weekly = 26

    monthly = 24

    yearly = 0

    autosnap = no

    autoprune = yes

    prune_defer = 80

/usr/local/bin/zfs-nightly-backup.sh

#!/bin/bash

GLOBAL_TIMEOUT="6h"

# --- CRASH SAFETY NET ---

# If the script exits prematurely for ANY reason, run the shutdown function

failure_cleanup() {

    echo "$(date '+[%Y-%m-%d %H:%M:%S]') CRITICAL: Script terminated unexpectedly! Triggering safety shutdown."

    ssh root@pve-shug9 "/sbin/shutdown +10 'Nightly backup crashed, shutting down in 10 minutes'"

    /sbin/shutdown +10 "Nightly backup crashed, shutting down in 10 minutes"

}

# Trap standard exit signals (1 = General errors, 2 = Ctrl+C, 15 = Terminate)

trap 'if [ "$EXIT_STATUS" != "0" ] && [ "$EXIT_STATUS" != "124" ]; then failure_cleanup; fi' EXIT

  

run_backups() {

    # pull existing snapshots from source (thinkstation)

    /usr/sbin/syncoid --quiet -r --no-sync-snap --create-bookmark --use-hold --identifier=pull --preserve-recordsize --preserve-properties root@pve-thinkstation:noggapool/bobbie stanleypool/bobbie

    sleep 10

    /usr/sbin/syncoid --quiet -r --no-sync-snap --create-bookmark --use-hold --identifier=pull --preserve-recordsize --preserve-properties root@pve-thinkstation:noggapool/photos stanleypool/photos

    sleep 10

    /usr/sbin/syncoid --quiet -r --no-sync-snap --create-bookmark --use-hold --identifier=pull --preserve-recordsize --preserve-properties root@pve-thinkstation:noggapool/archive stanleypool/archive

    sleep 10

    /usr/sbin/syncoid --quiet -r --no-sync-snap --create-bookmark --use-hold --identifier=pull --preserve-recordsize --preserve-properties root@pve-thinkstation:noggapool/music stanleypool/music

    sleep 10

    /usr/sbin/syncoid --quiet -r --no-sync-snap --create-bookmark --use-hold --identifier=pull --preserve-recordsize --preserve-properties root@pve-thinkstation:noggapool/video stanleypool/video

    sleep 10

  

    # push to remote (shug9)

    /usr/sbin/syncoid --quiet -r --no-sync-snap --create-bookmark --use-hold --identifier=push --preserve-recordsize --preserve-properties root@pve-shug9:bathpool/bobbie stanleypool/bobbie

    sleep 10

    /usr/sbin/syncoid --quiet -r --no-sync-snap --create-bookmark --use-hold --identifier=push --preserve-recordsize --preserve-properties stanleypool/photos root@pve-shug9:bathpool/photos

    sleep 10

    /usr/sbin/syncoid --quiet -r --no-sync-snap --create-bookmark --use-hold --identifier=push --preserve-recordsize --preserve-properties stanleypool/archive root@pve-shug9:bathpool/archive

    sleep 10

    /usr/sbin/syncoid --quiet -r --no-sync-snap --create-bookmark --use-hold --identifier=push --preserve-recordsize --preserve-properties stanleypool/music root@pve-shug9:bathpool/music

    sleep 10

  

    # only run the prune after successful transfers

    ssh root@pve-shug9 "/usr/sbin/sanoid --quiet --prune-snapshots"

    sleep 5

    /usr/sbin/sanoid --quiet --prune-snapshots

    sleep 5

    echo "Backup script completed successfully."

}

  

# Export the function so the timeout subshell can see it

export -f run_backups

  

# Run the function wrapped in the timeout utility

timeout "$GLOBAL_TIMEOUT" bash -c run_backups

EXIT_STATUS=$?

  

# --- EVALUATE EXIT STATE FOR LOGGING ---

  

if [ $EXIT_STATUS -eq 124 ]; then

    echo "$(date '+[%Y-%m-%d %H:%M:%S]') ERROR: Script exceeded global timeout of $GLOBAL_TIMEOUT. Aborting."

elif [ $EXIT_STATUS -ne 0 ]; then

    echo "$(date '+[%Y-%m-%d %H:%M:%S]') ERROR: Backup function failed with exit code $EXIT_STATUS."

else

    echo "$(date '+[%Y-%m-%d %H:%M:%S]') Success: All replication steps completed."

fi

  

# --- UNCONDITIONAL 10-MINUTE DELAYED SHUTDOWN ---

# This runs normally for Success or Timeout states.

# (General script crashes bypass this and hit the 'trap' function at the top).

ssh root@pve-shug9 "/sbin/shutdown +10 'Nightly backup/replication sequence finished, shutting down in 10 minutes'"

/sbin/shutdown +10 "Nightly backup/replication sequence finished, shutting down in 10 minutes"

  

exit $EXIT_STATUS