aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-12-17 12:02:26 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-12-17 12:02:26 +0100
commite599d576d621f4518f0026166c4e209f0a2e3171 (patch)
treee6c30649ebaa2b769234bf75012304f2389a9ce7
parent492bc2a3444fc4c1b12a7264389327e365c48287 (diff)
add initialization script
-rw-r--r--README.md7
-rwxr-xr-xinit.sh34
2 files changed, 41 insertions, 0 deletions
diff --git a/README.md b/README.md
index 5342a6f..3bdfddf 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,9 @@
# hbak
Simple distributed backup utility for btrfs.
+
+# Dependencies
+
+* btrfs-progs
+* gpg
+* netcat
+* pv
diff --git a/init.sh b/init.sh
new file mode 100755
index 0000000..e8abdd5
--- /dev/null
+++ b/init.sh
@@ -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