diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-03-21 10:29:56 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-03-21 10:29:56 +0100 |
commit | 2224bfa7af546bcf41f7d4a2f91d603f1eb96f76 (patch) | |
tree | 8aaa331b4550b9f3f19050377b8b634a829def2d |
-rw-r--r-- | .gitignore | 4 | ||||
-rwxr-xr-x | backup | 7 | ||||
-rwxr-xr-x | env.def | 5 | ||||
-rw-r--r-- | exclude | 2 | ||||
-rwxr-xr-x | forget | 5 | ||||
-rw-r--r-- | readme.md | 15 | ||||
-rwxr-xr-x | run | 5 | ||||
-rw-r--r-- | systemd/backup.service | 9 | ||||
-rw-r--r-- | systemd/backup.timer | 8 |
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 @@ -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)" + @@ -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' @@ -0,0 +1,2 @@ +.cache/ +.npm/ @@ -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 @@ -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 |