diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-12-17 12:02:26 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-12-17 12:02:26 +0100 |
commit | e599d576d621f4518f0026166c4e209f0a2e3171 (patch) | |
tree | e6c30649ebaa2b769234bf75012304f2389a9ce7 | |
parent | 492bc2a3444fc4c1b12a7264389327e365c48287 (diff) |
add initialization script
-rw-r--r-- | README.md | 7 | ||||
-rwxr-xr-x | init.sh | 34 |
2 files changed, 41 insertions, 0 deletions
@@ -1,2 +1,9 @@ # hbak Simple distributed backup utility for btrfs. + +# Dependencies + +* btrfs-progs +* gpg +* netcat +* pv @@ -0,0 +1,34 @@ +#! /bin/sh + +find_partition_uuid() { + findmnt -nso UUID -M / +} + +HOST=$(hostname) + +read -p "Enter new passphrase: " -s PASSPHRASE +read -p "Enter subvolumes to backup: " SUBVOLS +read -p "Enter remotes to sync to: " REMOTES + +mkdir -p /etc/hbak.d +echo "${PASSPHRASE}" > /etc/hbak.d/passphrase +echo "${SUBVOLS}" > /etc/hbak.d/subvolumes +echo "${REMOTES}" > /etc/hbak.d/remotes + +chmod 0700 /etc/hbak.d +chmod 0600 /etc/hbak.d/* +chown -R root:root /etc/hbak.d + +mkdir -p /mnt/hbak +mount -o compress=zstd UUID=$(find_partition_uuid) /mnt/hbak + +btrfs subvolume create /mnt/hbak/snapshots +btrfs subvolume create /mnt/hbak/backups + +for SUBVOL in ${SUBVOLS}; do + btrfs subvolume snapshot -r /mnt/hbak/${SUBVOL} /mnt/hbak/snapshots/${SUBVOL} + + for REMOTE in ${REMOTES}; do + (echo "${HOST}_${SUBVOL}"; btrfs send /mnt/hbak/snapshots/${SUBVOL} | pv | gpg --batch --symmetric -a --cipher-algo AES256 --passphrase-file /etc/hbak.d/passphrase) | nc ${REMOTE} 45545 + done +done |