From e099e2dbe61e9ad4da9469e7d8d1762019e9de46 Mon Sep 17 00:00:00 2001 From: "Jean (east-high-Nerd)" Date: Fri, 11 Jul 2025 19:44:33 -0400 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ backup.conf | 2 ++ backup.sh | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 .gitignore create mode 100644 backup.conf create mode 100755 backup.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9782c5b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +backup.conf +backup-last diff --git a/backup.conf b/backup.conf new file mode 100644 index 0000000..02dc615 --- /dev/null +++ b/backup.conf @@ -0,0 +1,2 @@ +SOURCE="" +DEST="" diff --git a/backup.sh b/backup.sh new file mode 100755 index 0000000..2132a51 --- /dev/null +++ b/backup.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -euo pipefail + + +BASEDIR="$(dirname ${0} | sed "s|^.|${PWD}|")" +source "${BASEDIR}/backup.conf" +TIMESTAMP="$(date +%Y_%m_%d-%H_%M_%S)" +SNAPSHOT="${SOURCE}@${TIMESTAMP}" + + +sudo zfs snapshot ${SNAPSHOT} + +if [[ -f "${BASEDIR}/backup-last" ]]; then + BACKUP_LAST="$(cat ${BASEDIR}/backup-last)" + + sudo \ + zfs \ + send \ + -i ${BACKUP_LAST} \ + ${SNAPSHOT} \ + | \ + sudo \ + zfs \ + receive \ + ${DEST} +else + sudo \ + zfs \ + send \ + ${SNAPSHOT} \ + | \ + sudo \ + zfs \ + receive \ + ${DEST} +fi + +printf "@${TIMESTAMP}" | tee "${BASEDIR}/backup-last" &> /dev/null