From 9760cd05ec82a821526008a826cd115f1a159c0e Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Tue, 18 Jan 2022 20:22:54 +0100 Subject: [PATCH 01/30] Truly support custom PREFIX= install * Before, doing `$ PREFIX=/usr/local make install` would install files to`/usr/local/usr/local..` which is wrong * With this PR, files will be installed to the expected location e.g. `/usr/local/etc/restic` * `Makefile` almost completely rewritten * As e.g. `default.env` would source `_global.env`, `default.env` must be edited to find the right location of `_global.env` depending on what `$PREFIX` was set to. * see documented build stages in the `Makefile` itself. * Made sure that the rules are correct so that only modifed files are installed, not all at once unnecessarily like before. * A sub-goal was that the [PKGBUILD](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=restic-systemd-automatic-backup#n20) for Arch should not need to do any custom install configuration, to keep everything easier to maintain. `$ make install` should work out of the box for Arch. * Additionally added the `-b` flag to `install(1)` that makes a backup of existing `etc/restic/*` files before installing a newer version. Fixes #49 --- .gitignore | 6 +- CHANGELOG.md | 14 ++ Makefile | 154 +++++++++++++----- README.md | 27 ++- etc/cron.d/restic | 2 +- .../{_global.env.template => _global.env} | 4 +- .../{default.env.template => default.env} | 2 +- etc/restic/{pw.txt.template => pw.txt} | 0 {usr/local/sbin => sbin}/cron_mail | 0 .../sbin => sbin}/nm-unmetered-connection.sh | 0 {usr/local/sbin => sbin}/restic_backup.sh | 0 {usr/local/sbin => sbin}/restic_check.sh | 0 {usr/local/sbin => sbin}/resticw | 0 {usr/local/sbin => sbin}/systemd-email | 0 .../system/nm-unmetered-connection.service | 3 +- .../systemd/system/restic-backup@.service | 2 +- .../lib}/systemd/system/restic-backup@.timer | 0 .../lib}/systemd/system/restic-check@.service | 2 +- .../lib}/systemd/system/restic-check@.timer | 0 .../systemd/system/status-email-user@.service | 2 +- 20 files changed, 158 insertions(+), 60 deletions(-) rename etc/restic/{_global.env.template => _global.env} (88%) rename etc/restic/{default.env.template => default.env} (97%) rename etc/restic/{pw.txt.template => pw.txt} (100%) rename {usr/local/sbin => sbin}/cron_mail (100%) rename {usr/local/sbin => sbin}/nm-unmetered-connection.sh (100%) rename {usr/local/sbin => sbin}/restic_backup.sh (100%) rename {usr/local/sbin => sbin}/restic_check.sh (100%) rename {usr/local/sbin => sbin}/resticw (100%) rename {usr/local/sbin => sbin}/systemd-email (100%) rename {etc => usr/lib}/systemd/system/nm-unmetered-connection.service (63%) rename {etc => usr/lib}/systemd/system/restic-backup@.service (77%) rename {etc => usr/lib}/systemd/system/restic-backup@.timer (100%) rename {etc => usr/lib}/systemd/system/restic-check@.service (70%) rename {etc => usr/lib}/systemd/system/restic-check@.timer (100%) rename {etc => usr/lib}/systemd/system/status-email-user@.service (82%) diff --git a/.gitignore b/.gitignore index 9ea865d..7fa0aa3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ -# Prevent check-in of these sensitive files. Instead they are generated from the corresponding *.template file. -etc/restic/pw.txt -etc/restic/_global.env -etc/restic/default.env +# make install +/build # IntelliJ .idea/ diff --git a/CHANGELOG.md b/CHANGELOG.md index a84ccdd..8ffd3ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - `resticw` wrapper for working with different profiles without the need to source the profiles first. +- `$make install` will now make a timestamped backup of any existing `/etc/restic/*` files before installing a newer version. + +### Changed +- **BREAKING CHANGE** moved systemd installation with makefile from `/etc/systemd/system` to `/usr/lib/systemd/system` as this is what packages should do. This is to be able to simplify the arch [PKGBUILD](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=restic-systemd-automatic-backup) so that it does not need to do anything else than `make install`. + - If you upgrade form an existing install, you should disable and then re-enable the timer, so that the symlink is pointing to the new location of the timer. + ```console + # systemctl disable restic-backup@.timer + # systemctl enable restic-backup@.timer + ``` +- **BREAKING CHANGE** moved script installation with makefile from `/usr/local/sbin` to `/sbin` to have a simpler interface to work with `$PREFIX`. + +### Fixed +- Installation with custom `PREFIX` now works properly with Make: `$ PREFIX=/usr/local make install` whill now install everything at the expected location. With this, it's easy to use this script as non-root user on e.g. an macOS system. ## [4.0.0] - 2022-02-01 ### Fixed @@ -46,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - `restic_backup.sh` now finds `.backup_exclude` files on each backup path as intended. +- Install executeables to `$PREFIX/sbin` instead of `$PREFIX/user/local/sbin`, so that `$ PREFIX=/usr/local make install` does what is expected. ## [1.0.1] - 2021-12-03 ### Fixed diff --git a/Makefile b/Makefile index c8b81ed..40c5d6b 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,77 @@ -# Not file targets. -.PHONY: help install install-scripts install-conf install-systemd uninstall +### Notes ### +# This build process is done in three stages: +# 1. copy source files to the local build directory. +# 2. replace the string "$INSTALL_PREFIX" with the value of $PREFIX +# 3. copy files from the build directory to the target directory. +# +# Why this dance? +# * To fully support that a user can install this project to a custom path e.g. $(PREFIX=/usr/local make install), +# we need to modify the files that refer to other files on disk. We do this by having a placeholder "$INSTALL_PREFIX" +# that is substituted with the value of $PREFIX when installed +# * We don't want to modify the files that are controlled by git, thus let's copy them to a build directory and then modify. + +### Non-file targets ### +.PHONY: help install install-scripts install-conf install-systemd clean uninstall ### Macros ### -SRCS_SCRIPTS = $(filter-out %cron_mail, $(wildcard usr/local/sbin/*)) +NOW := $(shell date +%Y-%m-%d_%H:%M:%S) + +# Source: https://stackoverflow.com/a/14777895/265508 +ifeq ($(OS),Windows_NT) + CUR_OS := Windows +else + CUR_OS := $(shell uname) +endif + +# GNU install and macOS install have incompatible command line arguments. +ifeq ($(CUR_OS),Darwin) + BAK_SUFFIX = -B .$(NOW).bak +else + BAK_SUFFIX = --suffix=.$(NOW).bak +endif + +# Create parent directories of a file, if not existing. +# Reference: https://stackoverflow.com/a/25574592/265508 +MKDIR_PARENTS=sh -c '\ + dir=$$(dirname $$1); \ + test -d $$dir || mkdir -p $$dir \ + ' MKDIR_PARENTS + + +# Source directories. +DIR_SCRIPTS = sbin +DIR_CONF = etc/restic +DIR_SYSTEMD = usr/lib/systemd/system + +# Source files. +SRCS_SCRIPTS = $(filter-out %cron_mail, $(wildcard $(DIR_SCRIPTS)/*)) # $(sort) remove duplicates that comes from running make install >1 times. -SRCS_CONF = $(sort $(patsubst %.template, %, $(wildcard etc/restic/*))) -SRCS_SYSTEMD = $(wildcard etc/systemd/system/*) +SRCS_CONF = $(sort $(patsubst %.template, %, $(wildcard $(DIR_CONF)/*))) +SRCS_SYSTEMD = $(wildcard $(DIR_SYSTEMD)/*) -# To change the installation root path, set the PREFIX variable in your shell's environment, like: -# $ PREFIX=/usr/local make install -# $ PREFIX=/tmp/test make install -DEST_SCRIPTS = $(PREFIX)/usr/local/sbin -DEST_CONF = $(PREFIX)/etc/restic -DEST_SYSTEMD = $(PREFIX)/etc/systemd/system -INSTALLED_FILES = $(addprefix $(PREFIX)/, $(SRCS_SCRIPTS) $(SRCS_CONF) $(SRCS_SYSTEMD)) +# Local build directory. Sources will be copied here, modified and then installed from this directory. +BUILD_DIR := build +BUILD_DIR_SCRIPTS = $(BUILD_DIR)/$(DIR_SCRIPTS) +BUILD_DIR_CONF = $(BUILD_DIR)/$(DIR_CONF) +BUILD_DIR_SYSTEMD = $(BUILD_DIR)/$(DIR_SYSTEMD) + +# Sources copied to build directory. +BUILD_SRCS_SCRIPTS = $(addprefix $(BUILD_DIR)/, $(SRCS_SCRIPTS)) +BUILD_SRCS_CONF = $(addprefix $(BUILD_DIR)/, $(SRCS_CONF)) +BUILD_SRCS_SYSTEMD = $(addprefix $(BUILD_DIR)/, $(SRCS_SYSTEMD)) + +# Destination directories +DEST_DIR_SCRIPTS = $(PREFIX)/$(DIR_SCRIPTS) +DEST_DIR_CONF = $(PREFIX)/$(DIR_CONF) +DEST_DIR_SYSTEMD = $(PREFIX)/$(DIR_SYSTEMD) + +# Destination files. +DEST_SCRIPTS = $(addprefix $(PREFIX)/, $(SRCS_SCRIPTS)) +DEST_CONF = $(addprefix $(PREFIX)/, $(SRCS_CONF)) +DEST_SYSTEMD = $(addprefix $(PREFIX)/, $(SRCS_SYSTEMD)) + +INSTALLED_FILES = $(DEST_SCRIPTS) $(DEST_CONF) $(DEST_SYSTEMD) ### Targets ### # target: all - Default target. @@ -24,33 +81,9 @@ all: install help: @egrep "#\starget:" [Mm]akefile | sed 's/\s-\s/\t\t\t/' | cut -d " " -f3- | sort -d -# target: install - Install all files -install: install-scripts install-conf install-systemd - - -# target: install-scripts - Install executables. -install-scripts: - install -d $(DEST_SCRIPTS) - install -m 0744 $(filter-out %/resticw, $(SRCS_SCRIPTS)) $(DEST_SCRIPTS) - install -m 0755 usr/local/sbin/resticw $(DEST_SCRIPTS) - -# Copy templates to new files with restricted permissions. -# Why? Because the non-template files are git-ignored to prevent that someone who clones or forks this repo checks in their sensitive data like the B2 password! -etc/restic/_global.env etc/restic/default.env etc/restic/pw.txt: - install -m 0600 $@.template $@ - -# target: install-conf - Install restic configuration files. -# will create these files locally only if they don't already exist -# `|` means that dependencies are order-only, i.e. only created if they don't already exist. -install-conf: | $(SRCS_CONF) - install -d $(DEST_CONF) - install -b -m 0600 $(SRCS_CONF) $(DEST_CONF) - $(RM) etc/restic/_global.env etc/restic/default.env etc/restic/pw.txt - -# target: install-systemd - Install systemd timer and service files. -install-systemd: - install -d $(DEST_SYSTEMD) - install -m 0644 $(SRCS_SYSTEMD) $(DEST_SYSTEMD) +# target: clean - Remove build files. +clean: + $(RM) -r $(BUILD_DIR) # target: uninstall - Uninstall ALL files from the install targets. uninstall: @@ -58,3 +91,46 @@ uninstall: echo $(RM) $$file; \ $(RM) $$file; \ done + +# To change the installation root path, set the PREFIX variable in your shell's environment, like: +# $ PREFIX=/usr/local make install +# $ PREFIX=/tmp/test make install +# target: install - Install all files +install: install-scripts install-conf install-systemd + +# Install targets - add build sources to prereqa as well, so that build dir is re-created if deleted (expected behaviour). +# target: install-scripts - Install executables. +install-scripts: $(DEST_SCRIPTS) +# target: install-conf - Install restic configuration files. +install-conf: $(DEST_CONF) $(BUILD_SRCS_CONF) +# target: install-systemd - Install systemd timer and service files. +install-systemd: $(DEST_SYSTEMD) + + +# Copies sources to build directory & replace "$INSTALL_PREFIX" +# dir= line needs to be in the same subshell to use shared envvars. Reference: https://stackoverflow.com/a/36419671/265508 +$(BUILD_DIR)/% : % + ${MKDIR_PARENTS} $@ + cp $< $@ + sed -i.bak -e "s|\$$INSTALL_PREFIX|$$PREFIX|g" $@; rm $@.bak + + +# For the destination files to be built, build-files must exist. +#$(DEST_SCRIPTS): $(BUILD_SRCS_SCRIPTS) +#$(DEST_CONF): $(BUILD_SRCS_CONF) +#$(DEST_SYSTEMD): $(BUILD_SRCS_SYSTEMD) + +# Install destination script files. +$(DEST_DIR_SCRIPTS)/%: $(BUILD_DIR_SCRIPTS)/% + ${MKDIR_PARENTS} $@ + install -m 0744 $< $@ + +# Install destination conf files. Additionally backup existing files. +$(DEST_DIR_CONF)/%: $(BUILD_DIR_CONF)/% + ${MKDIR_PARENTS} $@ + install -m 0600 -b $(BAK_SUFFIX) $< $@ + +# Install destination script files. +$(DEST_DIR_SYSTEMD)/%: $(BUILD_DIR_SYSTEMD)/% + ${MKDIR_PARENTS} $@ + install -m 0644 $< $@ diff --git a/README.md b/README.md index cb0a511..90374be 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Nevertheless the project should work out of the box, be minimal but still open t * `/etc/restic/backup_exclude.txt` - List of file patterns to ignore. This will trim down your backup size and the speed of the backup a lot when done properly! 1. Initialize remote repo as described [below](#3-initialize-remote-repo) 1. Configure [how often](https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events) back up should be made. - * Edit if needed `OnCalendar` in `/etc/systemd/system/restic-check@.timer`. + * Edit if needed `OnCalendar` in `/usr/lib/systemd/system/restic-check@.timer`. 1. Enable automated backup for starting with the system (`enable` creates symlinks): ```console $ sudo systemctl start restic-backup@default.timer @@ -91,6 +91,18 @@ $ git clone https://github.com/erikw/restic-systemd-automatic-backup.git && cd $ $ sudo make install ```` +If you want to install everything manually, we will install files to `/etc`, `/sbin`, and not use the `$make install` command, then you need to clean up a placeholder `$INSTALL_PREFIX` in the souce files first by running: +```console +$ find etc sbin -type f -exec sed -i.bak -e 's|$INSTALL_PREFIX||g' {} \; -exec rm {}.bak \; +``` +and you should now see that all files have been changed like e.g. +```diff +-export RESTIC_PASSWORD_FILE="$INSTALL_PREFIX/etc/restic/pw.txt" ++export RESTIC_PASSWORD_FILE="/etc/restic/pw.txt" +``` +This prefix is there so that make users can set a different `$PREFIX` when installing like `PREFIX=/usr/local make install`. So if we don't use the makefile, we need to remove this prefix with the command above just. + + Arch Linux users can install the aur package [restic-systemd-automatic-backup](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/) e.g.: ```console $ yaourt -S restic-systemd-automatic-backup @@ -126,7 +138,7 @@ $ restic init ``` ## 4. Script for doing the backup -Put this file in `/usr/local/sbin`: +Put this file in `/sbin`: * `restic_backup.sh`: A script that defines how to run the backup. The intention is that you should not need to edit this script yourself, but be able to control everything from the `*.env` profiles. Restic support exclude files. They list file pattern paths to exclude from you backups, files that just occupy storage space, backup-time, network and money. `restic_backup.sh` allows for a few different exclude files. @@ -139,7 +151,7 @@ Now see if the backup itself works, by running as root ```console $ sudo -i $ source /etc/restic/default.env -$ /usr/local/sbin/restic_backup.sh +$ /sbin/restic_backup.sh ```` ## 6. Verify the backup @@ -159,8 +171,7 @@ $ ls /mnt/restic ## 7. Backup automatically; systemd service + timer Now we can do the modern version of a cron-job, a systemd service + timer, to run the backup every day! -Put these files in `/etc/systemd/system/`: - +Put these files in `/etc/systemd/system` (note that the Makefile installs as package to `/usr/lib/systemd/system`) * `restic-backup@.service`: A service that calls the backup script with the specified profile. The profile is specified by the value after `@` when running it (see below). * `restic-backup@.timer`: A timer that starts the former backup every day (same thing about profile here). @@ -204,7 +215,7 @@ $ journalctl -f -u restic-backup@default.service ## 8. Email notification on failure We want to be aware when the automatic backup fails, so we can fix it. Since my laptop does not run a mail server, I went for a solution to set up my laptop to be able to send emails with [postfix via my Gmail](https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/). Follow the instructions over there. -Put this file in `/usr/local/sbin`: +Put this file in `/sbin`: * `systemd-email`: Sends email using sendmail(1). This script also features time-out for not spamming Gmail servers and getting my account blocked. Put this files in `/etc/systemd/system/`: @@ -216,7 +227,7 @@ As you maybe noticed already before, `restic-backup.service` is configured to st ## 9. Optional: automated backup checks Once in a while it can be good to do a health check of the remote repository, to make sure it's not getting corrupt. This can be done with `$ restic check`. -There is companion scripts, service and timer (`*check*`) to restic-backup.sh that checks the restic backup for errors; look in the repo in `etc/systemd/system` and `usr/local/sbin` and copy what you need over to their corresponding locations. +There is companion scripts, service and timer (`*check*`) to restic-backup.sh that checks the restic backup for errors; look in the repo in `usr/lib/systemd/system/` and `sbin/` and copy what you need over to their corresponding locations. ```console $ sudo -i @@ -245,7 +256,7 @@ straightforward (it needs to run with sudo to read environment). Just run: If you want to run an all-classic cron job instead, do like this: * `etc/cron.d/restic`: Depending on your system's cron, put this in `/etc/cron.d/` or similar, or copy the contents to $(sudo crontab -e). The format of this file is tested under FreeBSD, and might need adaptions depending on your cron. -* `usr/local/sbin/cron_mail`: A wrapper for running cron jobs, that sends output of the job as an email using the mail(1) command. +* `sbin/cron_mail`: A wrapper for running cron jobs, that sends output of the job as an email using the mail(1) command. # Uninstall diff --git a/etc/cron.d/restic b/etc/cron.d/restic index b510fc0..eca6735 100644 --- a/etc/cron.d/restic +++ b/etc/cron.d/restic @@ -1,5 +1,5 @@ SHELL=/bin/sh -PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:/usr/local/sbin/ +PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:$INSTALL_PREFIX/sbin/ # Order of crontab fields # minute hour mday month wday command # Reference: https://www.freebsd.org/doc/handbook/configtuning-cron.html diff --git a/etc/restic/_global.env.template b/etc/restic/_global.env similarity index 88% rename from etc/restic/_global.env.template rename to etc/restic/_global.env index 5bd7c6c..b70a154 100644 --- a/etc/restic/_global.env.template +++ b/etc/restic/_global.env @@ -8,9 +8,9 @@ # The restic repository encryption key -export RESTIC_PASSWORD_FILE="/etc/restic/pw.txt" +export RESTIC_PASSWORD_FILE="$INSTALL_PREFIX/etc/restic/pw.txt" # The global restic exclude file -export RESTIC_BACKUP_EXCLUDE_FILE="/etc/restic/backup_exclude.txt" +export RESTIC_BACKUP_EXCLUDE_FILE="$INSTALL_PREFIX/etc/restic/backup_exclude.txt" # Backblaze B2 credentials keyID & applicationKey pair. # Restic environment variables are documented at https://restic.readthedocs.io/en/latest/040_backup.html#environment-variables diff --git a/etc/restic/default.env.template b/etc/restic/default.env similarity index 97% rename from etc/restic/default.env.template rename to etc/restic/default.env index 967d390..eec4e1a 100644 --- a/etc/restic/default.env.template +++ b/etc/restic/default.env @@ -9,7 +9,7 @@ # Thus you don't have to provide all the arguments like # $ restic --repo ... --password-file ... -source /etc/restic/_global.env +source $INSTALL_PREFIX/etc/restic/_global.env # Below envvar will override those in _global.env diff --git a/etc/restic/pw.txt.template b/etc/restic/pw.txt similarity index 100% rename from etc/restic/pw.txt.template rename to etc/restic/pw.txt diff --git a/usr/local/sbin/cron_mail b/sbin/cron_mail similarity index 100% rename from usr/local/sbin/cron_mail rename to sbin/cron_mail diff --git a/usr/local/sbin/nm-unmetered-connection.sh b/sbin/nm-unmetered-connection.sh similarity index 100% rename from usr/local/sbin/nm-unmetered-connection.sh rename to sbin/nm-unmetered-connection.sh diff --git a/usr/local/sbin/restic_backup.sh b/sbin/restic_backup.sh similarity index 100% rename from usr/local/sbin/restic_backup.sh rename to sbin/restic_backup.sh diff --git a/usr/local/sbin/restic_check.sh b/sbin/restic_check.sh similarity index 100% rename from usr/local/sbin/restic_check.sh rename to sbin/restic_check.sh diff --git a/usr/local/sbin/resticw b/sbin/resticw similarity index 100% rename from usr/local/sbin/resticw rename to sbin/resticw diff --git a/usr/local/sbin/systemd-email b/sbin/systemd-email similarity index 100% rename from usr/local/sbin/systemd-email rename to sbin/systemd-email diff --git a/etc/systemd/system/nm-unmetered-connection.service b/usr/lib/systemd/system/nm-unmetered-connection.service similarity index 63% rename from etc/systemd/system/nm-unmetered-connection.service rename to usr/lib/systemd/system/nm-unmetered-connection.service index e2ce521..9ae42d8 100644 --- a/etc/systemd/system/nm-unmetered-connection.service +++ b/usr/lib/systemd/system/nm-unmetered-connection.service @@ -3,5 +3,4 @@ Description=Check if the current NetworkManager connection is metered [Service] Type=oneshot -ExecStart=/usr/local/sbin/nm-unmetered-connection.sh - +ExecStart=$INSTALL_PREFIX/sbin/nm-unmetered-connection.sh diff --git a/etc/systemd/system/restic-backup@.service b/usr/lib/systemd/system/restic-backup@.service similarity index 77% rename from etc/systemd/system/restic-backup@.service rename to usr/lib/systemd/system/restic-backup@.service index a41b156..84d46d9 100644 --- a/etc/systemd/system/restic-backup@.service +++ b/usr/lib/systemd/system/restic-backup@.service @@ -10,4 +10,4 @@ Nice=10 Environment="HOME=/root" # The random sleep (in seconds) is in the case of multiple backup profiles. Many restic instances started at the same time could case high load or network bandwith usage. # `systemd-cat` allows showing the restic output to the systemd journal -ExecStart=bash -c 'sleep $(shuf -i 0-300 -n 1) && source /etc/restic/%I.env && /usr/local/sbin/restic_backup.sh | systemd-cat' +ExecStart=bash -c 'sleep $(shuf -i 0-300 -n 1) && source $INSTALL_PREFIX/etc/restic/%I.env && $INSTALL_PREFIX/sbin/restic_backup.sh | systemd-cat' diff --git a/etc/systemd/system/restic-backup@.timer b/usr/lib/systemd/system/restic-backup@.timer similarity index 100% rename from etc/systemd/system/restic-backup@.timer rename to usr/lib/systemd/system/restic-backup@.timer diff --git a/etc/systemd/system/restic-check@.service b/usr/lib/systemd/system/restic-check@.service similarity index 70% rename from etc/systemd/system/restic-check@.service rename to usr/lib/systemd/system/restic-check@.service index 6c6f745..30eca31 100644 --- a/etc/systemd/system/restic-check@.service +++ b/usr/lib/systemd/system/restic-check@.service @@ -8,4 +8,4 @@ Requires=nm-unmetered-connection.service Type=simple Nice=10 # `systemd-cat` allows showing the restic output to the systemd journal -ExecStart=bash -c 'source /etc/restic/%I.env && /usr/local/sbin/restic_check.sh | systemd-cat' +ExecStart=bash -c 'source $INSTALL_PREFIX/etc/restic/%I.env && $INSTALL_PREFIX/sbin/restic_check.sh | systemd-cat' diff --git a/etc/systemd/system/restic-check@.timer b/usr/lib/systemd/system/restic-check@.timer similarity index 100% rename from etc/systemd/system/restic-check@.timer rename to usr/lib/systemd/system/restic-check@.timer diff --git a/etc/systemd/system/status-email-user@.service b/usr/lib/systemd/system/status-email-user@.service similarity index 82% rename from etc/systemd/system/status-email-user@.service rename to usr/lib/systemd/system/status-email-user@.service index a2897ed..697bad2 100644 --- a/etc/systemd/system/status-email-user@.service +++ b/usr/lib/systemd/system/status-email-user@.service @@ -6,6 +6,6 @@ Description=Send status email for %i to user [Service] Type=oneshot -ExecStart=/usr/local/sbin/systemd-email abc@gmail.com %i +ExecStart=$INSTALL_PREFIX/sbin/systemd-email abc@gmail.com %i User=root Group=systemd-journal From 861535a86e8a0e11a1379a1bbb8b2d92e678718c Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 14:48:38 +0100 Subject: [PATCH 02/30] Check properly for GNU install --- Makefile | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 40c5d6b..2429d74 100644 --- a/Makefile +++ b/Makefile @@ -16,18 +16,12 @@ ### Macros ### NOW := $(shell date +%Y-%m-%d_%H:%M:%S) -# Source: https://stackoverflow.com/a/14777895/265508 -ifeq ($(OS),Windows_NT) - CUR_OS := Windows -else - CUR_OS := $(shell uname) -endif - # GNU install and macOS install have incompatible command line arguments. -ifeq ($(CUR_OS),Darwin) - BAK_SUFFIX = -B .$(NOW).bak -else +GNU_INSTALL := $(shell install --version 2>/dev/null | grep -q GNU && echo true || echo false) +ifeq ($(GNU_INSTALL),true) BAK_SUFFIX = --suffix=.$(NOW).bak +else + BAK_SUFFIX = -B .$(NOW).bak endif # Create parent directories of a file, if not existing. From 4236c93b57bf0255a05b21d2f46c952154ed3b54 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 14:53:32 +0100 Subject: [PATCH 03/30] spell --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2429d74..ef0e489 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ uninstall: # target: install - Install all files install: install-scripts install-conf install-systemd -# Install targets - add build sources to prereqa as well, so that build dir is re-created if deleted (expected behaviour). +# Install targets - add build sources to prereq as well, so that build dir is re-created if deleted (expected behaviour). # target: install-scripts - Install executables. install-scripts: $(DEST_SCRIPTS) # target: install-conf - Install restic configuration files. From 1a890de7ac4701a3a4d27994da83f7fa15196d2c Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 14:55:24 +0100 Subject: [PATCH 04/30] Remove target dependency that was not cleaned up before --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ef0e489..504f938 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,7 @@ install: install-scripts install-conf install-systemd # target: install-scripts - Install executables. install-scripts: $(DEST_SCRIPTS) # target: install-conf - Install restic configuration files. -install-conf: $(DEST_CONF) $(BUILD_SRCS_CONF) +install-conf: $(DEST_CONF) # target: install-systemd - Install systemd timer and service files. install-systemd: $(DEST_SYSTEMD) From ccf39e822dcc7b80d73e00d588c9108a7b23dbda Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:02:24 +0100 Subject: [PATCH 05/30] Remove comment not relevant --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 504f938..3f85d5e 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,6 @@ install-systemd: $(DEST_SYSTEMD) # Copies sources to build directory & replace "$INSTALL_PREFIX" -# dir= line needs to be in the same subshell to use shared envvars. Reference: https://stackoverflow.com/a/36419671/265508 $(BUILD_DIR)/% : % ${MKDIR_PARENTS} $@ cp $< $@ From 25666f17a0d28977a7db648f91e4e90c9ce9b459 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:02:53 +0100 Subject: [PATCH 06/30] Remove old out-commented solution --- Makefile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Makefile b/Makefile index 3f85d5e..40b292a 100644 --- a/Makefile +++ b/Makefile @@ -107,12 +107,6 @@ $(BUILD_DIR)/% : % cp $< $@ sed -i.bak -e "s|\$$INSTALL_PREFIX|$$PREFIX|g" $@; rm $@.bak - -# For the destination files to be built, build-files must exist. -#$(DEST_SCRIPTS): $(BUILD_SRCS_SCRIPTS) -#$(DEST_CONF): $(BUILD_SRCS_CONF) -#$(DEST_SYSTEMD): $(BUILD_SRCS_SYSTEMD) - # Install destination script files. $(DEST_DIR_SCRIPTS)/%: $(BUILD_DIR_SCRIPTS)/% ${MKDIR_PARENTS} $@ From fc04da5a2d08d3c0079f559d61ae9f18abd7d046 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:04:44 +0100 Subject: [PATCH 07/30] Fix comment --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 40b292a..ad0fee9 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,7 @@ $(DEST_DIR_CONF)/%: $(BUILD_DIR_CONF)/% ${MKDIR_PARENTS} $@ install -m 0600 -b $(BAK_SUFFIX) $< $@ -# Install destination script files. +# Install destination system files. $(DEST_DIR_SYSTEMD)/%: $(BUILD_DIR_SYSTEMD)/% ${MKDIR_PARENTS} $@ install -m 0644 $< $@ From a117c9550868f32a8e8fbcfbc629d3eed95c7957 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:13:01 +0100 Subject: [PATCH 08/30] Format Makefile --- Makefile | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index ad0fee9..0a82b59 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,28 @@ -### Notes ### +#### Notes #################################################################### # This build process is done in three stages: # 1. copy source files to the local build directory. # 2. replace the string "$INSTALL_PREFIX" with the value of $PREFIX # 3. copy files from the build directory to the target directory. # # Why this dance? -# * To fully support that a user can install this project to a custom path e.g. $(PREFIX=/usr/local make install), -# we need to modify the files that refer to other files on disk. We do this by having a placeholder "$INSTALL_PREFIX" -# that is substituted with the value of $PREFIX when installed -# * We don't want to modify the files that are controlled by git, thus let's copy them to a build directory and then modify. +# * To fully support that a user can install this project to a custom path e.g. +# $(PREFIX=/usr/local make install), we need to modify the files that refer +# to other files on disk. We do this by having a placeholder +# "$INSTALL_PREFIX" that is substituted with the value of $PREFIX when +# installed. +# * We don't want to modify the files that are controlled by git, thus let's +# copy them to a build directory and then modify. -### Non-file targets ### -.PHONY: help install install-scripts install-conf install-systemd clean uninstall +#### Non-file targets ######################################################### +.PHONY: all help clean uninstall \ + install install-scripts install-conf install-systemd -### Macros ### +#### Macros ################################################################### NOW := $(shell date +%Y-%m-%d_%H:%M:%S) # GNU install and macOS install have incompatible command line arguments. -GNU_INSTALL := $(shell install --version 2>/dev/null | grep -q GNU && echo true || echo false) +GNU_INSTALL := $(shell install --version 2>/dev/null | \ + grep -q GNU && echo true || echo false) ifeq ($(GNU_INSTALL),true) BAK_SUFFIX = --suffix=.$(NOW).bak else @@ -44,7 +49,8 @@ SRCS_CONF = $(sort $(patsubst %.template, %, $(wildcard $(DIR_CONF)/*))) SRCS_SYSTEMD = $(wildcard $(DIR_SYSTEMD)/*) -# Local build directory. Sources will be copied here, modified and then installed from this directory. +# Local build directory. Sources will be copied here, +# modified and then installed from this directory. BUILD_DIR := build BUILD_DIR_SCRIPTS = $(BUILD_DIR)/$(DIR_SCRIPTS) BUILD_DIR_CONF = $(BUILD_DIR)/$(DIR_CONF) @@ -67,13 +73,15 @@ DEST_SYSTEMD = $(addprefix $(PREFIX)/, $(SRCS_SYSTEMD)) INSTALLED_FILES = $(DEST_SCRIPTS) $(DEST_CONF) $(DEST_SYSTEMD) -### Targets ### + +#### Targets ################################################################## # target: all - Default target. all: install # target: help - Display all targets. help: - @egrep "#\starget:" [Mm]akefile | sed 's/\s-\s/\t\t\t/' | cut -d " " -f3- | sort -d + @egrep "#\starget:" [Mm]akefile | \ + sed 's/\s-\s/\t\t\t/' | cut -d " " -f3- | sort -d # target: clean - Remove build files. clean: @@ -86,13 +94,16 @@ uninstall: $(RM) $$file; \ done -# To change the installation root path, set the PREFIX variable in your shell's environment, like: +# To change the installation root path, +# set the PREFIX variable in your shell's environment, like: # $ PREFIX=/usr/local make install # $ PREFIX=/tmp/test make install # target: install - Install all files install: install-scripts install-conf install-systemd -# Install targets - add build sources to prereq as well, so that build dir is re-created if deleted (expected behaviour). +# Install targets - add build sources to prereq as well, +# so that build dir is re-created if deleted (expected behaviour). +# # target: install-scripts - Install executables. install-scripts: $(DEST_SCRIPTS) # target: install-conf - Install restic configuration files. @@ -100,7 +111,6 @@ install-conf: $(DEST_CONF) # target: install-systemd - Install systemd timer and service files. install-systemd: $(DEST_SYSTEMD) - # Copies sources to build directory & replace "$INSTALL_PREFIX" $(BUILD_DIR)/% : % ${MKDIR_PARENTS} $@ From 67cd6ee94b7c3b97beec17effc57c105df8129f5 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:18:39 +0100 Subject: [PATCH 09/30] Add back dependency on builddir --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0a82b59..03cdb4b 100644 --- a/Makefile +++ b/Makefile @@ -105,11 +105,11 @@ install: install-scripts install-conf install-systemd # so that build dir is re-created if deleted (expected behaviour). # # target: install-scripts - Install executables. -install-scripts: $(DEST_SCRIPTS) +install-scripts: $(DEST_SCRIPTS) $(BUILD_SRCS_CONF) # target: install-conf - Install restic configuration files. -install-conf: $(DEST_CONF) +install-conf: $(DEST_CONF) $(BUILD_SRCS_CONF) # target: install-systemd - Install systemd timer and service files. -install-systemd: $(DEST_SYSTEMD) +install-systemd: $(DEST_SYSTEMD) $(BUILD_SRCS_CONF) # Copies sources to build directory & replace "$INSTALL_PREFIX" $(BUILD_DIR)/% : % From c43367fab32c81c7270cdf81758627f60c6edb7b Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:27:43 +0100 Subject: [PATCH 10/30] Simpler sed expression --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 03cdb4b..78a0c87 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ install-systemd: $(DEST_SYSTEMD) $(BUILD_SRCS_CONF) $(BUILD_DIR)/% : % ${MKDIR_PARENTS} $@ cp $< $@ - sed -i.bak -e "s|\$$INSTALL_PREFIX|$$PREFIX|g" $@; rm $@.bak + sed -i.bak -e 's|$$INSTALL_PREFIX|$(PREFIX)|g' $@; rm $@.bak # Install destination script files. $(DEST_DIR_SCRIPTS)/%: $(BUILD_DIR_SCRIPTS)/% From dc28ad2b52950c9183cee8e961c777dff2d4956a Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:28:14 +0100 Subject: [PATCH 11/30] Update README.md Co-authored-by: Gerard Bosch <30733556+gerardbosch@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 90374be..dc16f3e 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ and you should now see that all files have been changed like e.g. -export RESTIC_PASSWORD_FILE="$INSTALL_PREFIX/etc/restic/pw.txt" +export RESTIC_PASSWORD_FILE="/etc/restic/pw.txt" ``` -This prefix is there so that make users can set a different `$PREFIX` when installing like `PREFIX=/usr/local make install`. So if we don't use the makefile, we need to remove this prefix with the command above just. +This prefix is there so that `make` users can set a different `$PREFIX` when installing like `PREFIX=/usr/local make install`. So if we don't use the makefile, we need to remove this prefix with the command above just. Arch Linux users can install the aur package [restic-systemd-automatic-backup](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/) e.g.: From 494bcc29f047eb31f89e6cca4e59e6d7ed42320b Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:36:41 +0100 Subject: [PATCH 12/30] s/SCRIPTS/SCRIPT/g --- Makefile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 78a0c87..712d901 100644 --- a/Makefile +++ b/Makefile @@ -38,40 +38,40 @@ MKDIR_PARENTS=sh -c '\ # Source directories. -DIR_SCRIPTS = sbin +DIR_SCRIPT = sbin DIR_CONF = etc/restic DIR_SYSTEMD = usr/lib/systemd/system # Source files. -SRCS_SCRIPTS = $(filter-out %cron_mail, $(wildcard $(DIR_SCRIPTS)/*)) +SRCS_SCRIPT = $(filter-out %cron_mail, $(wildcard $(DIR_SCRIPT)/*)) # $(sort) remove duplicates that comes from running make install >1 times. -SRCS_CONF = $(sort $(patsubst %.template, %, $(wildcard $(DIR_CONF)/*))) +SRCS_CONF = $(sort $(patsubst %.template, %, $(wildcard $(DIR_CONF)/*))) SRCS_SYSTEMD = $(wildcard $(DIR_SYSTEMD)/*) # Local build directory. Sources will be copied here, # modified and then installed from this directory. -BUILD_DIR := build -BUILD_DIR_SCRIPTS = $(BUILD_DIR)/$(DIR_SCRIPTS) +BUILD_DIR := build +BUILD_DIR_SCRIPT = $(BUILD_DIR)/$(DIR_SCRIPT) BUILD_DIR_CONF = $(BUILD_DIR)/$(DIR_CONF) BUILD_DIR_SYSTEMD = $(BUILD_DIR)/$(DIR_SYSTEMD) # Sources copied to build directory. -BUILD_SRCS_SCRIPTS = $(addprefix $(BUILD_DIR)/, $(SRCS_SCRIPTS)) +BUILD_SRCS_SCRIPT = $(addprefix $(BUILD_DIR)/, $(SRCS_SCRIPT)) BUILD_SRCS_CONF = $(addprefix $(BUILD_DIR)/, $(SRCS_CONF)) BUILD_SRCS_SYSTEMD = $(addprefix $(BUILD_DIR)/, $(SRCS_SYSTEMD)) # Destination directories -DEST_DIR_SCRIPTS = $(PREFIX)/$(DIR_SCRIPTS) +DEST_DIR_SCRIPT = $(PREFIX)/$(DIR_SCRIPT) DEST_DIR_CONF = $(PREFIX)/$(DIR_CONF) DEST_DIR_SYSTEMD = $(PREFIX)/$(DIR_SYSTEMD) # Destination files. -DEST_SCRIPTS = $(addprefix $(PREFIX)/, $(SRCS_SCRIPTS)) -DEST_CONF = $(addprefix $(PREFIX)/, $(SRCS_CONF)) +DEST_SCRIPT = $(addprefix $(PREFIX)/, $(SRCS_SCRIPT)) +DEST_CONF = $(addprefix $(PREFIX)/, $(SRCS_CONF)) DEST_SYSTEMD = $(addprefix $(PREFIX)/, $(SRCS_SYSTEMD)) -INSTALLED_FILES = $(DEST_SCRIPTS) $(DEST_CONF) $(DEST_SYSTEMD) +INSTALLED_FILES = $(DEST_SCRIPT) $(DEST_CONF) $(DEST_SYSTEMD) #### Targets ################################################################## @@ -105,7 +105,7 @@ install: install-scripts install-conf install-systemd # so that build dir is re-created if deleted (expected behaviour). # # target: install-scripts - Install executables. -install-scripts: $(DEST_SCRIPTS) $(BUILD_SRCS_CONF) +install-scripts: $(DEST_SCRIPT) $(BUILD_SRCS_CONF) # target: install-conf - Install restic configuration files. install-conf: $(DEST_CONF) $(BUILD_SRCS_CONF) # target: install-systemd - Install systemd timer and service files. @@ -118,7 +118,7 @@ $(BUILD_DIR)/% : % sed -i.bak -e 's|$$INSTALL_PREFIX|$(PREFIX)|g' $@; rm $@.bak # Install destination script files. -$(DEST_DIR_SCRIPTS)/%: $(BUILD_DIR_SCRIPTS)/% +$(DEST_DIR_SCRIPT)/%: $(BUILD_DIR_SCRIPT)/% ${MKDIR_PARENTS} $@ install -m 0744 $< $@ From 7f86dbd9f4bfaab4d5744d1a7d0f22c6fe26f122 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:39:54 +0100 Subject: [PATCH 13/30] Consistent macro names in Makefile --- Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 712d901..ec9e309 100644 --- a/Makefile +++ b/Makefile @@ -62,16 +62,16 @@ BUILD_SRCS_CONF = $(addprefix $(BUILD_DIR)/, $(SRCS_CONF)) BUILD_SRCS_SYSTEMD = $(addprefix $(BUILD_DIR)/, $(SRCS_SYSTEMD)) # Destination directories -DEST_DIR_SCRIPT = $(PREFIX)/$(DIR_SCRIPT) +DEST_DIR_SCRIPT = $(PREFIX)/$(DIR_SCRIPT) DEST_DIR_CONF = $(PREFIX)/$(DIR_CONF) DEST_DIR_SYSTEMD = $(PREFIX)/$(DIR_SYSTEMD) -# Destination files. -DEST_SCRIPT = $(addprefix $(PREFIX)/, $(SRCS_SCRIPT)) -DEST_CONF = $(addprefix $(PREFIX)/, $(SRCS_CONF)) -DEST_SYSTEMD = $(addprefix $(PREFIX)/, $(SRCS_SYSTEMD)) +# Destination file targets. +DEST_TARGS_SCRIPT = $(addprefix $(PREFIX)/, $(SRCS_SCRIPT)) +DEST_TARGS_CONF = $(addprefix $(PREFIX)/, $(SRCS_CONF)) +DEST_TARGS_SYSTEMD = $(addprefix $(PREFIX)/, $(SRCS_SYSTEMD)) -INSTALLED_FILES = $(DEST_SCRIPT) $(DEST_CONF) $(DEST_SYSTEMD) +INSTALLED_FILES = $(DEST_TARGS_SCRIPT) $(DEST_TARGS_CONF) $(DEST_TARGS_SYSTEMD) #### Targets ################################################################## @@ -105,11 +105,11 @@ install: install-scripts install-conf install-systemd # so that build dir is re-created if deleted (expected behaviour). # # target: install-scripts - Install executables. -install-scripts: $(DEST_SCRIPT) $(BUILD_SRCS_CONF) +install-scripts: $(DEST_TARGS_SCRIPT) $(BUILD_SRCS_CONF) # target: install-conf - Install restic configuration files. -install-conf: $(DEST_CONF) $(BUILD_SRCS_CONF) +install-conf: $(DEST_TARGS_CONF) $(BUILD_SRCS_CONF) # target: install-systemd - Install systemd timer and service files. -install-systemd: $(DEST_SYSTEMD) $(BUILD_SRCS_CONF) +install-systemd: $(DEST_TARGS_SYSTEMD) $(BUILD_SRCS_CONF) # Copies sources to build directory & replace "$INSTALL_PREFIX" $(BUILD_DIR)/% : % From dd092af6a17128e0f69c1b094eec19564f730324 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:43:57 +0100 Subject: [PATCH 14/30] Remove legacy .template --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ec9e309..3fa56bf 100644 --- a/Makefile +++ b/Makefile @@ -43,9 +43,8 @@ DIR_CONF = etc/restic DIR_SYSTEMD = usr/lib/systemd/system # Source files. -SRCS_SCRIPT = $(filter-out %cron_mail, $(wildcard $(DIR_SCRIPT)/*)) -# $(sort) remove duplicates that comes from running make install >1 times. -SRCS_CONF = $(sort $(patsubst %.template, %, $(wildcard $(DIR_CONF)/*))) +SRCS_SCRIPT = $(filter-out %cron_mail, $(wildcard $(DIR_SCRIPT)/*)) +SRCS_CONF = $(wildcard $(DIR_CONF)/*) SRCS_SYSTEMD = $(wildcard $(DIR_SYSTEMD)/*) From 6b315814d0ed1e6520d9beaaa89064a1f5da67b1 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:45:45 +0100 Subject: [PATCH 15/30] spell --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3fa56bf..2b39531 100644 --- a/Makefile +++ b/Makefile @@ -126,7 +126,7 @@ $(DEST_DIR_CONF)/%: $(BUILD_DIR_CONF)/% ${MKDIR_PARENTS} $@ install -m 0600 -b $(BAK_SUFFIX) $< $@ -# Install destination system files. +# Install destination systemd files. $(DEST_DIR_SYSTEMD)/%: $(BUILD_DIR_SYSTEMD)/% ${MKDIR_PARENTS} $@ install -m 0644 $< $@ From 59427625144c81009ef440bdcaeeec235c2b7ea4 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:48:58 +0100 Subject: [PATCH 16/30] Correct build source depdendency --- Makefile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 2b39531..29817b8 100644 --- a/Makefile +++ b/Makefile @@ -100,15 +100,14 @@ uninstall: # target: install - Install all files install: install-scripts install-conf install-systemd -# Install targets - add build sources to prereq as well, -# so that build dir is re-created if deleted (expected behaviour). -# +# Install targets. Prereq build sources as well, +# so that build dir is re-created if deleted. # target: install-scripts - Install executables. -install-scripts: $(DEST_TARGS_SCRIPT) $(BUILD_SRCS_CONF) +install-scripts: $(DEST_TARGS_SCRIPT) $(BUILD_SRCS_SCRIPT) # target: install-conf - Install restic configuration files. install-conf: $(DEST_TARGS_CONF) $(BUILD_SRCS_CONF) # target: install-systemd - Install systemd timer and service files. -install-systemd: $(DEST_TARGS_SYSTEMD) $(BUILD_SRCS_CONF) +install-systemd: $(DEST_TARGS_SYSTEMD) $(BUILD_SRCS_SYSTEMD) # Copies sources to build directory & replace "$INSTALL_PREFIX" $(BUILD_DIR)/% : % From 0255ad03d8e1c922459f72a93d11424c5ab42137 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:52:36 +0100 Subject: [PATCH 17/30] Format comments --- Makefile | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 29817b8..259d2e1 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ #### Notes #################################################################### -# This build process is done in three stages: +# This build process is done in three stages (out-of-source build): # 1. copy source files to the local build directory. -# 2. replace the string "$INSTALL_PREFIX" with the value of $PREFIX -# 3. copy files from the build directory to the target directory. +# 2. build dir: replace the string "$INSTALL_PREFIX" with the value of $PREFIX +# 3. install files from the build directory to the target directory. # # Why this dance? # * To fully support that a user can install this project to a custom path e.g. @@ -20,7 +20,7 @@ #### Macros ################################################################### NOW := $(shell date +%Y-%m-%d_%H:%M:%S) -# GNU install and macOS install have incompatible command line arguments. +# GNU and macOS install have incompatible command line arguments. GNU_INSTALL := $(shell install --version 2>/dev/null | \ grep -q GNU && echo true || echo false) ifeq ($(GNU_INSTALL),true) @@ -36,7 +36,6 @@ MKDIR_PARENTS=sh -c '\ test -d $$dir || mkdir -p $$dir \ ' MKDIR_PARENTS - # Source directories. DIR_SCRIPT = sbin DIR_CONF = etc/restic @@ -47,7 +46,6 @@ SRCS_SCRIPT = $(filter-out %cron_mail, $(wildcard $(DIR_SCRIPT)/*)) SRCS_CONF = $(wildcard $(DIR_CONF)/*) SRCS_SYSTEMD = $(wildcard $(DIR_SYSTEMD)/*) - # Local build directory. Sources will be copied here, # modified and then installed from this directory. BUILD_DIR := build @@ -109,7 +107,7 @@ install-conf: $(DEST_TARGS_CONF) $(BUILD_SRCS_CONF) # target: install-systemd - Install systemd timer and service files. install-systemd: $(DEST_TARGS_SYSTEMD) $(BUILD_SRCS_SYSTEMD) -# Copies sources to build directory & replace "$INSTALL_PREFIX" +# Copies sources to build directory & replace "$INSTALL_PREFIX". $(BUILD_DIR)/% : % ${MKDIR_PARENTS} $@ cp $< $@ From 21bb0535ee1909bf8b0343e5641b80d3f752817b Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sat, 5 Feb 2022 15:56:32 +0100 Subject: [PATCH 18/30] Note about make needing to be GNU make --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc16f3e..9375c4d 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ Nevertheless the project should work out of the box, be minimal but still open t # Requirements * `restic >=v0.9.6` -* (recommended) `make` if you want an automated install - * Arch: part of the `base-devel` meta package, Debian/Ubuntu: part of the `build-essential` meta package, macOS: preinstalled make works) +* (recommended) GNU `make` if you want an automated install + * Arch: part of the `base-devel` meta package, Debian/Ubuntu: part of the `build-essential` meta package, macOS: use the preinstalled or a more recent with Homebrew) # TL;DR Setup 1. Create B2 credentials as instructed [below](#1-create-backblaze-b2-account) From 1ee0e2c91990135166b6d8fd62676c823af75d02 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sun, 6 Feb 2022 14:36:41 +0100 Subject: [PATCH 19/30] Fix cron with multiple profiles --- Makefile | 18 ++++++++++++++++-- etc/cron.d/restic | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 259d2e1..1ad1a06 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ #### Non-file targets ######################################################### .PHONY: all help clean uninstall \ - install install-scripts install-conf install-systemd + install install-scripts install-conf install-systemd install-cron #### Macros ################################################################### NOW := $(shell date +%Y-%m-%d_%H:%M:%S) @@ -40,11 +40,13 @@ MKDIR_PARENTS=sh -c '\ DIR_SCRIPT = sbin DIR_CONF = etc/restic DIR_SYSTEMD = usr/lib/systemd/system +DIR_CRON = etc/cron.d # Source files. SRCS_SCRIPT = $(filter-out %cron_mail, $(wildcard $(DIR_SCRIPT)/*)) SRCS_CONF = $(wildcard $(DIR_CONF)/*) SRCS_SYSTEMD = $(wildcard $(DIR_SYSTEMD)/*) +SRCS_CRON = $(wildcard $(DIR_CRON)/*) # Local build directory. Sources will be copied here, # modified and then installed from this directory. @@ -52,23 +54,28 @@ BUILD_DIR := build BUILD_DIR_SCRIPT = $(BUILD_DIR)/$(DIR_SCRIPT) BUILD_DIR_CONF = $(BUILD_DIR)/$(DIR_CONF) BUILD_DIR_SYSTEMD = $(BUILD_DIR)/$(DIR_SYSTEMD) +BUILD_DIR_CRON = $(BUILD_DIR)/$(DIR_CRON) # Sources copied to build directory. BUILD_SRCS_SCRIPT = $(addprefix $(BUILD_DIR)/, $(SRCS_SCRIPT)) BUILD_SRCS_CONF = $(addprefix $(BUILD_DIR)/, $(SRCS_CONF)) BUILD_SRCS_SYSTEMD = $(addprefix $(BUILD_DIR)/, $(SRCS_SYSTEMD)) +BUILD_SRCS_CRON = $(addprefix $(BUILD_DIR)/, $(SRCS_CRON)) # Destination directories DEST_DIR_SCRIPT = $(PREFIX)/$(DIR_SCRIPT) DEST_DIR_CONF = $(PREFIX)/$(DIR_CONF) DEST_DIR_SYSTEMD = $(PREFIX)/$(DIR_SYSTEMD) +DEST_DIR_CRON = $(PREFIX)/$(DIR_CRON) # Destination file targets. DEST_TARGS_SCRIPT = $(addprefix $(PREFIX)/, $(SRCS_SCRIPT)) DEST_TARGS_CONF = $(addprefix $(PREFIX)/, $(SRCS_CONF)) DEST_TARGS_SYSTEMD = $(addprefix $(PREFIX)/, $(SRCS_SYSTEMD)) +DEST_TARGS_CRON = $(addprefix $(PREFIX)/, $(SRCS_CRON)) -INSTALLED_FILES = $(DEST_TARGS_SCRIPT) $(DEST_TARGS_CONF) $(DEST_TARGS_SYSTEMD) +INSTALLED_FILES = $(DEST_TARGS_SCRIPT) $(DEST_TARGS_CONF) \ + $(DEST_TARGS_SYSTEMD) $(DEST_TARGS_CRON) #### Targets ################################################################## @@ -106,6 +113,8 @@ install-scripts: $(DEST_TARGS_SCRIPT) $(BUILD_SRCS_SCRIPT) install-conf: $(DEST_TARGS_CONF) $(BUILD_SRCS_CONF) # target: install-systemd - Install systemd timer and service files. install-systemd: $(DEST_TARGS_SYSTEMD) $(BUILD_SRCS_SYSTEMD) +# target: install-cron - Install cronjob. +install-cron: $(DEST_TARGS_CRON) $(BUILD_SRCS_CRON) # Copies sources to build directory & replace "$INSTALL_PREFIX". $(BUILD_DIR)/% : % @@ -127,3 +136,8 @@ $(DEST_DIR_CONF)/%: $(BUILD_DIR_CONF)/% $(DEST_DIR_SYSTEMD)/%: $(BUILD_DIR_SYSTEMD)/% ${MKDIR_PARENTS} $@ install -m 0644 $< $@ + +# Install destination cron files. +$(DEST_DIR_CRON)/%: $(BUILD_DIR_CRON)/% + ${MKDIR_PARENTS} $@ + install -m 0644 $< $@ diff --git a/etc/cron.d/restic b/etc/cron.d/restic index eca6735..95f8ddb 100644 --- a/etc/cron.d/restic +++ b/etc/cron.d/restic @@ -4,5 +4,5 @@ PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:$INSTALL_PREFIX/sbin/ # minute hour mday month wday command # Reference: https://www.freebsd.org/doc/handbook/configtuning-cron.html # Reference: crontab(5). -@midnight root cron_mail restic_backup.sh -@monthly root cron_mail restic_check.sh +@midnight root . $INSTALL_PREFIX/etc/restic/default.sh && cron_mail restic_backup.sh +@monthly root . $INSTALL_PREFIX/etc/restic/default.sh && cron_mail restic_check.sh From 8db3d2717467d2640e7aeea117e639719c1d67bc Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sun, 6 Feb 2022 14:49:00 +0100 Subject: [PATCH 20/30] Rename top-level install targets "make install" -> "make install-systemd" so that I could now add a ""make install-cron" target. Soon there will be "make install-macos" "make install-windows" Thus it does not make sense to have a general `make install` anymore. --- Makefile | 40 +++++++++++++++++++++------------------- README.md | 18 +++++++++++------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 1ad1a06..576a97b 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,10 @@ # copy them to a build directory and then modify. #### Non-file targets ######################################################### -.PHONY: all help clean uninstall \ - install install-scripts install-conf install-systemd install-cron +.PHONY: help clean uninstall \ + install-systemd install-cron \ + install-targets-script install-targets-conf install-targets-systemd \ + install-targets-cron #### Macros ################################################################### NOW := $(shell date +%Y-%m-%d_%H:%M:%S) @@ -79,10 +81,8 @@ INSTALLED_FILES = $(DEST_TARGS_SCRIPT) $(DEST_TARGS_CONF) \ #### Targets ################################################################## -# target: all - Default target. -all: install - -# target: help - Display all targets. +# target: help - Default target - displayes all targets. +# TODO sed is broken help: @egrep "#\starget:" [Mm]akefile | \ sed 's/\s-\s/\t\t\t/' | cut -d " " -f3- | sort -d @@ -91,7 +91,7 @@ help: clean: $(RM) -r $(BUILD_DIR) -# target: uninstall - Uninstall ALL files from the install targets. +# target: uninstall - Uninstall ALL files from all install targets. uninstall: @for file in $(INSTALLED_FILES); do \ echo $(RM) $$file; \ @@ -100,21 +100,23 @@ uninstall: # To change the installation root path, # set the PREFIX variable in your shell's environment, like: -# $ PREFIX=/usr/local make install -# $ PREFIX=/tmp/test make install -# target: install - Install all files -install: install-scripts install-conf install-systemd +# $ PREFIX=/usr/local make install-systemd +# $ PREFIX=/tmp/test make install-systemd +# target: install-systemd - Install systemd setup. +install-systemd: install-targets-script install-targets-conf install-targets-systemd +# target: install-cron - Install cron setup. +install-cron: install-targets-cron # Install targets. Prereq build sources as well, # so that build dir is re-created if deleted. -# target: install-scripts - Install executables. -install-scripts: $(DEST_TARGS_SCRIPT) $(BUILD_SRCS_SCRIPT) -# target: install-conf - Install restic configuration files. -install-conf: $(DEST_TARGS_CONF) $(BUILD_SRCS_CONF) -# target: install-systemd - Install systemd timer and service files. -install-systemd: $(DEST_TARGS_SYSTEMD) $(BUILD_SRCS_SYSTEMD) -# target: install-cron - Install cronjob. -install-cron: $(DEST_TARGS_CRON) $(BUILD_SRCS_CRON) +# target: install-targets-script - Install executables. +install-targets-script: $(DEST_TARGS_SCRIPT) $(BUILD_SRCS_SCRIPT) +# target: install-targets-conf - Install restic configuration files. +install-targets-conf: $(DEST_TARGS_CONF) $(BUILD_SRCS_CONF) +# target: install-targets-systemd - Install systemd timer and service files. +install-targets-systemd: $(DEST_TARGS_SYSTEMD) $(BUILD_SRCS_SYSTEMD) +# target: install-targets-cron - Install cronjob. +install-targets-cron: $(DEST_TARGS_CRON) $(BUILD_SRCS_CRON) # Copies sources to build directory & replace "$INSTALL_PREFIX". $(BUILD_DIR)/% : % diff --git a/README.md b/README.md index 9375c4d..a944dfd 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,15 @@ Nevertheless the project should work out of the box, be minimal but still open t * (recommended) GNU `make` if you want an automated install * Arch: part of the `base-devel` meta package, Debian/Ubuntu: part of the `build-essential` meta package, macOS: use the preinstalled or a more recent with Homebrew) + + + + # TL;DR Setup 1. Create B2 credentials as instructed [below](#1-create-backblaze-b2-account) 1. Install config and scripts: ```console - $ sudo make install + $ sudo make install-systemd ``` ☝ **Note**: `sudo` is required here, as some files are installed into system directories (`/etc/` and `/usr/sbin`). Have a look to the `Makefile` to know more. @@ -88,10 +92,10 @@ Tip: The steps in this section will instruct you to copy files from this repo to ```console $ git clone https://github.com/erikw/restic-systemd-automatic-backup.git && cd $(basename "$_" .git) -$ sudo make install +$ sudo make install-systemd ```` -If you want to install everything manually, we will install files to `/etc`, `/sbin`, and not use the `$make install` command, then you need to clean up a placeholder `$INSTALL_PREFIX` in the souce files first by running: +If you want to install everything manually, we will install files to `/etc`, `/sbin`, and not use the `$make install-systemd` command, then you need to clean up a placeholder `$INSTALL_PREFIX` in the souce files first by running: ```console $ find etc sbin -type f -exec sed -i.bak -e 's|$INSTALL_PREFIX||g' {} \; -exec rm {}.bak \; ``` @@ -100,7 +104,7 @@ and you should now see that all files have been changed like e.g. -export RESTIC_PASSWORD_FILE="$INSTALL_PREFIX/etc/restic/pw.txt" +export RESTIC_PASSWORD_FILE="/etc/restic/pw.txt" ``` -This prefix is there so that `make` users can set a different `$PREFIX` when installing like `PREFIX=/usr/local make install`. So if we don't use the makefile, we need to remove this prefix with the command above just. +This prefix is there so that `make` users can set a different `$PREFIX` when installing like `PREFIX=/usr/local make install-systemd`. So if we don't use the makefile, we need to remove this prefix with the command above just. Arch Linux users can install the aur package [restic-systemd-automatic-backup](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/) e.g.: @@ -256,11 +260,11 @@ straightforward (it needs to run with sudo to read environment). Just run: If you want to run an all-classic cron job instead, do like this: * `etc/cron.d/restic`: Depending on your system's cron, put this in `/etc/cron.d/` or similar, or copy the contents to $(sudo crontab -e). The format of this file is tested under FreeBSD, and might need adaptions depending on your cron. + * You can use `$ make install-cron` to copy it over to `/etc/cron.d`. * `sbin/cron_mail`: A wrapper for running cron jobs, that sends output of the job as an email using the mail(1) command. # Uninstall - -There is a make target to remove all files (scripts and configs) that were installed by `sudo make install`. Just run: +There is a make target to remove all files (scripts and configs) that were installed by `sudo make install-*`. Just run: ```console $ sudo make uninstall @@ -273,7 +277,7 @@ A list of variations of this setup: # Development * To not mess up your real installation when changing the `Makefile` simply install to a `$PREFIX` like ```console - $ PREFIX=/tmp/restic-test make install + $ PREFIX=/tmp/restic-test make install-systemd ``` * **Updating the `resticw` parser:** If you ever update the usage `DOC`, you will need to refresh the auto-generated parser: ```console From c01bb5a00e7deef162e7bbe73c79f213882326da Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sun, 6 Feb 2022 15:10:31 +0100 Subject: [PATCH 21/30] Fix broken help target --- Makefile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 576a97b..a3df512 100644 --- a/Makefile +++ b/Makefile @@ -81,11 +81,9 @@ INSTALLED_FILES = $(DEST_TARGS_SCRIPT) $(DEST_TARGS_CONF) \ #### Targets ################################################################## -# target: help - Default target - displayes all targets. -# TODO sed is broken +# target: help - Default target; displays all targets. help: - @egrep "#\starget:" [Mm]akefile | \ - sed 's/\s-\s/\t\t\t/' | cut -d " " -f3- | sort -d + @egrep "#\starget:" [Mm]akefile | cut -d " " -f3- | sort -d # target: clean - Remove build files. clean: @@ -104,18 +102,15 @@ uninstall: # $ PREFIX=/tmp/test make install-systemd # target: install-systemd - Install systemd setup. install-systemd: install-targets-script install-targets-conf install-targets-systemd + # target: install-cron - Install cron setup. install-cron: install-targets-cron # Install targets. Prereq build sources as well, # so that build dir is re-created if deleted. -# target: install-targets-script - Install executables. install-targets-script: $(DEST_TARGS_SCRIPT) $(BUILD_SRCS_SCRIPT) -# target: install-targets-conf - Install restic configuration files. install-targets-conf: $(DEST_TARGS_CONF) $(BUILD_SRCS_CONF) -# target: install-targets-systemd - Install systemd timer and service files. install-targets-systemd: $(DEST_TARGS_SYSTEMD) $(BUILD_SRCS_SYSTEMD) -# target: install-targets-cron - Install cronjob. install-targets-cron: $(DEST_TARGS_CRON) $(BUILD_SRCS_CRON) # Copies sources to build directory & replace "$INSTALL_PREFIX". From eb6e7b4a8dc92f182737ed9ac0bd35cfcb77c2c2 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sun, 6 Feb 2022 15:16:19 +0100 Subject: [PATCH 22/30] Begin structure README after system setup --- README.md | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a944dfd..4ea0535 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,13 @@ Nevertheless the project should work out of the box, be minimal but still open t +# Setup +Depending on your system, the setup will look different. Choose one of +* [Linux + Systemd](#setup-linux-systemd) +* [Cron](#setup-cron) - for any system having a cron daemon. Tested on FreeBSD and macOS. - -# TL;DR Setup +## Setup Linux Systemd +### TL;DR Setup 1. Create B2 credentials as instructed [below](#1-create-backblaze-b2-account) 1. Install config and scripts: ```console @@ -85,7 +89,7 @@ Nevertheless the project should work out of the box, be minimal but still open t 1. (optional) Setup email on failure as described [here](#8-email-notification-on-failure) -# Step-by-step and manual setup +### Step-by-step and manual setup This is a more detailed explanation than the TL;DR section that will give you more understanding in the setup, and maybe inspire you to develop your own setup based on this one even! Tip: The steps in this section will instruct you to copy files from this repo to system directories. If you don't want to do this manually, you can use the Makefile: @@ -112,13 +116,13 @@ Arch Linux users can install the aur package [restic-systemd-automatic-backup](h $ yaourt -S restic-systemd-automatic-backup ```` -## 1. Create Backblaze B2 Account, Bucket and keys +#### 1. Create Backblaze B2 Account, Bucket and keys First, see this official Backblaze [tutorial](https://help.backblaze.com/hc/en-us/articles/4403944998811-Quickstart-Guide-for-Restic-and-Backblaze-B2-Cloud-Storage) on restic, and follow the instructions ("Create Backblaze account with B2 enabled") there on how to create a new B2 bucket. In general, you'd want a private bucket, without B2 encryption (restic does the encryption client side for us) and without the object lock feature. For restic to be able to connect to your bucket, you want to in the B2 settings create a pair of keyID and applicationKey. It's a good idea to create a separate pair of ID and Key with for each bucket that you will use, with limited read&write access to only that bucket. -## 2. Configure your B2 credentials locally +#### 2. Configure your B2 credentials locally > **Attention!** Going the manual way requires that most of the following commands are run as root. Put these files in `/etc/restic/`: @@ -133,7 +137,7 @@ Put these files in `/etc/restic/`: $ openssl rand -base64 128 | tr -d '\n' > /etc/restic/pw.txt ``` -## 3. Initialize remote repo +#### 3. Initialize remote repo Now we must initialize the repository on the remote end: ```console $ sudo -i @@ -141,7 +145,7 @@ $ source /etc/restic/default.env $ restic init ``` -## 4. Script for doing the backup +#### 4. Script for doing the backup Put this file in `/sbin`: * `restic_backup.sh`: A script that defines how to run the backup. The intention is that you should not need to edit this script yourself, but be able to control everything from the `*.env` profiles. @@ -149,7 +153,7 @@ Restic support exclude files. They list file pattern paths to exclude from you b * `/etc/restic/backup_exclude.txt` - global exclude list. You can use only this one if your setup is easy. This is set in `_global.env`. If you need a different file for another profile, you can override the envvar `RESTIC_BACKUP_EXCLUDE_FILE` in this profile. * `.backup_exclude.txt` per backup path. If you have e.g. an USB disk mounted at /mnt/media and this path is included in the `$RESTIC_BACKUP_PATHS`, you can place a file `/mnt/media/.backup_exclude.txt` and it will automatically picked up. The nice thing about this is that the backup paths are self-contained in terms of what they shoud exclude! -## 5. Make first backup +#### 5. Make first backup Now see if the backup itself works, by running as root ```console @@ -158,7 +162,7 @@ $ source /etc/restic/default.env $ /sbin/restic_backup.sh ```` -## 6. Verify the backup +#### 6. Verify the backup As the `default.env` is already sourced in your root shell, you can now just list the snapshos ```console $ sudo -i @@ -172,7 +176,7 @@ $ restic mount /mnt/restic $ ls /mnt/restic ``` -## 7. Backup automatically; systemd service + timer +#### 7. Backup automatically; systemd service + timer Now we can do the modern version of a cron-job, a systemd service + timer, to run the backup every day! Put these files in `/etc/systemd/system` (note that the Makefile installs as package to `/usr/lib/systemd/system`) @@ -216,7 +220,7 @@ $ journalctl -f -u restic-backup@default.service -## 8. Email notification on failure +#### 8. Email notification on failure We want to be aware when the automatic backup fails, so we can fix it. Since my laptop does not run a mail server, I went for a solution to set up my laptop to be able to send emails with [postfix via my Gmail](https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/). Follow the instructions over there. Put this file in `/sbin`: @@ -228,7 +232,7 @@ Put this files in `/etc/systemd/system/`: As you maybe noticed already before, `restic-backup.service` is configured to start `status-email-user.service` on failure. -## 9. Optional: automated backup checks +#### 9. Optional: automated backup checks Once in a while it can be good to do a health check of the remote repository, to make sure it's not getting corrupt. This can be done with `$ restic check`. There is companion scripts, service and timer (`*check*`) to restic-backup.sh that checks the restic backup for errors; look in the repo in `usr/lib/systemd/system/` and `sbin/` and copy what you need over to their corresponding locations. @@ -239,14 +243,14 @@ $ systemctl start restic-check@default.timer $ systemctl enable restic-check@default.timer ```` -## 10. Optional: 🏃 Restic wrapper +#### 10. Optional: 🏃 Restic wrapper For convenience there's a `restic` wrapper script that makes loading profiles and **running restic** straightforward (it needs to run with sudo to read environment). Just run: - `sudo resticw WHATEVER` (e.g. `sudo resticw snapshots`) to use the default profile. - You can run the wrapper by passing a specific profile: `resticw -p anotherprofile snapshots`. -### Useful commands +##### Useful commands | Command | Description | |---------------------------------------------------|-------------------------------------------------------------------| @@ -256,12 +260,14 @@ straightforward (it needs to run with sudo to read environment). Just run: | `resticw mount /mnt/restic` | Mount your remote repository | -# Cron? +## Setup Cron If you want to run an all-classic cron job instead, do like this: -* `etc/cron.d/restic`: Depending on your system's cron, put this in `/etc/cron.d/` or similar, or copy the contents to $(sudo crontab -e). The format of this file is tested under FreeBSD, and might need adaptions depending on your cron. +1. Follow the main setup from [Step-by-step and manual setup](#step-by-step-and-manual-setup) but skip the systemd parts. +1. `etc/cron.d/restic`: Depending on your system's cron, put this in `/etc/cron.d/` or similar, or copy the contents to $(sudo crontab -e). The format of this file is tested under FreeBSD, and might need adaptions depending on your cron. * You can use `$ make install-cron` to copy it over to `/etc/cron.d`. -* `sbin/cron_mail`: A wrapper for running cron jobs, that sends output of the job as an email using the mail(1) command. +1. (Optional) `sbin/cron_mail`: A wrapper for running cron jobs, that sends output of the job as an email using the mail(1) command. + # Uninstall There is a make target to remove all files (scripts and configs) that were installed by `sudo make install-*`. Just run: From a57971e27ebea654010f100c13311b4e9a7996c0 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sun, 6 Feb 2022 15:25:45 +0100 Subject: [PATCH 23/30] Add navigation tip --- README.md | 4 ++++ img/readme_sections.png | Bin 0 -> 17992 bytes 2 files changed, 4 insertions(+) create mode 100644 img/readme_sections.png diff --git a/README.md b/README.md index 4ea0535..2a99e7b 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,10 @@ The scope for this is not to be a full-fledged super solution that solves all th Nevertheless the project should work out of the box, be minimal but still open the doors for configuration and extensions by users. +## Navigate this README +Tip: use the Section icon in the top left of this document to navigate the sections. +![README Sections](img/readme_sections.png) + # Requirements * `restic >=v0.9.6` * (recommended) GNU `make` if you want an automated install diff --git a/img/readme_sections.png b/img/readme_sections.png new file mode 100644 index 0000000000000000000000000000000000000000..2e78f75126d14fd811e8e10cd5bc429f819ff718 GIT binary patch literal 17992 zcmb@tWmsK7k}!%~1-kc+!toFIYV?(XjH5G1%u(BK4@;O@cQ-Ce?WGc&t8JI}uV zz5|ETbaz!()v4~Ts;(2M^hpX8i4X|_0s>V=T0#W^0#XuOPC$SH|7Cp&3jtS1S&EA* z$%u=SD>>PlS=yLFK+q)^8yH~8e54yPG&C?68fTz>mKMH&Fjni znx><(3BcHdR_%c(RQ}aujS@rtT*o|ANqkf7oQ5<%zVUPZ+dy$4sHO4T)U;c2%_&Cq7D=l5C>Iv5U_ZJaSw;VkJuvw^#vPi7sX@)q7F8Z z9V^g`wG*PwHSufTY{H_Fw`jm%|L;L5in*cHskz_)XBl{!GF%$+W!|p5Iy!d2LWy6P z0NFC69M54dJ|syvNl6rxJl62iKg2L-a+0;a2(_;?C@6Rv06-coWnbcVR#qE(V}q~F zp%|aj2fMpBdb(@Qlthh`DOVw5HZ-DUV`9l|NW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*PK!_mvy>M>HB_4YnIY~vFrY)fKH_5C_>kc=(7MnuCNm z+~gC<=_86j4MCtPL>g!3?%E>;xq@={lrVrU@b@TK8wG$w`yC;~MWfvON`_=<6W zpwrcB?DMrDC){`YXbXd-7xVQ7^9a$*nShJ}PiPq$k{oB~Em}BFSw-pg9ar`t&ydD` zeR_`^K9nqCdtcVOLP^p1oiJ_;Y-t>x3{9I1?1+ROZe?XTW#V{d*(pO$0~CQ8h`^6s zK!AG6GbjYx3Knyio+c8iD@<+{yh0N~9*|00000NkvXXu0mjf DEQL^^ literal 0 HcmV?d00001 From 0fc7c29c2f637ecd928d070b99280e92ab6b1e02 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sun, 6 Feb 2022 15:26:43 +0100 Subject: [PATCH 24/30] Push image down --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2a99e7b..3371712 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,10 @@ Nevertheless the project should work out of the box, be minimal but still open t ## Navigate this README Tip: use the Section icon in the top left of this document to navigate the sections. + ![README Sections](img/readme_sections.png) + # Requirements * `restic >=v0.9.6` * (recommended) GNU `make` if you want an automated install From 54e2d17e23dc2098c559a46df39459eee110e736 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Sun, 6 Feb 2022 15:28:56 +0100 Subject: [PATCH 25/30] Modified: CHANGELOG.md Makefile --- CHANGELOG.md | 4 +++- Makefile | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ffd3ef..83a2565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - `resticw` wrapper for working with different profiles without the need to source the profiles first. -- `$make install` will now make a timestamped backup of any existing `/etc/restic/*` files before installing a newer version. +- `$ make install-systemd` will now make a timestamped backup of any existing `/etc/restic/*` files before installing a newer version. +- `$ make install-cron` for installing the cron-job. ### Changed - **BREAKING CHANGE** moved systemd installation with makefile from `/etc/systemd/system` to `/usr/lib/systemd/system` as this is what packages should do. This is to be able to simplify the arch [PKGBUILD](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=restic-systemd-automatic-backup) so that it does not need to do anything else than `make install`. @@ -17,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # systemctl enable restic-backup@.timer ``` - **BREAKING CHANGE** moved script installation with makefile from `/usr/local/sbin` to `/sbin` to have a simpler interface to work with `$PREFIX`. +- Renamed top level make install targets. The old `$ make install` is now `$ make install-systemd` ### Fixed - Installation with custom `PREFIX` now works properly with Make: `$ PREFIX=/usr/local make install` whill now install everything at the expected location. With this, it's easy to use this script as non-root user on e.g. an macOS system. diff --git a/Makefile b/Makefile index a3df512..a11900d 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ uninstall: install-systemd: install-targets-script install-targets-conf install-targets-systemd # target: install-cron - Install cron setup. -install-cron: install-targets-cron +install-cron: install-targets-script install-targets-conf install-targets-cron # Install targets. Prereq build sources as well, # so that build dir is re-created if deleted. From 645df1a0d4020c656b047c794c40fbbfe24f74fc Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Mon, 7 Feb 2022 18:22:33 +0100 Subject: [PATCH 26/30] Move /sbin to /bin As more users would have /bin than /sbin in their PATH --- .github/workflows/linter.yml | 4 ++-- CHANGELOG.md | 2 +- Makefile | 2 +- README.md | 18 +++++++++--------- {sbin => bin}/cron_mail | 2 +- {sbin => bin}/nm-unmetered-connection.sh | 0 {sbin => bin}/restic_backup.sh | 0 {sbin => bin}/restic_check.sh | 0 {sbin => bin}/resticw | 0 {sbin => bin}/systemd-email | 0 etc/cron.d/restic | 2 +- .../system/nm-unmetered-connection.service | 2 +- usr/lib/systemd/system/restic-backup@.service | 2 +- usr/lib/systemd/system/restic-check@.service | 2 +- .../systemd/system/status-email-user@.service | 2 +- 15 files changed, 19 insertions(+), 19 deletions(-) rename {sbin => bin}/cron_mail (87%) rename {sbin => bin}/nm-unmetered-connection.sh (100%) rename {sbin => bin}/restic_backup.sh (100%) rename {sbin => bin}/restic_check.sh (100%) rename {sbin => bin}/resticw (100%) rename {sbin => bin}/systemd-email (100%) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 9d54d2a..964ccbc 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -7,13 +7,13 @@ on: paths: - '**.sh' - '.github/workflows/linter.yml' - - 'usr/local/sbin/**' + - 'bin/**' pull_request: branches: master paths: - '**.sh' - '.github/workflows/linter.yml' - - 'usr/local/sbin/**' + - 'bin/**' jobs: build: name: Lint Code Base diff --git a/CHANGELOG.md b/CHANGELOG.md index 83a2565..809d963 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # systemctl disable restic-backup@.timer # systemctl enable restic-backup@.timer ``` -- **BREAKING CHANGE** moved script installation with makefile from `/usr/local/sbin` to `/sbin` to have a simpler interface to work with `$PREFIX`. +- **BREAKING CHANGE** moved script installation with makefile from `/usr/local/sbin` to `/bin` to have a simpler interface to work with `$PREFIX`. - Renamed top level make install targets. The old `$ make install` is now `$ make install-systemd` ### Fixed diff --git a/Makefile b/Makefile index a11900d..b99233d 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ MKDIR_PARENTS=sh -c '\ ' MKDIR_PARENTS # Source directories. -DIR_SCRIPT = sbin +DIR_SCRIPT = bin DIR_CONF = etc/restic DIR_SYSTEMD = usr/lib/systemd/system DIR_CRON = etc/cron.d diff --git a/README.md b/README.md index 3371712..8fefdb8 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Depending on your system, the setup will look different. Choose one of $ sudo make install-systemd ``` ☝ **Note**: `sudo` is required here, as some files are installed into system directories (`/etc/` - and `/usr/sbin`). Have a look to the `Makefile` to know more. + and `/usr/bin`). Have a look to the `Makefile` to know more. 1. Fill out configuration values (edit with sudo): * `/etc/restic/pw.txt` - Contains the password (single line) to be used by restic to encrypt the repository files. Should be different than your B2 password! * `/etc/restic/_global.env` - Global environment variables. @@ -105,9 +105,9 @@ $ git clone https://github.com/erikw/restic-systemd-automatic-backup.git && cd $ $ sudo make install-systemd ```` -If you want to install everything manually, we will install files to `/etc`, `/sbin`, and not use the `$make install-systemd` command, then you need to clean up a placeholder `$INSTALL_PREFIX` in the souce files first by running: +If you want to install everything manually, we will install files to `/etc`, `/bin`, and not use the `$make install-systemd` command, then you need to clean up a placeholder `$INSTALL_PREFIX` in the souce files first by running: ```console -$ find etc sbin -type f -exec sed -i.bak -e 's|$INSTALL_PREFIX||g' {} \; -exec rm {}.bak \; +$ find etc bin -type f -exec sed -i.bak -e 's|$INSTALL_PREFIX||g' {} \; -exec rm {}.bak \; ``` and you should now see that all files have been changed like e.g. ```diff @@ -152,7 +152,7 @@ $ restic init ``` #### 4. Script for doing the backup -Put this file in `/sbin`: +Put this file in `/bin`: * `restic_backup.sh`: A script that defines how to run the backup. The intention is that you should not need to edit this script yourself, but be able to control everything from the `*.env` profiles. Restic support exclude files. They list file pattern paths to exclude from you backups, files that just occupy storage space, backup-time, network and money. `restic_backup.sh` allows for a few different exclude files. @@ -165,7 +165,7 @@ Now see if the backup itself works, by running as root ```console $ sudo -i $ source /etc/restic/default.env -$ /sbin/restic_backup.sh +$ /bin/restic_backup.sh ```` #### 6. Verify the backup @@ -229,7 +229,7 @@ $ journalctl -f -u restic-backup@default.service #### 8. Email notification on failure We want to be aware when the automatic backup fails, so we can fix it. Since my laptop does not run a mail server, I went for a solution to set up my laptop to be able to send emails with [postfix via my Gmail](https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/). Follow the instructions over there. -Put this file in `/sbin`: +Put this file in `/bin`: * `systemd-email`: Sends email using sendmail(1). This script also features time-out for not spamming Gmail servers and getting my account blocked. Put this files in `/etc/systemd/system/`: @@ -241,7 +241,7 @@ As you maybe noticed already before, `restic-backup.service` is configured to st #### 9. Optional: automated backup checks Once in a while it can be good to do a health check of the remote repository, to make sure it's not getting corrupt. This can be done with `$ restic check`. -There is companion scripts, service and timer (`*check*`) to restic-backup.sh that checks the restic backup for errors; look in the repo in `usr/lib/systemd/system/` and `sbin/` and copy what you need over to their corresponding locations. +There is companion scripts, service and timer (`*check*`) to restic-backup.sh that checks the restic backup for errors; look in the repo in `usr/lib/systemd/system/` and `bin/` and copy what you need over to their corresponding locations. ```console $ sudo -i @@ -272,7 +272,7 @@ If you want to run an all-classic cron job instead, do like this: 1. Follow the main setup from [Step-by-step and manual setup](#step-by-step-and-manual-setup) but skip the systemd parts. 1. `etc/cron.d/restic`: Depending on your system's cron, put this in `/etc/cron.d/` or similar, or copy the contents to $(sudo crontab -e). The format of this file is tested under FreeBSD, and might need adaptions depending on your cron. * You can use `$ make install-cron` to copy it over to `/etc/cron.d`. -1. (Optional) `sbin/cron_mail`: A wrapper for running cron jobs, that sends output of the job as an email using the mail(1) command. +1. (Optional) `bin/cron_mail`: A wrapper for running cron jobs, that sends output of the job as an email using the mail(1) command. # Uninstall @@ -294,7 +294,7 @@ A list of variations of this setup: * **Updating the `resticw` parser:** If you ever update the usage `DOC`, you will need to refresh the auto-generated parser: ```console $ pip install doctopt.sh - $ doctopt.sh usr/local/sbin/resticw + $ doctopt.sh usr/local/bin/resticw ``` # Releasing diff --git a/sbin/cron_mail b/bin/cron_mail similarity index 87% rename from sbin/cron_mail rename to bin/cron_mail index 65af7e4..cd5c07d 100755 --- a/sbin/cron_mail +++ b/bin/cron_mail @@ -5,7 +5,7 @@ # Why? Because of FreeBSD the system cron uses sendmail, and I want to use ssmtp. # Make your crontab files like: #SHELL=/bin/sh -#PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin +#PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:$INSTALL_PREFIX/bin #@daily root cron_mail freebsd-update cron mail_target=root diff --git a/sbin/nm-unmetered-connection.sh b/bin/nm-unmetered-connection.sh similarity index 100% rename from sbin/nm-unmetered-connection.sh rename to bin/nm-unmetered-connection.sh diff --git a/sbin/restic_backup.sh b/bin/restic_backup.sh similarity index 100% rename from sbin/restic_backup.sh rename to bin/restic_backup.sh diff --git a/sbin/restic_check.sh b/bin/restic_check.sh similarity index 100% rename from sbin/restic_check.sh rename to bin/restic_check.sh diff --git a/sbin/resticw b/bin/resticw similarity index 100% rename from sbin/resticw rename to bin/resticw diff --git a/sbin/systemd-email b/bin/systemd-email similarity index 100% rename from sbin/systemd-email rename to bin/systemd-email diff --git a/etc/cron.d/restic b/etc/cron.d/restic index 95f8ddb..ed6f5ce 100644 --- a/etc/cron.d/restic +++ b/etc/cron.d/restic @@ -1,5 +1,5 @@ SHELL=/bin/sh -PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:$INSTALL_PREFIX/sbin/ +PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:$INSTALL_PREFIX/bin/ # Order of crontab fields # minute hour mday month wday command # Reference: https://www.freebsd.org/doc/handbook/configtuning-cron.html diff --git a/usr/lib/systemd/system/nm-unmetered-connection.service b/usr/lib/systemd/system/nm-unmetered-connection.service index 9ae42d8..89871c4 100644 --- a/usr/lib/systemd/system/nm-unmetered-connection.service +++ b/usr/lib/systemd/system/nm-unmetered-connection.service @@ -3,4 +3,4 @@ Description=Check if the current NetworkManager connection is metered [Service] Type=oneshot -ExecStart=$INSTALL_PREFIX/sbin/nm-unmetered-connection.sh +ExecStart=$INSTALL_PREFIX/bin/nm-unmetered-connection.sh diff --git a/usr/lib/systemd/system/restic-backup@.service b/usr/lib/systemd/system/restic-backup@.service index 84d46d9..b435f00 100644 --- a/usr/lib/systemd/system/restic-backup@.service +++ b/usr/lib/systemd/system/restic-backup@.service @@ -10,4 +10,4 @@ Nice=10 Environment="HOME=/root" # The random sleep (in seconds) is in the case of multiple backup profiles. Many restic instances started at the same time could case high load or network bandwith usage. # `systemd-cat` allows showing the restic output to the systemd journal -ExecStart=bash -c 'sleep $(shuf -i 0-300 -n 1) && source $INSTALL_PREFIX/etc/restic/%I.env && $INSTALL_PREFIX/sbin/restic_backup.sh | systemd-cat' +ExecStart=bash -c 'sleep $(shuf -i 0-300 -n 1) && source $INSTALL_PREFIX/etc/restic/%I.env && $INSTALL_PREFIX/bin/restic_backup.sh | systemd-cat' diff --git a/usr/lib/systemd/system/restic-check@.service b/usr/lib/systemd/system/restic-check@.service index 30eca31..8bc3653 100644 --- a/usr/lib/systemd/system/restic-check@.service +++ b/usr/lib/systemd/system/restic-check@.service @@ -8,4 +8,4 @@ Requires=nm-unmetered-connection.service Type=simple Nice=10 # `systemd-cat` allows showing the restic output to the systemd journal -ExecStart=bash -c 'source $INSTALL_PREFIX/etc/restic/%I.env && $INSTALL_PREFIX/sbin/restic_check.sh | systemd-cat' +ExecStart=bash -c 'source $INSTALL_PREFIX/etc/restic/%I.env && $INSTALL_PREFIX/bin/restic_check.sh | systemd-cat' diff --git a/usr/lib/systemd/system/status-email-user@.service b/usr/lib/systemd/system/status-email-user@.service index 697bad2..7b68afe 100644 --- a/usr/lib/systemd/system/status-email-user@.service +++ b/usr/lib/systemd/system/status-email-user@.service @@ -6,6 +6,6 @@ Description=Send status email for %i to user [Service] Type=oneshot -ExecStart=$INSTALL_PREFIX/sbin/systemd-email abc@gmail.com %i +ExecStart=$INSTALL_PREFIX/bin/systemd-email abc@gmail.com %i User=root Group=systemd-journal From b4684d3cfb08066750f0cbbc4c19ed89f88776eb Mon Sep 17 00:00:00 2001 From: Gerard Bosch <30733556+gerardbosch@users.noreply.github.com> Date: Tue, 8 Feb 2022 13:01:32 +0100 Subject: [PATCH 27/30] Fix README: Backup frequency (#68) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8fefdb8..8e385ef 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Depending on your system, the setup will look different. Choose one of * `/etc/restic/backup_exclude.txt` - List of file patterns to ignore. This will trim down your backup size and the speed of the backup a lot when done properly! 1. Initialize remote repo as described [below](#3-initialize-remote-repo) 1. Configure [how often](https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events) back up should be made. - * Edit if needed `OnCalendar` in `/usr/lib/systemd/system/restic-check@.timer`. + * Edit if needed `OnCalendar` in `/usr/lib/systemd/system/restic-backup@.timer`. 1. Enable automated backup for starting with the system (`enable` creates symlinks): ```console $ sudo systemctl start restic-backup@default.timer From 2dbd618344751688a1ae708bbef0e15187a96e73 Mon Sep 17 00:00:00 2001 From: Gerard Bosch <30733556+gerardbosch@users.noreply.github.com> Date: Tue, 8 Feb 2022 16:43:30 +0100 Subject: [PATCH 28/30] Fix README: Enabling/starting systemd unit (#69) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit systemctl start restic-backup@default.timer was failing with the following message: ```console ❯ sudo systemctl start restic-backup@default.timer Failed to start restic-backup@default.timer: Unit nm-unmetered-connection.service failed to load properly, please adjust/correct and reload service manager: Device or resource busy See system logs and 'systemctl status restic-backup@default.timer' for details. ``` and by doing `systemctl daemon-reload` before that command solved the issue. But according to `man systemd` in order to avoid this, it seems that `enable` command must be issued before `start`, as it reloads the system manager configuration (in a way equivalent to daemon-reload). So, once properly sorted, it seems that both commands can be fused into a single `enable --now` command :) --- README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8e385ef..2cb0cac 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,7 @@ Depending on your system, the setup will look different. Choose one of * Edit if needed `OnCalendar` in `/usr/lib/systemd/system/restic-backup@.timer`. 1. Enable automated backup for starting with the system (`enable` creates symlinks): ```console - $ sudo systemctl start restic-backup@default.timer - $ sudo systemctl enable restic-backup@default.timer + $ sudo systemctl enable --now restic-backup@default.timer ``` 1. And run an immediate backup if you want (if not, it will run on daily basis): ```console @@ -89,8 +88,7 @@ Depending on your system, the setup will look different. Choose one of 1. (optional) Define multiple profiles: just make a copy of the `default.env` and use the defined profile name in place of `default` to run backups or enable timers. Notice that the value after `@` works as a parameter. 1. (optional) Enable the check job that verifies that the backups for the profile are all intact. ```console - $ sudo systemctl start restic-check@default.timer - $ sudo systemctl enable restic-check@default.timer + $ sudo systemctl enable --now restic-check@default.timer ```` 1. (optional) Setup email on failure as described [here](#8-email-notification-on-failure) @@ -193,8 +191,7 @@ Put these files in `/etc/systemd/system` (note that the Makefile installs as pac Now simply enable the timer with: ```console -$ systemctl start restic-backup@default.timer -$ systemctl enable restic-backup@default.timer +$ sudo systemctl enable --now restic-backup@default.timer ```` ☝ **Note**: You can run it with different values instead of `default` if you use multiple profiles. @@ -244,9 +241,7 @@ Once in a while it can be good to do a health check of the remote repository, to There is companion scripts, service and timer (`*check*`) to restic-backup.sh that checks the restic backup for errors; look in the repo in `usr/lib/systemd/system/` and `bin/` and copy what you need over to their corresponding locations. ```console -$ sudo -i -$ systemctl start restic-check@default.timer -$ systemctl enable restic-check@default.timer +$ sudo systemctl enable --now restic-check@default.timer ```` #### 10. Optional: 🏃 Restic wrapper From e6884998382e073a23f31dbe5cd2a98bb1083387 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Tue, 8 Feb 2022 16:49:10 +0100 Subject: [PATCH 29/30] Surpress mkdir in make install --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b99233d..72256bf 100644 --- a/Makefile +++ b/Makefile @@ -115,26 +115,26 @@ install-targets-cron: $(DEST_TARGS_CRON) $(BUILD_SRCS_CRON) # Copies sources to build directory & replace "$INSTALL_PREFIX". $(BUILD_DIR)/% : % - ${MKDIR_PARENTS} $@ + @${MKDIR_PARENTS} $@ cp $< $@ sed -i.bak -e 's|$$INSTALL_PREFIX|$(PREFIX)|g' $@; rm $@.bak # Install destination script files. $(DEST_DIR_SCRIPT)/%: $(BUILD_DIR_SCRIPT)/% - ${MKDIR_PARENTS} $@ + @${MKDIR_PARENTS} $@ install -m 0744 $< $@ # Install destination conf files. Additionally backup existing files. $(DEST_DIR_CONF)/%: $(BUILD_DIR_CONF)/% - ${MKDIR_PARENTS} $@ + @${MKDIR_PARENTS} $@ install -m 0600 -b $(BAK_SUFFIX) $< $@ # Install destination systemd files. $(DEST_DIR_SYSTEMD)/%: $(BUILD_DIR_SYSTEMD)/% - ${MKDIR_PARENTS} $@ + @${MKDIR_PARENTS} $@ install -m 0644 $< $@ # Install destination cron files. $(DEST_DIR_CRON)/%: $(BUILD_DIR_CRON)/% - ${MKDIR_PARENTS} $@ + @${MKDIR_PARENTS} $@ install -m 0644 $< $@ From 6c1d182e21643c0c3ceb48c2352ceca010775401 Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Tue, 8 Feb 2022 17:13:26 +0100 Subject: [PATCH 30/30] Only sleep in service if other restic running --- usr/lib/systemd/system/restic-backup@.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/lib/systemd/system/restic-backup@.service b/usr/lib/systemd/system/restic-backup@.service index b435f00..b5c0d11 100644 --- a/usr/lib/systemd/system/restic-backup@.service +++ b/usr/lib/systemd/system/restic-backup@.service @@ -10,4 +10,4 @@ Nice=10 Environment="HOME=/root" # The random sleep (in seconds) is in the case of multiple backup profiles. Many restic instances started at the same time could case high load or network bandwith usage. # `systemd-cat` allows showing the restic output to the systemd journal -ExecStart=bash -c 'sleep $(shuf -i 0-300 -n 1) && source $INSTALL_PREFIX/etc/restic/%I.env && $INSTALL_PREFIX/bin/restic_backup.sh | systemd-cat' +ExecStart=bash -c 'ps cax | grep -q restic && sleep $(shuf -i 0-300 -n 1); source $INSTALL_PREFIX/etc/restic/%I.env && $INSTALL_PREFIX/bin/restic_backup.sh | systemd-cat'