Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a94c6f7df3 |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -6,10 +6,6 @@ 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.
|
||||
@@ -48,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
|
||||
@@ -92,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
|
||||
@@ -103,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!
|
||||
|
||||
3
LICENSE
3
LICENSE
@@ -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.
|
||||
|
||||
@@ -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>
|
||||
35
Makefile
35
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 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,17 +57,12 @@ 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)/*))
|
||||
@@ -84,7 +70,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)/*)
|
||||
SRCS_SCHEDTASK = install_restic_scheduledtask.ps1
|
||||
|
||||
# Local build directory. Sources will be copied here,
|
||||
# modified and then installed from this directory.
|
||||
@@ -94,7 +80,6 @@ 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))
|
||||
@@ -134,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; \
|
||||
@@ -155,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)
|
||||
@@ -170,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)/% : %
|
||||
|
||||
55
README.md
55
README.md
@@ -1,30 +1,28 @@
|
||||
# Automatic restic backups using systemd services and timers
|
||||
*formerly named restic-systemd-automatic-backup*
|
||||
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
<br>
|
||||
[](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/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/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)
|
||||
[](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)
|
||||
[](LICENSE)
|
||||
[](https://github.com/Netflix/osstracker)
|
||||
[](https://github.com/Netflix/osstracker)
|
||||
<br>
|
||||
|
||||
[](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"/>
|
||||
[](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
|
||||
@@ -266,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
|
||||
@@ -291,20 +290,20 @@ $ 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-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.
|
||||
@@ -321,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
|
||||
@@ -369,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
|
||||
@@ -390,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).
|
||||
|
||||
@@ -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
|
||||
@@ -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."
|
||||
Reference in New Issue
Block a user