From 2224bfa7af546bcf41f7d4a2f91d603f1eb96f76 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 21 Mar 2022 10:29:56 +0100 Subject: initial commit --- .gitignore | 4 ++++ backup | 7 +++++++ env.def | 5 +++++ exclude | 2 ++ forget | 5 +++++ readme.md | 15 +++++++++++++++ run | 5 +++++ systemd/backup.service | 9 +++++++++ systemd/backup.timer | 8 ++++++++ 9 files changed, 60 insertions(+) create mode 100644 .gitignore create mode 100755 backup create mode 100755 env.def create mode 100644 exclude create mode 100755 forget create mode 100644 readme.md create mode 100755 run create mode 100644 systemd/backup.service create mode 100644 systemd/backup.timer diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f104b21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +conf.d/* +pre.d/* +post.d/* +env diff --git a/backup b/backup new file mode 100755 index 0000000..74d967c --- /dev/null +++ b/backup @@ -0,0 +1,7 @@ +#!/bin/bash +cd $(dirname $0) +source ./env +[[ -f "./pre.d/$(basename $1)" ]] && source "./pre.d/$(basename $1)" +restic backup --files-from $1 --exclude-file exclude --tag "$(basename $1)" +[[ -f "./post.d/$(basename $1)" ]] && source "./post.d/$(basename $1)" + diff --git a/env.def b/env.def new file mode 100755 index 0000000..569100e --- /dev/null +++ b/env.def @@ -0,0 +1,5 @@ +#!/bin/sh +# copy this file as 'env' and set these options +export RESTIC_REPOSITORY='/mnt/backup1' +export RESTIC_PASSWORD='' +export RESTIC_CACHE_DIR='/var/cache/restic' diff --git a/exclude b/exclude new file mode 100644 index 0000000..e8485b4 --- /dev/null +++ b/exclude @@ -0,0 +1,2 @@ +.cache/ +.npm/ diff --git a/forget b/forget new file mode 100755 index 0000000..6049301 --- /dev/null +++ b/forget @@ -0,0 +1,5 @@ +#!/bin/bash +cd $(dirname $0) +source ./env +restic forget --prune --tag "$(basename $1)" --keep-last 2 --group-by tags + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..cc2e752 --- /dev/null +++ b/readme.md @@ -0,0 +1,15 @@ +# backup + +this is a simple backup setup that I use on my home server + +`conf.d` contains files that have file glob lists in them, like `.gitignore` +files. `./run` then runs restic for each file in `conf.d` and backs up the file +list under the tag of the file name. if a file with the same name as in +`conf.d` exists in `pre.d` it gets run before restic, and the same goes for +`post.d` but it's after restic. `env` contains environment variables for +restic, and gets sourced by `backup`. + +by default, only the last two backups are stored, and old ones get deleted. +this can be edited in `forget`. + +systemd unit/timer files are included diff --git a/run b/run new file mode 100755 index 0000000..0bc8ae6 --- /dev/null +++ b/run @@ -0,0 +1,5 @@ +#!/bin/sh +cd $(dirname $0) +find conf.d -type f -exec ./backup {} \; +find conf.d -type f -exec ./forget {} \; + diff --git a/systemd/backup.service b/systemd/backup.service new file mode 100644 index 0000000..4e35922 --- /dev/null +++ b/systemd/backup.service @@ -0,0 +1,9 @@ +[Unit] +Description=Backup cronjob + +[Service] +Type=oneshot +ExecStart=/root/backup/run + +[Install] +WantedBy=multi-user.target diff --git a/systemd/backup.timer b/systemd/backup.timer new file mode 100644 index 0000000..12cb76e --- /dev/null +++ b/systemd/backup.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Backup cronjob + +[Timer] +OnCalendar=*-*-* 03:00:00 + +[Install] +WantedBy=timers.target -- cgit v1.2.3