21 Commits

Author SHA1 Message Date
Erik Westrup
3a8ca5a815 Modified: CHANGELOG.md 2022-02-13 19:20:15 +01:00
Erik Westrup
37e38b4cb5 Modified: CHANGELOG.md 2022-02-13 19:20:02 +01:00
Erik Westrup
8f734ccc69 How to disable old launchagent 2022-02-13 19:19:00 +01:00
Erik Westrup
56c4fca8f6 Merge branch 'optionals'
* optionals:
  Made scripts optional
  Cron not using cron_email by default
2022-02-13 19:18:37 +01:00
Erik Westrup
9449d78596 Made scripts optional 2022-02-13 19:15:55 +01:00
Erik Westrup
c50e66b48f Cron not using cron_email by default 2022-02-13 18:47:31 +01:00
Erik Westrup
c1edb2efe1 Remove execution bit on bin/ as these are set when installing 2022-02-13 18:45:52 +01:00
Erik Westrup
8275f708ea Link to schedtask doc 2022-02-13 18:37:04 +01:00
Erik Westrup
eac8b97932 Modified: CHANGELOG.md 2022-02-13 17:53:36 +01:00
Erik Westrup
bb40afa67a Rename launchagent for consistency 2022-02-13 17:50:10 +01:00
Erik Westrup
cacfe58269 Merge branch 'rename_repo'
* rename_repo:
  replace old with new name
  Update into
2022-02-13 16:40:35 +01:00
Erik Westrup
96e9bc23ab replace old with new name 2022-02-13 16:39:25 +01:00
Erik Westrup
911f9f44d2 Update into 2022-02-13 16:33:12 +01:00
Erik Westrup
abac4b11ba Remove duplicated readme line 2022-02-13 15:54:05 +01:00
Erik Westrup
cfaab7eb72 Move schedtasks to own subdir 2022-02-13 11:46:02 +01:00
Erik Westrup
978ca2becb Merge branch 'winfix'
* winfix:
  Modified: Makefile
  Add uninstall
  rename schedtask ps1
  scoop prefix git
2022-02-13 11:35:08 +01:00
Erik Westrup
6cb6b41066 Modified: Makefile 2022-02-13 11:32:58 +01:00
Erik Westrup
16302e5d35 Add uninstall 2022-02-13 11:29:04 +01:00
Erik Westrup
aeec8991b6 rename schedtask ps1 2022-02-13 11:14:04 +01:00
Erik Westrup
0f5a8f0ca5 scoop prefix git 2022-02-13 11:10:38 +01:00
Erik Westrup
4a2ca821d7 Merge pull request #78 from erikw/windows
Add Windows support with TaskScheduler
2022-02-12 20:46:39 +01:00
15 changed files with 138 additions and 63 deletions

View File

