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