aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-03-21 10:29:56 +0100
committerlonkaars <loek@pipeframe.xyz>2022-03-21 10:29:56 +0100
commit2224bfa7af546bcf41f7d4a2f91d603f1eb96f76 (patch)
tree8aaa331b4550b9f3f19050377b8b634a829def2d
initial commitHEADmaster
-rw-r--r--.gitignore4
-rwxr-xr-xbackup7
-rwxr-xr-xenv.def5
-rw-r--r--exclude2
-rwxr-xr-xforget5
-rw-r--r--readme.md15
-rwxr-xr-xrun5
-rw-r--r--systemd/backup.service9
-rw-r--r--systemd/backup.timer8
9 files changed, 60 insertions, 0 deletions
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