]> code.delx.au - monosys/commitdiff
Strip down to just bsnap
authorJames Bunton <jamesbunton@delx.net.au>
Thu, 8 Aug 2019 22:47:45 +0000 (08:47 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Thu, 8 Aug 2019 22:47:45 +0000 (08:47 +1000)
18 files changed:
PKGBUILD
backup [deleted file]
backup.service [deleted file]
backup.timer [deleted file]
bsnap [moved from bsnap-lvm with 100% similarity]
bsnap-borg.install [deleted file]
bsnap-zfs [deleted file]
bsnap-zfs.install [deleted file]
etc-borg-root-env [deleted file]
etc-borg-root-exclude [deleted file]
setup-root-ssh [deleted file]
znap-daily.service [deleted file]
znap-daily.timer [deleted file]
znap-frequent.service [deleted file]
znap-frequent.timer [deleted file]
znap-hourly.service [deleted file]
znap-hourly.timer [deleted file]
znap-take [deleted file]

index 542caa6b3354e7fb947a908c94ac3489b38137f6..5af108e96aa1737c67ba4912e6e3541c24ec3a11 100644 (file)
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,75 +1,14 @@
-pkgbase="bsnap"
-pkgname=("bsnap-borg" "bsnap-zfs" "bsnap-lvm")
-pkgver=1.0.6
-pkgrel=2
+pkgname=bsnap
+pkgver=2.0.0
+pkgrel=1
 arch=("any")
-source=("backup"
-        "backup.service"
-        "backup.timer"
-        "bsnap-lvm"
-        "setup-root-ssh"
-        "bsnap-zfs"
-        "etc-borg-root-env"
-        "etc-borg-root-exclude"
-        "znap-daily.service"
-        "znap-daily.timer"
-        "znap-frequent.service"
-        "znap-frequent.timer"
-        "znap-hourly.service"
-        "znap-hourly.timer"
-        "znap-take")
-md5sums=('bb0e105cbf551b2c7cfbd840e8d2e7df'
-         'ebc356d63196ff3ea1b3bdc51d00ae3a'
-         'bf94b96bf063e1cff498a1a08dc92ac6'
-         '38c60af3cf213bd6fd62ef70c95295a9'
-         '6f173fb271b64dfcc84b2536b076b36f'
-         'ebf29f2525fc5ca671f4c24b90908d11'
-         '05897a7215d9ef75e174e3dec94ca416'
-         'c1a6bc56587c272a9a567c74f2e0ed51'
-         'b233a09cdbd997699e1ba03559ef892a'
-         'eeafe687944641a401a7f7f902dac73a'
-         '606b981ecbde6f7c90f135e91986b678'
-         '916f9b7a74c4516da6aad084c0c32e3e'
-         '832f2cd78dc266d97d3ad37d11448462'
-         '0624408bb7c90a36e11f89eb64a8923e'
-         '777d9c0dc722d1098323d0ea5db0ee89')
+source=("bsnap")
+md5sums=('38c60af3cf213bd6fd62ef70c95295a9')
 
-package_bsnap-borg() {
-    pkgdesc="Borg backup tools"
-    depends=("borg")
-    backup=("etc/borg/root/exclude" "etc/borg/root/env")
-    install="bsnap-borg.install"
-
-    mkdir -p "${pkgdir}/usr/bin/"
-    install -m 0755 backup setup-root-ssh "${pkgdir}/usr/bin/"
-
-    mkdir -p "${pkgdir}/etc/borg/root/"
-    install -m 0644 -T etc-borg-root-exclude "${pkgdir}/etc/borg/root/exclude"
-    install -m 0600 -T etc-borg-root-env "${pkgdir}/etc/borg/root/env"
-
-    mkdir -p "${pkgdir}/usr/lib/systemd/system/"
-    install -m 0644 backup.{timer,service} "${pkgdir}/usr/lib/systemd/system/"
-}
-
-package_bsnap-zfs() {
-    pkgdesc="Backup / snapshot tools for ZFS"
-    depends=("zfs-utils" "zfs-auto-snapshot")
-    conflicts=("bsnap-lvm")
-    install="bsnap-zfs.install"
-
-    mkdir -p "${pkgdir}/usr/bin/"
-    install -m 0755 -T bsnap-zfs "${pkgdir}/usr/bin/bsnap"
-    install -m 0755 znap-take "${pkgdir}/usr/bin/"
-
-    mkdir -p "${pkgdir}/usr/lib/systemd/system/"
-    install -m 0644 znap-*.{timer,service} "${pkgdir}/usr/lib/systemd/system/"
-}
-
-package_bsnap-lvm() {
+package() {
     pkgdesc="Backup / snapshot tools for LVM or btrfs"
     optdepends=("lvm2" "btrfs-progs")
-    conflicts=("bsnap-zfs")
 
     mkdir -p "${pkgdir}/usr/bin/"
-    install -m 0755 -T bsnap-lvm "${pkgdir}/usr/bin/bsnap"
+    install -m 0755 -T bsnap "${pkgdir}/usr/bin/bsnap"
 }
diff --git a/backup b/backup
deleted file mode 100755 (executable)
index 3af2b3e..0000000
--- a/backup
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/bin/bash
-
-set -eu
-
-if [ "$(id -u)" -ne 0 ]; then
-    echo "Must be root"
-    exit 1
-fi
-
-if [ "$(pgrep backup)" != "$$" ]; then
-    echo "Backup is still running!"
-    exit 1
-fi
-
-if [ -z "${1:-}" ]; then
-    echo "Usage: $0 root"
-    exit 1
-fi
-
-BACKUP_PROFILE="$1"
-source "/etc/borg/${BACKUP_PROFILE}/env"
-HOME=/root
-
-ionice -c 3 -p $$
-renice -n 19 -p $$ > /dev/null
-
-if [ "$BACKUP_SNAP" -eq 1 ]; then
-    echo ">>> Snapshotting"
-    bsnap on
-fi
-
-cd "$BACKUP_PATH"
-
-echo ">>> Starting backup"
-borg create \
-    $([ -t 0 ] && echo --progress) \
-    --info --stats \
-    --compression lz4 \
-    --exclude-from "/etc/borg/${BACKUP_PROFILE}/exclude" \
-    "${BACKUP_REPO}::{hostname}-{now}" .
-
-echo ">>> Pruning old backups"
-borg prune \
-    --info --stats \
-    --keep-daily=7 \
-    --keep-weekly=4 \
-    --keep-monthly=12 \
-    --prefix='{hostname}-' \
-    "$BACKUP_REPO"
-
-cd /
-
-if [ "$BACKUP_SNAP" -eq 1 ]; then
-    echo ">>> Unsnapshotting"
-    bsnap off
-fi
-
-exit 0
diff --git a/backup.service b/backup.service
deleted file mode 100644 (file)
index 5c31b45..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-[Unit]
-Description=Borg backup service
-
-[Service]
-Type=oneshot
-ExecStart=/usr/bin/backup root
diff --git a/backup.timer b/backup.timer
deleted file mode 100644 (file)
index 94d13d0..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-[Unit]
-Description=Borg backup timer
-
-[Timer]
-OnCalendar=*-*-* 03:00:00
-RandomizedDelaySec=7200
-Persistent=true
-
-[Install]
-WantedBy=timers.target
diff --git a/bsnap-lvm b/bsnap
similarity index 100%
rename from bsnap-lvm
rename to bsnap
diff --git a/bsnap-borg.install b/bsnap-borg.install
deleted file mode 100644 (file)
index a0525ad..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#! bash
-
-function post_install {
-    if grep -q "SECRET" /etc/borg/root/env; then
-        echo ">>> Generating passphrase for /etc/borg/root/env"
-        BORG_PASSPHRASE="$(dd if=/dev/urandom of=/dev/stdout bs=1 count=15 2>/dev/null | base64)"
-        sed -i "s|SECRET|$BORG_PASSPHRASE|" "${pkgdir}/etc/borg/root/env"
-    fi
-
-    if ! systemctl is-enabled backup.timer > /dev/null; then
-        echo ">>> You should run: systemctl enable backup.timer"
-    fi
-}
diff --git a/bsnap-zfs b/bsnap-zfs
deleted file mode 100755 (executable)
index dcd8c54..0000000
--- a/bsnap-zfs
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/bin/bash
-
-set -eu
-
-function snap {
-    unsnap
-
-    znap-take bsnap 1
-    mount_snapshots
-    mkdir -p /a/boot
-    mount --bind /boot /a/boot
-}
-
-function unsnap {
-    if ! [ -d /a ]; then
-        return
-    fi
-
-    umount /a/boot || true
-    rmdir /a/boot || true
-
-    if ls &> /dev/null /a/*; then
-        umount /a/* || true
-        rmdir /a/* || true
-    fi
-    rmdir /a || true
-}
-
-function list_snapshots {
-    local fsname
-    for fsname in $(zfs list -H -o name); do
-        zfs list -H -o name -S creation -t snapshot -d 1 -r "$fsname" | \
-            grep '@znap_....-..-..-...._bsnap' | \
-            head -n1
-    done
-}
-
-function mount_snapshots {
-    local snapname
-    local fsname
-    local mountpoint
-
-    for snapname in $(list_snapshots); do
-        fsname="${snapname%@*}"
-        mountpoint="/a/$(echo "$fsname" | cut -d/ -f2- | tr '/' '_')"
-        mkdir -p "$mountpoint"
-        mount -t zfs "$snapname" "$mountpoint"
-    done
-}
-
-if [ "$(id -u)" -ne 0 ]; then
-    echo "Must be root"
-    exit 1
-fi
-
-if [ "${1:-}" = "off" ]; then
-    unsnap
-elif [ "${1:-}" = "on" ]; then
-    snap
-else
-    echo "Usage: $0 on|off"
-    exit 1
-fi
diff --git a/bsnap-zfs.install b/bsnap-zfs.install
deleted file mode 100644 (file)
index 5c558c4..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#! bash
-
-function post_install {
-    if ! zfs get all -t filesystem | grep -q "backup:"; then
-        echo
-        echo ">>> You'll need to configure ZFS properties for automatic snapshots to work"
-        echo ">>> zfs set backup:frequent=on backup:hourly=on backup:daily=on backup:bsnap=on tank/root"
-        echo
-        echo ">>> Then enable and start some of the znap-*.timer systemd units."
-    fi
-}
diff --git a/etc-borg-root-env b/etc-borg-root-env
deleted file mode 100644 (file)
index 6627c5f..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-BACKUP_SNAP=1
-BACKUP_PATH="/a"
-BACKUP_REPO="backuphost:root"
-export BORG_PASSPHRASE="SECRET"
diff --git a/etc-borg-root-exclude b/etc-borg-root-exclude
deleted file mode 100644 (file)
index b2658a0..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-sh:**/.cache
-sh:**/.thumbnails
-sh:**/tmp
-
-sh:var/cache/apt/archives/*
-sh:var/cache/pacman/*
-sh:var/lib/systemd/coredump
diff --git a/setup-root-ssh b/setup-root-ssh
deleted file mode 100755 (executable)
index c85c8c7..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-
-if [ "$(id -u)" -ne 0 ]; then
-    echo "Must be root"
-    exit 1
-fi
-
-set -eu
-
-if [ -f /root/.ssh/id_rsa.pub ]; then
-    echo "SSH public key already exists. Exiting!"
-    exit 1
-fi
-
-if [ -f /root/.ssh/config ]; then
-    echo "SSH config already exists. Exiting!"
-    exit 1
-fi
-
-umask 0077
-
-echo ">>> ssh-keygen"
-ssh-keygen
-
-cat /root/.ssh/id_rsa.pub
-
-echo ">>> creating .ssh/config"
-cat > /root/.ssh/config <<EOF
-Host *
-    HashKnownHosts no
-
-Host backuphost
-    User borg
-    Hostname backup.example.com
-EOF
diff --git a/znap-daily.service b/znap-daily.service
deleted file mode 100644 (file)
index 332e400..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-[Unit]
-Description=ZFS daily snapshot service
-
-[Service]
-Type=oneshot
-ExecStart=/usr/bin/znap-take daily 30
diff --git a/znap-daily.timer b/znap-daily.timer
deleted file mode 100644 (file)
index 65dd773..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-[Unit]
-Description=ZFS daily snapshot timer
-
-[Timer]
-OnCalendar=daily
-Persistent=true
-
-[Install]
-WantedBy=timers.target
diff --git a/znap-frequent.service b/znap-frequent.service
deleted file mode 100644 (file)
index 6ee8b32..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-[Unit]
-Description=ZFS frequent snapshot service
-
-[Service]
-Type=oneshot
-ExecStart=/usr/bin/znap-take frequent 10
diff --git a/znap-frequent.timer b/znap-frequent.timer
deleted file mode 100644 (file)
index 4aca231..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-[Unit]
-Description=ZFS frequent snapshot timer
-
-[Timer]
-OnCalendar=*:0/5
-Persistent=true
-
-[Install]
-WantedBy=timers.target
diff --git a/znap-hourly.service b/znap-hourly.service
deleted file mode 100644 (file)
index b3e5796..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-[Unit]
-Description=ZFS hourly snapshot service
-
-[Service]
-Type=oneshot
-ExecStart=/usr/bin/znap-take hourly 12
diff --git a/znap-hourly.timer b/znap-hourly.timer
deleted file mode 100644 (file)
index 2943736..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-[Unit]
-Description=ZFS hourly snapshot timer
-
-[Timer]
-OnCalendar=hourly
-Persistent=true
-
-[Install]
-WantedBy=timers.target
diff --git a/znap-take b/znap-take
deleted file mode 100755 (executable)
index 8a64f10..0000000
--- a/znap-take
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-set -eu
-
-if [ -z "${1:-}" ] || [ -z "${2:-}" ]; then
-    echo "Usage: $0 label keep"
-    exit 1
-fi
-
-label="$1"
-keep="$2"
-
-zfs list -H -o "backup:${label},name" | \
-    awk -F'\t' '$1 == "on" { print $2 }' | \
-    xargs -d '\n' zfs-auto-snapshot --prefix=znap --label="$label" --keep="$keep"