Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eac8b97932 | ||
|
|
bb40afa67a | ||
|
|
cacfe58269 | ||
|
|
96e9bc23ab | ||
|
|
911f9f44d2 | ||
|
|
abac4b11ba | ||
|
|
cfaab7eb72 | ||
|
|
978ca2becb | ||
|
|
6cb6b41066 | ||
|
|
16302e5d35 | ||
|
|
aeec8991b6 | ||
|
|
0f5a8f0ca5 | ||
|
|
4a2ca821d7 | ||
|
|
3b08a42495 | ||
|
|
9ec3b1cb79 | ||
|
|
35c1c45352 | ||
|
|
f45b6298a4 | ||
|
|
9fa5074699 | ||
|
|
71d0e8c5c1 | ||
|
|
0d92cca32d | ||
|
|
30d18b8b0e | ||
|
|
9ff51d691a | ||
|
|
edaafdf10a | ||
|
|
07541cfaf2 | ||
|
|
399e7cd4ce | ||
|
|
0f3d39dfe1 | ||
|
|
f7c13f7290 |
25
CHANGELOG.md
25
CHANGELOG.md
@@ -6,7 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [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.
|
||||
|
||||
## [5.3.1] - 2022-02-12
|
||||
### Fixed
|
||||
- Launchagentdir make macro
|
||||
|
||||
## [5.3.0] - 2022-02-12
|
||||
### Added
|
||||
- Allow custom launchagent dir, used by Homebrew.
|
||||
|
||||
## [5.2.1] - 2022-02-11
|
||||
### Added
|
||||
- Homebrew Formula at [erikw/homebrew-tap](https://github.com/erikw/homebrew-tap). You can now install with `$ brew install erikw/tap/restic-automatic-backup-scheduler`!
|
||||
|
||||
### Fixed
|
||||
- Use default profile in LaunchAgent.
|
||||
|
||||
@@ -29,7 +48,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
|
||||
@@ -73,7 +92,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
|
||||
@@ -84,7 +103,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>
|
||||
43
Makefile
43
Makefile
@@ -18,7 +18,8 @@
|
||||
.PHONY: help clean uninstall \
|
||||
install-systemd install-cron \
|
||||
install-targets-script install-targets-conf install-targets-systemd \
|
||||
install-targets-cron \
|
||||
install-targets-cron install-targets-launchagent \
|
||||
install-targets-schedtask uninstall-targets-schedtask \
|
||||
activate-launchagent deactivate-launchagent
|
||||
|
||||
#### Macros ###################################################################
|
||||
@@ -33,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 '\
|
||||
@@ -42,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.
|
||||
@@ -53,12 +63,20 @@ INSTALL_PREFIX := $(PREFIX)
|
||||
# Where to install persistent configuration files. Used by Homebrew.
|
||||
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)/*))
|
||||
@@ -66,6 +84,7 @@ SRCS_CONF = $(wildcard $(DIR_CONF)/*)
|
||||
SRCS_SYSTEMD = $(wildcard $(DIR_SYSTEMD)/*)
|
||||
SRCS_CRON = $(wildcard $(DIR_CRON)/*)
|
||||
SRCS_LAUNCHAGENT= $(wildcard $(DIR_LAUNCHAGENT)/*)
|
||||
SRCS_SCHEDTASK = $(wildcard $(DIR_SCHEDTASK)/*)
|
||||
|
||||
# Local build directory. Sources will be copied here,
|
||||
# modified and then installed from this directory.
|
||||
@@ -75,6 +94,7 @@ 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))
|
||||
@@ -82,13 +102,14 @@ BUILD_SRCS_CONF = $(addprefix $(BUILD_DIR)/, $(SRCS_CONF))
|
||||
BUILD_SRCS_SYSTEMD = $(addprefix $(BUILD_DIR)/, $(SRCS_SYSTEMD))
|
||||
BUILD_SRCS_CRON = $(addprefix $(BUILD_DIR)/, $(SRCS_CRON))
|
||||
BUILD_SRCS_LAUNCHAGENT = $(addprefix $(BUILD_DIR)/, $(SRCS_LAUNCHAGENT))
|
||||
BUILD_SRCS_SCHEDTASK = $(addprefix $(BUILD_DIR)/, $(SRCS_SCHEDTASK))
|
||||
|
||||
# Destination directories
|
||||
DEST_DIR_SCRIPT = $(PREFIX)/$(DIR_SCRIPT)
|
||||
DEST_DIR_CONF = $(SYSCONFDIR)/$(DIR_CONF)
|
||||
DEST_DIR_SYSTEMD = $(PREFIX)/$(DIR_SYSTEMD)
|
||||
DEST_DIR_CRON = $(PREFIX)/$(DIR_CRON)
|
||||
DEST_DIR_LAUNCHAGENT= $(HOME)/$(DIR_LAUNCHAGENT)
|
||||
DEST_DIR_LAUNCHAGENT= $(LAUNCHAGENTDIR)/$(DIR_LAUNCHAGENT)
|
||||
DEST_DIR_MAC_LOG = $(HOME)/Library/Logs/restic
|
||||
|
||||
# Destination file targets.
|
||||
@@ -96,7 +117,7 @@ DEST_TARGS_SCRIPT = $(addprefix $(PREFIX)/, $(SRCS_SCRIPT))
|
||||
DEST_TARGS_CONF = $(addprefix $(SYSCONFDIR)/, $(SRCS_CONF))
|
||||
DEST_TARGS_SYSTEMD = $(addprefix $(PREFIX)/, $(SRCS_SYSTEMD))
|
||||
DEST_TARGS_CRON = $(addprefix $(PREFIX)/, $(SRCS_CRON))
|
||||
DEST_TARGS_LAUNCHAGENT = $(addprefix $(HOME)/, $(SRCS_LAUNCHAGENT))
|
||||
DEST_TARGS_LAUNCHAGENT = $(addprefix $(LAUNCHAGENTDIR)/, $(SRCS_LAUNCHAGENT))
|
||||
|
||||
INSTALLED_FILES = $(DEST_TARGS_SCRIPT) $(DEST_TARGS_CONF) \
|
||||
$(DEST_TARGS_SYSTEMD) $(DEST_TARGS_CRON) \
|
||||
@@ -113,7 +134,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; \
|
||||
@@ -134,6 +155,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 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)
|
||||
@@ -142,6 +170,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_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)/% : %
|
||||
|
||||
112
README.md
112
README.md
@@ -1,27 +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-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/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-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.
|
||||
|
||||
@@ -49,6 +52,7 @@ Tip: use the Section icon in the top left of this document to navigate the secti
|
||||
Depending on your system, the setup will look different. Choose one of
|
||||
* <img height="16" width="16" src="https://unpkg.com/simple-icons@v6/icons/linux.svg" /> [Linux + Systemd](#setup-linux-systemd)
|
||||
* <img height="16" width="16" src="https://unpkg.com/simple-icons@v6/icons/apple.svg" /> [macOS + LaunchAgent](#setup-macos-launchagent)
|
||||
* <img height="16" width="16" src="https://unpkg.com/simple-icons@v6/icons/windows.svg" /> [Windows + ScheduledTask](#setup-windows-scheduledtask)
|
||||
* <img height="16" width="16" src="https://unpkg.com/simple-icons@v6/icons/clockify.svg" /> [Cron](#setup-cron) - for any system having a cron daemon. Tested on FreeBSD and macOS.
|
||||
|
||||
## Setup Linux Systemd
|
||||
@@ -100,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
|
||||
````
|
||||
|
||||
@@ -116,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
|
||||
@@ -262,9 +266,22 @@ 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
|
||||
With Homebrew you can easily install this project from the [erikw/homebrew-tap](https://github.com/erikw/homebrew-tap):
|
||||
```console
|
||||
$ brew install erikw/tap/restic-automatic-backup-scheduler
|
||||
```
|
||||
|
||||
Then control the service with homebrew:
|
||||
```console
|
||||
$ brew services start restic-automatic-backup-scheduler
|
||||
$ brew services restart restic-automatic-backup-scheduler
|
||||
$ brew services stop 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`
|
||||
* install everything to `/usr/local` and run restic as your own user, not root
|
||||
@@ -274,24 +291,66 @@ LaunchAgent is the modern service scheduler in in macOS that uses [Launchd](http
|
||||
```
|
||||
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
|
||||
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:
|
||||
```console
|
||||
powershell> scoop install restic make git
|
||||
```
|
||||
1. In a non-privileged PowerShell, start git-bash and clone this repo
|
||||
```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)
|
||||
```
|
||||
1. Install scripts, conf and the ScheduledTask
|
||||
```console
|
||||
git-bash$ make install-schedtask
|
||||
```
|
||||
1. Edit configs and initialize repo according to *TL;DR* section above
|
||||
```console
|
||||
git-bash$ vim /etc/restic/*
|
||||
git-bash$ source /etc/restic/default.env.sh
|
||||
git-bash$ restic init
|
||||
git-bash$ restic_backup.sh
|
||||
```
|
||||
Note that you should use cygwin/git-bash paths e.g. in `default.env.sh` you can have
|
||||
```bash
|
||||
export RESTIC_BACKUP_PATHS='/c/Users/<username>/My Documents'
|
||||
```
|
||||
1. Inspect the installed tasks and make a test run
|
||||
1. Open the app "Task Scheduler" (`taskschd.msc`)
|
||||
1. Go to the local "Task Scheduler Library"
|
||||
1. Right click on one of the newly installed tasks e.g. `restic_backup` and click "run".
|
||||
- If the tasks are not there, maybe you opended it up before `make install-schedtask`: just close and start it again to refresh.
|
||||
1. Now a git-bash window should open running `restic_backup.sh`, and the next time the configured schedule hits!
|
||||
1. With `taskschd.msc` you can easily start, stop, delete and configure the scheduled tasks to your liking.
|
||||
|
||||
|
||||
After installing, you can control your backups through `tasksched.msc`:
|
||||
<a href="img/tasksched.png" title="Windows Task Scheduler"><img src="img/tasksched.png" width="512" alt="Windows Task Schedulder"></a>
|
||||
|
||||
|
||||
## Setup Cron
|
||||
If you want to run an all-classic cron job instead, do like this:
|
||||
|
||||
@@ -310,7 +369,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
|
||||
@@ -331,4 +390,5 @@ To make a new release:
|
||||
$ git tag vX.Y.Z
|
||||
$ git push && git push --tags
|
||||
```
|
||||
1. Test and update the AUR [PKGBUILD](https://aur.archlinux.org/packages/restic-systemd-automatic-backup/) if needed.
|
||||
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).
|
||||
|
||||
19
ScheduledTask/install.ps1
Normal file
19
ScheduledTask/install.ps1
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env pwsh
|
||||
# Install restic scheduled tasks.
|
||||
# Test run the installed actions by
|
||||
# 1. open the app "Task Scheduler" (taskschd.msc)
|
||||
# 2. go to the local "Task Scheduler Library"
|
||||
# 3. right click on the new tasks and click "run".
|
||||
# Reference: https://blogs.technet.microsoft.com/heyscriptingguy/2015/01/13/use-powershell-to-create-scheduled-tasks/
|
||||
# Reference: https://www.davidjnice.com/cygwin_scheduled_tasks.html
|
||||
|
||||
|
||||
# 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"'
|
||||
$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"'
|
||||
$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
|
||||
@@ -57,6 +57,10 @@ for backup_path in "${backup_paths[@]}"; do
|
||||
fi
|
||||
done
|
||||
|
||||
# --one-file-system is not supportd on Windows (=msys).
|
||||
FS_ARG=
|
||||
test "$OSTYPE" = msys || FS_ARG=--one-file-system
|
||||
|
||||
# NOTE start all commands in background and wait for them to finish.
|
||||
# Reason: bash ignores any signals while child process is executing and thus the trap exit hook is not triggered.
|
||||
# However if put in subprocesses, wait(1) waits until the process finishes OR signal is received.
|
||||
@@ -72,7 +76,7 @@ wait $!
|
||||
# --tag lets us reference these backups later when doing restic-forget.
|
||||
restic backup \
|
||||
--verbose="$RESTIC_VERBOSITY_LEVEL" \
|
||||
--one-file-system \
|
||||
$FS_ARG \
|
||||
--tag "$RESTIC_BACKUP_TAG" \
|
||||
--option b2.connections="$B2_CONNECTIONS" \
|
||||
"${exclusion_args[@]}" \
|
||||
|
||||
BIN
img/tasksched.png
Normal file
BIN
img/tasksched.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 136 KiB |
Reference in New Issue
Block a user