Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a8ca5a815 | ||
|
|
37e38b4cb5 | ||
|
|
8f734ccc69 | ||
|
|
56c4fca8f6 | ||
|
|
9449d78596 | ||
|
|
c50e66b48f | ||
|
|
c1edb2efe1 | ||
|
|
8275f708ea | ||
|
|
eac8b97932 | ||
|
|
bb40afa67a | ||
|
|
cacfe58269 | ||
|
|
96e9bc23ab | ||
|
|
911f9f44d2 | ||
|
|
abac4b11ba | ||
|
|
cfaab7eb72 | ||
|
|
978ca2becb | ||
|
|
6cb6b41066 | ||
|
|
16302e5d35 | ||
|
|
aeec8991b6 | ||
|
|
0f5a8f0ca5 | ||
|
|
4a2ca821d7 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -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!
|
||||
|
||||
3
LICENSE
3
LICENSE
@@ -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.
|
||||
|
||||
@@ -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>
|
||||
48
Makefile
48
Makefile
@@ -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)/% : %
|
||||
|
||||
86
README.md
86
README.md
@@ -1,28 +1,30 @@
|
||||
# Automatic restic backups using systemd services and timers
|
||||
[](#)
|
||||
[](#)
|
||||
*formerly named restic-systemd-automatic-backup*
|
||||
|
||||
[](#)
|
||||
[](#)
|
||||
<br>
|
||||
[](https://github.com/erikw/restic-systemd-automatic-backup/actions/workflows/linter.yml)
|
||||
[](https://github.com/erikw/restic-systemd-automatic-backup/tags)
|
||||
[](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/)
|
||||
[](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/)
|
||||
[](https://github.com/erikw/restic-automatic-backup-scheduler/actions/workflows/linter.yml)
|
||||
[](https://github.com/erikw/restic-automatic-backup-scheduler/tags)
|
||||
[](https://aur.archlinux.org/packages/restic-automatic-backup-scheduler/)
|
||||
[](https://aur.archlinux.org/packages/restic-automatic-backup-scheduler/)
|
||||
[](https://github.com/erikw/homebrew-tap)
|
||||
[](https://github.com/erikw/restic-systemd-automatic-backup/issues)
|
||||
[](https://github.com/erikw/restic-systemd-automatic-backup/issues?q=is%3Aissue+is%3Aclosed)
|
||||
[](https://github.com/erikw/restic-systemd-automatic-backup/pulls?q=is%3Apr+is%3Aclosed)
|
||||
[](https://github.com/erikw/restic-automatic-backup-scheduler/issues)
|
||||
[](https://github.com/erikw/restic-automatic-backup-scheduler/issues?q=is%3Aissue+is%3Aclosed)
|
||||
[](https://github.com/erikw/restic-automatic-backup-scheduler/pulls?q=is%3Apr+is%3Aclosed)
|
||||
[](LICENSE)
|
||||
[](https://github.com/Netflix/osstracker)
|
||||
[](https://github.com/Netflix/osstracker)
|
||||
<br>
|
||||
|
||||
[](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"/>
|
||||
[](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).
|
||||
|
||||
@@ -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."
|
||||
5
ScheduledTask/uninstall.ps1
Normal file
5
ScheduledTask/uninstall.ps1
Normal 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
0
bin/cron_mail
Executable file → Normal 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
0
bin/resticw
Executable file → Normal 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
[Unit]
|
||||
Description=Backup with restic on schedule
|
||||
Requires=nm-unmetered-connection.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
[Unit]
|
||||
Description=Check restic backup Backblaze B2 for errors on a schedule
|
||||
Requires=nm-unmetered-connection.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=monthly
|
||||
|
||||
Reference in New Issue
Block a user