@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [7.1.0] - 2022-02-13
### Changed
- Minimize base install. The following features are now opt-in: nm-unmetered detection, cron_mail, systemd-email.
## [7.0.0] - 2022-02-13
### Changed
- Renamed project from `restic-systemd-automatic-backup` to `restic-automatic-backup-scheduler` to fit all now supported setups.
## [6.0.0] - 2022-02-12
### Added
- Windows support with native ScheduledTask! New target `$ make install-schedtask` for Windows users.
@@ -44,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `$ 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`.
- **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-automatic-backup-scheduler) 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@<profile>.timer
@@ -88,7 +96,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.0.0] - 2022-02-01
### Changed
- **BREAKING CHANGE** [#45](https://github.com/erikw/restic-systemd-automatic-backup/pull/45): multiple backup profiles are now supported. Please backup your configuration before upgrading. The setup of configuration files are now laied out differently. See the [README.md](README.md) TL;DR setup section.
- **BREAKING CHANGE** [#45](https://github.com/erikw/restic-automatic-backup-scheduler/pull/45): multiple backup profiles are now supported. Please backup your configuration before upgrading. The setup of configuration files are now laied out differently. See the [README.md](README.md) TL;DR setup section.
- `restic_backup.sh` has had variables extracted to profiles instead, to allow for configuration of different backups on the same system.
- `b2_env.sh` is split to two files `_global.env` and `default.env` (the default profile). `_global.env` will have B2 accountID and accountKey and `default.env` has backup paths, and retention.
- `b2_pw.sh` renamed to pw.txt
@@ -99,7 +107,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.0.1] - 2021-12-03
### Fixed
- $(make install) now works for the *.template files ([#40](https://github.com/erikw/restic-systemd-automatic-backup/issues/40))
- $(make install) now works for the *.template files ([#40](https://github.com/erikw/restic-automatic-backup-scheduler/issues/40))
## [1.0.0] - 2021-12-02
It's time to call this a proper major version!

View File

@@ -1,5 +1,4 @@
restic-systemd-automatic-backup - My restic backup solution using Backblaze B2 storage, systemd timers (or cron) and email notifications on failure.
restic-automatic-backup-scheduler - Automatic restic backup using Backblaze B2 storage, Linux systemd timers, macOS LaunchAgent, Windows ScheduledTask or simply cron
Copyright (c) 2022, Erik Westrup + see commit log for auhtors
All rights reserved.

View File

@@ -6,7 +6,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.github.erikw.restic-automatic-backup</string>
<string>com.github.erikw.restic-automatic-backup-scheduler</string>
<key>ProgramArguments</key>
<!-- exec in subshell to 1) source *.env.sh 2) expand $HOME to logpath (ref. https://apple.stackexchange.com/a/365880/197493) -->
<array>

View File

@@ -19,7 +19,7 @@
install-systemd install-cron \
install-targets-script install-targets-conf install-targets-systemd \
install-targets-cron install-targets-launchagent \
install-targets-schedtask \
install-targets-schedtask uninstall-targets-schedtask \
activate-launchagent deactivate-launchagent
#### Macros ###################################################################
@@ -34,6 +34,15 @@ else
BAK_SUFFIX = -B .$(NOW).bak
endif
# Source: https://stackoverflow.com/a/14777895/265508
ifeq ($(OS),Windows_NT)
CUR_OS := Windows
else
CUR_OS := $(shell uname)
endif
# Create parent directories of a file, if not existing.
# Reference: https://stackoverflow.com/a/25574592/265508
MKDIR_PARENTS=sh -c '\
@@ -43,7 +52,7 @@ MKDIR_PARENTS=sh -c '\
# LaunchAgent names.
UID := $(shell id -u)
LAUNCHAGENT = com.github.erikw.restic-automatic-backup
LAUNCHAGENT = com.github.erikw.restic-automatic-backup-scheduler
LAUNCHAGENT_TARGET = gui/$(UID)/$(LAUNCHAGENT)
# What to substitute $INSTALL_PREFIX in sources to.
@@ -57,29 +66,42 @@ SYSCONFDIR := $(PREFIX)
# Where to install LaunchAgent. Used by Homebrew.
LAUNCHAGENTDIR := $(HOME)
# ScheduledTask powershell scripts.
SCHEDTASK_INSTALL = install.ps1
SCHEDTASK_UNINSTALL = uninstall.ps1
# Source directories.
DIR_SCRIPT = bin
DIR_CONF = etc/restic
DIR_SYSTEMD = usr/lib/systemd/system
DIR_CRON = etc/cron.d
DIR_LAUNCHAGENT = Library/LaunchAgents
DIR_SCHEDTASK = ScheduledTask
# Source files.
SRCS_SCRIPT = $(filter-out %cron_mail, $(wildcard $(DIR_SCRIPT)/*))
SRCS_SCRIPT = $(filter-out \
%cron_mail \
%systemd-email \
%nm-unmetered-connection.sh \
, $(wildcard $(DIR_SCRIPT)/*))
SRCS_CONF = $(wildcard $(DIR_CONF)/*)
SRCS_SYSTEMD = $(wildcard $(DIR_SYSTEMD)/*)
SRCS_SYSTEMD = $(filter-out \
%status-email-user@.service \
%nm-unmetered-connection.service \
, $(wildcard $(DIR_SYSTEMD)/*))
SRCS_CRON = $(wildcard $(DIR_CRON)/*)
SRCS_LAUNCHAGENT= $(wildcard $(DIR_LAUNCHAGENT)/*)
SRCS_SCHEDTASK = install_restic_scheduledtask.ps1
SRCS_SCHEDTASK = $(wildcard $(DIR_SCHEDTASK)/*)
# Local build directory. Sources will be copied here,
# modified and then installed from this directory.
BUILD_DIR := build
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)
BUILD_DIR_LAUNCHAGENT = $(BUILD_DIR)/$(DIR_LAUNCHAGENT)
BUILD_DIR_SCHEDTASK = $(BUILD_DIR)/$(DIR_SCHEDTASK)
# Sources copied to build directory.
BUILD_SRCS_SCRIPT = $(addprefix $(BUILD_DIR)/, $(SRCS_SCRIPT))
@@ -119,7 +141,7 @@ clean:
$(RM) -r $(BUILD_DIR)
# target: uninstall - Uninstall ALL installed (including config) files.
uninstall:
uninstall: uninstall-schedtask
@for file in $(INSTALLED_FILES); do \
echo $(RM) $$file; \
$(RM) $$file; \
@@ -140,10 +162,13 @@ install-cron: install-targets-script install-targets-conf install-targets-cron
install-launchagent: install-targets-script install-targets-conf \
install-targets-launchagent
# target: install-schedtask - Install Windows ScheduledTask
# target: install-schedtask - Install Windows ScheduledTasks
install-schedtask: install-targets-script install-targets-conf \
install-targets-schedtask
# target: uninstall-schedtask - Uninstall Windows ScheduledTasks
uninstall-schedtask: uninstall-targets-schedtask
# Install targets. Prereq build sources as well,
# so that build dir is re-created if deleted.
install-targets-script: $(DEST_TARGS_SCRIPT) $(BUILD_SRCS_SCRIPT)
@@ -152,8 +177,11 @@ install-targets-systemd: $(DEST_TARGS_SYSTEMD) $(BUILD_SRCS_SYSTEMD)
install-targets-cron: $(DEST_TARGS_CRON) $(BUILD_SRCS_CRON)
install-targets-launchagent: $(DEST_TARGS_LAUNCHAGENT) \
$(BUILD_SRCS_LAUNCHAGENT) $(DEST_DIR_MAC_LOG)
install-targets-schedtask: $(BUILD_SRCS_SCHEDTASK)
./$<
install-targets-schedtask: $(BUILD_DIR_SCHEDTASK)/$(SCHEDTASK_INSTALL)
test $(CUR_OS) != Windows || ./$<
uninstall-targets-schedtask: $(BUILD_DIR_SCHEDTASK)/$(SCHEDTASK_UNINSTALL)
test $(CUR_OS) != Windows || ./$<
# Copies sources to build directory & replace "$INSTALL_PREFIX".
$(BUILD_DIR)/% : %

View File

@@ -1,28 +1,30 @@
# Automatic restic backups using systemd services and timers
[![GitHub Stars](https://img.shields.io/github/stars/erikw/restic-systemd-automatic-backup?style=social)](#)
[![GitHub Forks](https://img.shields.io/github/forks/erikw/restic-systemd-automatic-backup?style=social)](#)
*formerly named restic-systemd-automatic-backup*
[![GitHub Stars](https://img.shields.io/github/stars/erikw/restic-automatic-backup-scheduler?style=social)](#)
[![GitHub Forks](https://img.shields.io/github/forks/erikw/restic-automatic-backup-scheduler?style=social)](#)
<br>
[![Lint Code Base](https://github.com/erikw/restic-systemd-automatic-backup/actions/workflows/linter.yml/badge.svg)](https://github.com/erikw/restic-systemd-automatic-backup/actions/workflows/linter.yml)
[![Latest tag](https://img.shields.io/github/v/tag/erikw/restic-systemd-automatic-backup)](https://github.com/erikw/restic-systemd-automatic-backup/tags)
[![AUR version](https://img.shields.io/aur/version/restic-systemd-automatic-backup)](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/)
[![AUR maintainer](https://img.shields.io/aur/maintainer/restic-systemd-automatic-backup?label=AUR%20maintainer)](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/)
[![Lint Code Base](https://github.com/erikw/restic-automatic-backup-scheduler/actions/workflows/linter.yml/badge.svg)](https://github.com/erikw/restic-automatic-backup-scheduler/actions/workflows/linter.yml)
[![Latest tag](https://img.shields.io/github/v/tag/erikw/restic-automatic-backup-scheduler)](https://github.com/erikw/restic-automatic-backup-scheduler/tags)
[![AUR version](https://img.shields.io/aur/version/restic-automatic-backup-scheduler)](https://aur.archlinux.org/packages/restic-automatic-backup-scheduler/)
[![AUR maintainer](https://img.shields.io/aur/maintainer/restic-automatic-backup-scheduler?label=AUR%20maintainer)](https://aur.archlinux.org/packages/restic-automatic-backup-scheduler/)
[![Homebrew Formula](https://img.shields.io/badge/homebrew-erikw%2Ftap-orange)](https://github.com/erikw/homebrew-tap)
[![Open issues](https://img.shields.io/github/issues/erikw/restic-systemd-automatic-backup)](https://github.com/erikw/restic-systemd-automatic-backup/issues)
[![Closed issues](https://img.shields.io/github/issues-closed/erikw/restic-systemd-automatic-backup?color=success)](https://github.com/erikw/restic-systemd-automatic-backup/issues?q=is%3Aissue+is%3Aclosed)
[![Closed PRs](https://img.shields.io/github/issues-pr-closed/erikw/restic-systemd-automatic-backup?color=success)](https://github.com/erikw/restic-systemd-automatic-backup/pulls?q=is%3Apr+is%3Aclosed)
[![Open issues](https://img.shields.io/github/issues/erikw/restic-automatic-backup-scheduler)](https://github.com/erikw/restic-automatic-backup-scheduler/issues)
[![Closed issues](https://img.shields.io/github/issues-closed/erikw/restic-automatic-backup-scheduler?color=success)](https://github.com/erikw/restic-automatic-backup-scheduler/issues?q=is%3Aissue+is%3Aclosed)
[![Closed PRs](https://img.shields.io/github/issues-pr-closed/erikw/restic-automatic-backup-scheduler?color=success)](https://github.com/erikw/restic-automatic-backup-scheduler/pulls?q=is%3Apr+is%3Aclosed)
[![License](https://img.shields.io/badge/license-BSD--3-blue)](LICENSE)
[![OSS Lifecycle](https://img.shields.io/osslifecycle/erikw/restic-systemd-automatic-backup)](https://github.com/Netflix/osstracker)
[![OSS Lifecycle](https://img.shields.io/osslifecycle/erikw/restic-automatic-backup-scheduler)](https://github.com/Netflix/osstracker)
<br>
[![Contributors](https://img.shields.io/github/contributors/erikw/restic-systemd-automatic-backup)](https://github.com/erikw/restic-systemd-automatic-backup/graphs/contributors) including these top contributors:
<a href = "https://github.com/erikw/restic-systemd-automatic-backup/graphs/contributors">
<img src = "https://contrib.rocks/image?repo=erikw/restic-systemd-automatic-backup&max=24"/>
[![Contributors](https://img.shields.io/github/contributors/erikw/restic-automatic-backup-scheduler)](https://github.com/erikw/restic-automatic-backup-scheduler/graphs/contributors) including these top contributors:
<a href = "https://github.com/erikw/restic-automatic-backup-scheduler/graphs/contributors">
<img src = "https://contrib.rocks/image?repo=erikw/restic-automatic-backup-scheduler&max=24"/>
</a>
# Intro
[restic](https://restic.net/) is a command-line tool for making backups, the right way. Check the official website for a feature explanation. As a storage backend, I recommend [Backblaze B2](https://www.backblaze.com/b2/cloud-storage.html) as restic works well with it, and it is (at the time of writing) very affordable for the hobbyist hacker! (anecdotal: I pay for my full-systems backups each month typically < 1 USD).
Unfortunately restic does not come pre-configured with a way to run automated backups, say every day. However it's possible to set this up yourself using systemd/cron and some wrappers. This example also features email notifications when a backup fails to complete.
Unfortunately restic does not come pre-configured with a way to run automated backups, say every day. However it's possible to set this up yourself using built-in tools in your OS and some wrappers. For Linux with systemd, it's convenient to use systemd timers. For macOS systems, we can use built-in LaunchAgents. For Windows we can use ScheduledTasks. Any OS having something cron-like will also work!
Here follows a step-by step tutorial on how to set it up, with my sample script and configurations that you can modify to suit your needs.
@@ -102,7 +104,7 @@ This is a more detailed explanation than the TL;DR section that will give you mo
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:
```console
$ git clone https://github.com/erikw/restic-systemd-automatic-backup.git && cd $(basename "$_" .git)
$ git clone https://github.com/erikw/restic-automatic-backup-scheduler.git && cd $(basename "$_" .git)
$ sudo make install-systemd
````
@@ -118,9 +120,9 @@ and you should now see that all files have been changed like e.g.
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.:
Arch Linux users can install the aur package [restic-automatic-backup-scheduler](https://aur.archlinux.org/packages/restic-automatic-backup-scheduler/) e.g. with `yay(1)`:
```console
$ yaourt -S restic-systemd-automatic-backup
$ yay -S restic-automatic-backup-scheduler
````
#### 1. Create Backblaze B2 Account, Bucket and keys
@@ -235,7 +237,10 @@ Put this file in `/bin`:
Put this files in `/etc/systemd/system/`:
* `status-email-user@.service`: A service that can notify you via email when a systemd service fails. Edit the target email address in this file.
As you maybe noticed already before, `restic-backup.service` is configured to start `status-email-user.service` on failure.
Now edit `restic-backup.service` and `status-email-user.service` to call this service failure.
```
OnFailure=status-email-user@%n.service
```
#### 9. Optional: automated backup checks
@@ -247,7 +252,23 @@ There is companion scripts, service and timer (`*check*`) to restic-backup.sh th
$ sudo systemctl enable --now restic-check@default.timer
````
#### 10. Optional: 🏃 Restic wrapper
#### 10. Optional: No backup on metered connections
For a laptop, it can make sense to not do heavy backups when your on a metered connection like a shared connection from you mobile phone. To solve this we can set up a systemd service that is in success state only when a connection is unmetered. Then we can tell our backup service to depend on this service simply! When the unmetered service detects an unmetered connection it will go to failed state. Then our backup service will not run as it requires this other service to be in success state.
Put this file in `/bin`:
* `nm-unmetered-connection.sh`: Detects metered connections and returns will error code if one is detected. This scripts requires the Gnome [NetworkManager](https://wiki.gnome.org/Projects/NetworkManager) to be installed. Modify this script if your system has a different network manager.
Put this files in `/etc/systemd/system/`:
* `nm-unmetered-connection.service`: A service that is in success state if the connection is unmetered only.
Now edit `restic-backup.service` and `status-email-user.service` to require the new service to be in success state:
```
Requires=nm-unmetered-connection.service
```
#### 11. 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:
@@ -264,7 +285,6 @@ straightforward (it needs to run with sudo to read environment). Just run:
| `resticw mount /mnt/restic` | Mount your remote repository |
## Setup macOS LaunchAgent
LaunchAgent is the modern service scheduler in in macOS that uses [Launchd](https://www.launchd.info/).
[Launchd](https://www.launchd.info/) is the modern built-in service scheduler in macOS. It has support for running services as root (Daemon) or as a normal user (Agent). Here we set up an LauchAgent to be run as your normal user for starting regular backups.
### Homebrew
@@ -280,6 +300,12 @@ $ brew services restart restic-automatic-backup-scheduler
$ brew services stop restic-automatic-backup-scheduler
```
If `services start` fails, it might be due to previous version installed. In that case remove the existing version and try again:
```console
$ launchctl bootout gui/$UID/com.github.erikw.restic-automatic-backup-scheduler
$ brew services start restic-automatic-backup-scheduler
```
### Manual
1. In general, follow the same setup as in (#setup-linux-systemd) except for:
* use `make install-launchagent` instead of `make install-systemd`
@@ -290,26 +316,28 @@ $ brew services stop restic-automatic-backup-scheduler
```
1. After installation with `make` , edit the installed LaunchAgent if you want to change the default schedule or profile used:
```console
$ vim ~/Library/LaunchAgents/com.github.erikw.restic-automatic-backup.plist
$ vim ~/Library/LaunchAgents/com.github.erikw.restic-automatic-backup.plist
```
1. Now install, enable and start the first run!
```console
$ launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.github.erikw.restic-automatic-backup.plist
$ launchctl enable gui/$UID/com.github.erikw.restic-automatic-backup
$ launchctl kickstart -p gui/$UID/com.github.erikw.restic-automatic-backup
$ launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.github.erikw.restic-automatic-backup-scheduler.plist
$ launchctl enable gui/$UID/com.github.erikw.restic-automatic-backup-scheduler
$ launchctl kickstart -p gui/$UID/com.github.erikw.restic-automatic-backup-scheduler
```
As a convenience, a shortcut for the above commands are `$ make activate-launchagent`.
Use the `disable` command to temporarily pause the agent, or `bootout` to uninstall it.
```
$ launchctl disable gui/$UID/com.github.erikw.restic-automatic-backup
$ launchctl bootout gui/$UID/com.github.erikw.restic-automatic-backup
$ launchctl disable gui/$UID/com.github.erikw.restic-automatic-backup-scheduler
$ launchctl bootout gui/$UID/com.github.erikw.restic-automatic-backup-scheduler
```
If you updated the `.plist` file, you need to issue the `bootout` followed by `bootrstrap` and `enable` sub-commands of `launchctl`. This will guarantee that the file is properly reloaded.
## Setup Windows ScheduledTask
Windows comes with a built-in task scheduler called [ScheduledTask](https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtask?view=windowsserver2022-ps). The frontend app is "Task scheduler" (`taskschd.msc`) and we can use PowerShell commands to install a new scheduled task.
This is one of may ways you can get restic and this backup script working on Windows:
1. Install [scoop](https://scoop.sh/)
1. Install dependencies from a PowerShell with administrator privileges:
@@ -320,7 +348,7 @@ This is one of may ways you can get restic and this backup script working on Win
```console
powershell> git-bash
git-bash$ mkdir ~/src && cd ~/src/
git-bash$ git clone https://github.com/erikw/restic-systemd-automatic-backup.git && cd $(basename "$_" .git)
git-bash$ git clone https://github.com/erikw/restic-automatic-backup-scheduler.git && cd $(basename "$_" .git)
```
1. Install scripts, conf and the ScheduledTask
```console
@@ -368,7 +396,7 @@ $ sudo make uninstall
# Variations
A list of variations of this setup:
* Using `--files-from` [#44](https://github.com/erikw/restic-systemd-automatic-backup/issues/44)
* Using `--files-from` [#44](https://github.com/erikw/restic-automatic-backup-scheduler/issues/44)
# Development
* To not mess up your real installation when changing the `Makefile` simply install to a `$PREFIX` like
@@ -389,5 +417,5 @@ To make a new release:
$ git tag vX.Y.Z
$ git push && git push --tags
```
1. Update version in the AUR [PKGBUILD](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/).
1. Update version in the AUR [PKGBUILD](https://aur.archlinux.org/packages/restic-automatic-backup-scheduler/).
1. Update version in the Homebrew [Formula](https://github.com/erikw/homebrew-tap/blob/main/Formula/restic-automatic-backup-scheduler.rb).

View File

@@ -9,11 +9,11 @@
# Install restic_backup.sh
$action = New-ScheduledTaskAction -Execute 'C:\Program Files\Git\git-bash.exe' -Argument '-l -c "source $INSTALL_PREFIX/etc/restic/default.env.sh && $INSTALL_PREFIX/bin/restic_backup.sh"'
$action = New-ScheduledTaskAction -Execute "$(scoop prefix git)\git-bash.exe" -Argument '-l -c "source $INSTALL_PREFIX/etc/restic/default.env.sh && $INSTALL_PREFIX/bin/restic_backup.sh"'
$trigger = New-ScheduledTaskTrigger -Daily -At 7pm
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "restic_backup" -Description "Daily backup to B2 with restic."
# Install restic_check.sh
$action = New-ScheduledTaskAction -Execute 'C:\Program Files\Git\git-bash.exe' -Argument '-l -c "source $INSTALL_PREFIX/etc/restic/default.env.sh && /INSTALL_PREFIX/bin/restic_check.sh"'
$action = New-ScheduledTaskAction -Execute "$(scoop prefix git)\git-bash.exe" -Argument '-l -c "source $INSTALL_PREFIX/etc/restic/default.env.sh && /INSTALL_PREFIX/bin/restic_check.sh"'
$trigger = New-ScheduledTaskTrigger -Weekly -WeeksInterval 4 -DaysOfWeek Sunday -At 8pm -RandomDelay 128
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "restic_check" -Description "Check B2 backups with restic."

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env pwsh
# Uninstall restic scheduled tasks.
Unregister-ScheduledTask -TaskName "restic_backup" -Confirm:$false
Unregister-ScheduledTask -TaskName "restic_check" -Confirm:$false

0
bin/cron_mail Executable file → Normal file
View File

View File

@@ -1,19 +1,19 @@
#!/bin/bash
#!/usr/bin/env bash
# Requires Gnome NetworkManager
systemctl is-active dbus.service >/dev/null 2>&1 || exit 0
systemctl is-active NetworkManager.service >/dev/null 2>&1 || exit 0
metered_status=$(dbus-send --system --print-reply=literal \
--system --dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.NetworkManager string:Metered \
| grep -o ".$")
--system --dest=org.freedesktop.NetworkManager \
/org/freedesktop/NetworkManager \
org.freedesktop.DBus.Properties.Get \
string:org.freedesktop.NetworkManager string:Metered \
| grep -o ".$")
if [[ $metered_status =~ (1|3) ]]; then
echo Current connection is metered
exit 1
else
else
exit 0
fi

0
bin/resticw Executable file → Normal file
View File

View File

@@ -4,5 +4,10 @@ PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:$INSTALL_PREFIX/bin/
# minute hour mday month wday command
# Reference: https://www.freebsd.org/doc/handbook/configtuning-cron.html
# Reference: crontab(5).
@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
@midnight root . $INSTALL_PREFIX/etc/restic/default.sh && restic_backup.sh
@monthly root . $INSTALL_PREFIX/etc/restic/default.sh && restic_check.sh
# Email notification version. Make sure bin/cron_mail is in the above $PATH
#@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

View File

@@ -1,7 +1,9 @@
[Unit]
Description=Backup with restic to Backblaze B2
OnFailure=status-email-user@%n.service
Requires=nm-unmetered-connection.service
# Email on failure require special setup. See README.md
#OnFailure=status-email-user@%n.service
# Prevent backup on unmetered connection. Needs special setup. See README.md.
#Requires=nm-unmetered-connection.service
[Service]
Type=simple

View File

@@ -1,6 +1,5 @@
[Unit]
Description=Backup with restic on schedule
Requires=nm-unmetered-connection.service
[Timer]
OnCalendar=daily

View File

@@ -1,8 +1,10 @@
[Unit]
Description=Check restic backup Backblaze B2 for errors
OnFailure=status-email-user@%n.service
# Email on failure require special setup. See README.md
#OnFailure=status-email-user@%n.service
Conflicts=restic-backup.service
Requires=nm-unmetered-connection.service
# Prevent backup on unmetered connection. Needs special setup. See README.md.
#Requires=nm-unmetered-connection.service
[Service]
Type=simple

View File

@@ -1,6 +1,5 @@
[Unit]
Description=Check restic backup Backblaze B2 for errors on a schedule
Requires=nm-unmetered-connection.service
[Timer]
OnCalendar=monthly