1 Commits

Author SHA1 Message Date
Erik Westrup
a94c6f7df3 Modified: CHANGELOG.md 2022-02-12 20:48:01 +01:00
15 changed files with 63 additions and 138 deletions

View File

@@ -6,14 +6,6 @@ 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.
@@ -52,7 +44,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-automatic-backup-scheduler) 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-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@<profile>.timer
@@ -96,7 +88,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-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.
- **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.
- `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
@@ -107,7 +99,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-automatic-backup-scheduler/issues/40))
- $(make install) now works for the *.template files ([#40](https://github.com/erikw/restic-systemd-automatic-backup/issues/40))
## [1.0.0] - 2021-12-02
It's time to call this a proper major version!

View File

@@ -1,4 +1,5 @@
restic-automatic-backup-scheduler - Automatic restic backup using Backblaze B2 storage, Linux systemd timers, macOS LaunchAgent, Windows ScheduledTask or simply cron
restic-systemd-automatic-backup - My restic backup solution using Backblaze B2 storage, systemd timers (or cron) and email notifications on failure.
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-scheduler</string>
<string>com.github.erikw.restic-automatic-backup</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 uninstall-targets-schedtask \
install-targets-schedtask \
activate-launchagent deactivate-launchagent
#### Macros ###################################################################
@@ -34,15 +34,6 @@ 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 '\
@@ -52,7 +43,7 @@ MKDIR_PARENTS=sh -c '\
# LaunchAgent names.
UID := $(shell id -u)
LAUNCHAGENT = com.github.erikw.restic-automatic-backup-scheduler
LAUNCHAGENT = com.github.erikw.restic-automatic-backup
LAUNCHAGENT_TARGET = gui/$(UID)/$(LAUNCHAGENT)
# What to substitute $INSTALL_PREFIX in sources to.
@@ -66,42 +57,29 @@ 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 \
%systemd-email \
%nm-unmetered-connection.sh \
, $(wildcard $(DIR_SCRIPT)/*))
SRCS_SCRIPT = $(filter-out %cron_mail, $(wildcard $(DIR_SCRIPT)/*))
SRCS_CONF = $(wildcard $(DIR_CONF)/*)
SRCS_SYSTEMD = $(filter-out \
%status-email-user@.service \
%nm-unmetered-connection.service \
, $(wildcard $(DIR_SYSTEMD)/*))
SRCS_SYSTEMD = $(wildcard $(DIR_SYSTEMD)/*)
SRCS_CRON = $(wildcard $(DIR_CRON)/*)
SRCS_LAUNCHAGENT= $(wildcard $(DIR_LAUNCHAGENT)/*)
SRCS_SCHEDTASK = $(wildcard $(DIR_SCHEDTASK)/*)
SRCS_SCHEDTASK = install_restic_scheduledtask.ps1
# 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))
@@ -141,7 +119,7 @@ clean:
$(RM) -r $(BUILD_DIR)
# target: uninstall - Uninstall ALL installed (including config) files.
uninstall: uninstall-schedtask
uninstall:
@for file in $(INSTALLED_FILES); do \
echo $(RM) $$file; \
$(RM) $$file; \
@@ -162,13 +140,10 @@ 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 ScheduledTasks
# target: install-schedtask - Install Windows ScheduledTask
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)
@@ -177,11 +152,8 @@ 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_DIR_SCHEDTASK)/$(SCHEDTASK_INSTALL)
test $(CUR_OS) != Windows || ./$<
uninstall-targets-schedtask: $(BUILD_DIR_SCHEDTASK)/$(SCHEDTASK_UNINSTALL)
test $(CUR_OS) != Windows || ./$<
install-targets-schedtask: $(BUILD_SRCS_SCHEDTASK)
./$<
# Copies sources to build directory & replace "$INSTALL_PREFIX".
$(BUILD_DIR)/% : %

View File

@@ -1,30 +1,28 @@
# Automatic restic backups using systemd services and timers
*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)](#)
[![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)](#)
<br>
[![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/)
[![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/)
[![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-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)
[![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)
[![License](https://img.shields.io/badge/license-BSD--3-blue)](LICENSE)
[![OSS Lifecycle](https://img.shields.io/osslifecycle/erikw/restic-automatic-backup-scheduler)](https://github.com/Netflix/osstracker)
[![OSS Lifecycle](https://img.shields.io/osslifecycle/erikw/restic-systemd-automatic-backup)](https://github.com/Netflix/osstracker)
<br>
[![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"/>
[![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"/>
</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 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!
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.
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.
@@ -104,7 +102,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-automatic-backup-scheduler.git && cd $(basename "$_" .git)
$ git clone https://github.com/erikw/restic-systemd-automatic-backup.git && cd $(basename "$_" .git)
$ sudo make install-systemd
````
@@ -120,9 +118,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-automatic-backup-scheduler](https://aur.archlinux.org/packages/restic-automatic-backup-scheduler/) e.g. with `yay(1)`:
Arch Linux users can install the aur package [restic-systemd-automatic-backup](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/) e.g.:
```console
$ yay -S restic-automatic-backup-scheduler
$ yaourt -S restic-systemd-automatic-backup
````
#### 1. Create Backblaze B2 Account, Bucket and keys
@@ -237,10 +235,7 @@ 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.
Now edit `restic-backup.service` and `status-email-user.service` to call this service failure.
```
OnFailure=status-email-user@%n.service
```
As you maybe noticed already before, `restic-backup.service` is configured to start `status-email-user.service` on failure.
#### 9. Optional: automated backup checks
@@ -252,23 +247,7 @@ There is companion scripts, service and timer (`*check*`) to restic-backup.sh th
$ sudo systemctl enable --now restic-check@default.timer
````
#### 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
#### 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:
@@ -285,6 +264,7 @@ 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
@@ -300,12 +280,6 @@ $ 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`
@@ -316,28 +290,26 @@ $ brew services start 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-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
$ 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
```
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-scheduler
$ launchctl bootout gui/$UID/com.github.erikw.restic-automatic-backup-scheduler
$ launchctl disable gui/$UID/com.github.erikw.restic-automatic-backup
$ launchctl bootout gui/$UID/com.github.erikw.restic-automatic-backup
```
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:
@@ -348,7 +320,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-automatic-backup-scheduler.git && cd $(basename "$_" .git)
git-bash$ git clone https://github.com/erikw/restic-systemd-automatic-backup.git && cd $(basename "$_" .git)
```
1. Install scripts, conf and the ScheduledTask
```console
@@ -396,7 +368,7 @@ $ sudo make uninstall
# Variations
A list of variations of this setup:
* Using `--files-from` [#44](https://github.com/erikw/restic-automatic-backup-scheduler/issues/44)
* Using `--files-from` [#44](https://github.com/erikw/restic-systemd-automatic-backup/issues/44)
# Development
* To not mess up your real installation when changing the `Makefile` simply install to a `$PREFIX` like
@@ -417,5 +389,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-automatic-backup-scheduler/).
1. Update version in the AUR [PKGBUILD](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/).
1. Update version in the Homebrew [Formula](https://github.com/erikw/homebrew-tap/blob/main/Formula/restic-automatic-backup-scheduler.rb).

View File

@@ -1,5 +0,0 @@
#!/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 Normal file → Executable file
View File

View File

@@ -1,19 +1,19 @@
#!/usr/bin/env bash
# Requires Gnome NetworkManager
#!/bin/bash
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 Normal file → Executable file
View File

View File

@@ -4,10 +4,5 @@ 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 && 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
@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

@@ -9,11 +9,11 @@
# Install 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"'
$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"'
$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 "$(scoop prefix 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 'C:\Program Files\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

@@ -1,9 +1,7 @@
[Unit]
Description=Backup with restic to Backblaze B2
# 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
OnFailure=status-email-user@%n.service
Requires=nm-unmetered-connection.service
[Service]
Type=simple

View File

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

View File

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

View File

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