WIP: ZFS backup implementation
This commit is contained in:
7
roles/common/templates/zfsbackup/Dockerfile
Normal file
7
roles/common/templates/zfsbackup/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM python:3.10-alpine
|
||||
RUN \
|
||||
apk add openssh && \
|
||||
pip install zfs-autobackup && \
|
||||
ln -s /run-backup.sh /etc/periodic/daily/
|
||||
COPY ["cron.sh", "run-backup.sh", "/"]
|
||||
CMD ["/cron.sh"]
|
||||
4
roles/common/templates/zfsbackup/cron.sh
Executable file
4
roles/common/templates/zfsbackup/cron.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
exec busybox crond -f -l 0 -L /dev/stdout
|
||||
29
roles/common/templates/zfsbackup/run-backup.sh
Executable file
29
roles/common/templates/zfsbackup/run-backup.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
echo "running backup job"
|
||||
date -Iminutes
|
||||
|
||||
if [ ! -d ~/.ssh ]; then echo "error: $(realpath ~/.ssh) directory does not exist"; exit 1; fi
|
||||
|
||||
host_ip=$(ip r | head -1 | cut -d' ' -f3 | tr -d '\n')
|
||||
host=root@"$host_ip"
|
||||
remote=root@truenas.lab.home
|
||||
|
||||
if ! ssh -q "$host" exit; then echo "error: not able to ssh into host of container $host"; exit 1; fi
|
||||
if ! ssh -q "$remote" exit; then echo "error: not able to ssh into backup remote $remote"; exit 1; fi
|
||||
|
||||
hostname=$(ssh "$host" hostname | tr -d '\n')
|
||||
remote_dataset=Mass-Storage-New/Backup/$hostname
|
||||
zfs_prop_name="nas" # autobackup:nas = true
|
||||
|
||||
zfs-autobackup \
|
||||
--snapshot-format "{}_%Y-%m-%d_%H-%M_%S" \
|
||||
--encrypt \
|
||||
--ssh-source "$host" \
|
||||
--ssh-target "$remote" \
|
||||
"$zfs_prop_name" \
|
||||
"$remote_dataset"
|
||||
|
||||
echo "ran backup job"
|
||||
date -Iminutes
|
||||
Reference in New Issue
Block a user