Skip to content

Commit ba9d132

Browse files
add schedule documentation to README
1 parent 6ccb2b8 commit ba9d132

File tree

4 files changed

+168
-27
lines changed

4 files changed

+168
-27
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ifeq ($(UNAME),Darwin)
3737
TMP_MOUNT=${TMP_MOUNT_DARWIN}
3838
endif
3939

40-
.PHONY: all test test-ci build build-mac build-linux build-windows build-all coverage clean test-docker build-docker ramdisk passphrase rest-server nightly
40+
.PHONY: all test test-ci build build-mac build-linux build-windows build-all coverage clean test-docker build-docker ramdisk passphrase rest-server nightly toc
4141

4242
all: test build
4343

@@ -112,3 +112,8 @@ nightly:
112112
go install github.com/goreleaser/goreleaser
113113
go mod tidy
114114
goreleaser --snapshot --skip-publish --rm-dist
115+
116+
toc:
117+
go install github.com/ekalinin/github-markdown-toc.go
118+
go mod tidy
119+
cat README.md | github-markdown-toc.go --hide-footer

README.md

Lines changed: 158 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,34 @@ For the rest of the documentation, I'll be showing examples using the TOML file
3131

3232
# Table of Contents
3333

34-
* [resticprofile](#resticprofile)
35-
* [Requirements](#requirements)
36-
* [Installation (macOS, Linux & other unixes)](#installation-macos-linux--other-unixes)
37-
* [Installation for Windows using bash](#installation-for-windows-using-bash)
38-
* [Manual installation (Windows)](#manual-installation-windows)
39-
* [Upgrade](#upgrade)
40-
* [Using docker image](#using-docker-image)
41-
* [Please note:](#please-note)
42-
* [Configuration format](#configuration-format)
43-
* [Configuration examples](#configuration-examples)
44-
* [Configuration paths](#configuration-paths)
45-
* [macOS X](#macos-x)
46-
* [Other unixes (Linux and BSD)](#other-unixes-linux-and-bsd)
47-
* [Windows](#windows)
48-
* [Using resticprofile](#using-resticprofile)
49-
* [Command line reference](#command-line-reference)
50-
* [Minimum memory required](#minimum-memory-required)
51-
* [Scheduled backups](#scheduled-backups)
52-
* [Configuration file reference](#configuration-file-reference)
53-
* [Appendix](#appendix)
54-
* [Using resticprofile and systemd](#using-resticprofile-and-systemd)
55-
* [systemd calendars](#systemd-calendars)
56-
* [Configuring a systemd profile](#configuring-a-systemd-profile)
34+
* [resticprofile](#resticprofile)
35+
* [Table of Contents](#table-of-contents)
36+
* [Requirements](#requirements)
37+
* [Installation (macOS, Linux & other unixes)](#installation-macos-linux--other-unixes)
38+
* [Installation for Windows using bash](#installation-for-windows-using-bash)
39+
* [Manual installation (Windows)](#manual-installation-windows)
40+
* [Upgrade](#upgrade)
41+
* [Using docker image](#using-docker-image)
42+
* [Container host name](#container-host-name)
43+
* [Configuration format](#configuration-format)
44+
* [Configuration examples](#configuration-examples)
45+
* [Configuration paths](#configuration-paths)
46+
* [macOS X](#macos-x)
47+
* [Other unixes (Linux and BSD)](#other-unixes-linux-and-bsd)
48+
* [Windows](#windows)
49+
* [Using resticprofile](#using-resticprofile)
50+
* [Command line reference](#command-line-reference)
51+
* [Minimum memory required](#minimum-memory-required)
52+
* [Scheduled backups](#scheduled-backups)
53+
* [schedule\-type](#schedule-type)
54+
* [schedule](#schedule)
55+
* [Scheduling commands](#scheduling-commands)
56+
* [Configuration file reference](#configuration-file-reference)
57+
* [Appendix](#appendix)
58+
* [Using resticprofile and systemd](#using-resticprofile-and-systemd)
59+
* [systemd calendars](#systemd-calendars)
60+
* [Configuring a systemd profile](#configuring-a-systemd-profile)
61+
5762

5863
## Requirements
5964

@@ -133,7 +138,7 @@ You can list your profiles:
133138
$ docker run -it --rm -v $PWD/examples:/resticprofile creativeprojects/resticprofile profiles
134139
```
135140

136-
### Please note:
141+
### Container host name
137142

138143
Each time a container is started, it gets assigned a new random name. You should probably force a hostname to your container...
139144

@@ -519,10 +524,137 @@ It compares against `(total - used)` which is probably the best way to know how
519524

520525
## Scheduled backups
521526

522-
I'm working on a feature that is going to manage scheduled backups:
527+
resticprofile is capable of managing scheduled backups for you:
523528
- using **systemd** where available (Linux and various unixes)
524529
- using **launchd** on macOS X
525-
- using **Task Manager** on Windows
530+
- using **Task Scheduler** on Windows
531+
532+
Each profile can be scheduled independently (not groups yet). Two parameters are added on the profile:
533+
534+
```ini
535+
[profile]
536+
schedule = "*:00,30"
537+
schedule-type = "system"
538+
```
539+
540+
### schedule-type
541+
542+
`schedule-type` accepts two parameters: `system` or `user`. You can always run the schedule commands for a user schedule, but your backup will be running using your current user permissions on files. That's what you want if you're only saving your documents (or any other file inside your profile).
543+
544+
If you need to access some system or protected files, set the `schedule-type` to `system`. You will need to run resticprofile with `sudo` on unixes and with elevated prompt on Windows (please note on Windows resticprofile will ask you for elevated permissions if needed)
545+
546+
### schedule
547+
548+
The `schedule` parameter accepts many forms of input from the [systemd calendar event](https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events) type. This is by far the easiest to understand. It is the same format used to schedule on macOS and Windows.
549+
550+
The most general form is:
551+
```
552+
weekdays year-month-day hour:minute:second
553+
```
554+
555+
- use `*` to mean any
556+
- use `,` to separate multiple entries
557+
- use `..` for a range
558+
559+
**limitations**: divider (`/`), the `~` and timezones are not supported in macOS and Windows.
560+
561+
**macOS users**: please note the `year` and `second` fields have no effect on macOS. They don't make much sense anyway.
562+
563+
Here are a few examples (taken from the systemd documentation):
564+
565+
```
566+
Sat,Thu,Mon..Wed,Sat..Sun → Mon..Thu,Sat,Sun *-*-* 00:00:00
567+
Mon,Sun 12-*-* 2,1:23 → Mon,Sun 2012-*-* 01,02:23:00
568+
Wed *-1 → Wed *-*-01 00:00:00
569+
Wed..Wed,Wed *-1 → Wed *-*-01 00:00:00
570+
Wed, 17:48 → Wed *-*-* 17:48:00
571+
Wed..Sat,Tue 12-10-15 1:2:3 → Tue..Sat 2012-10-15 01:02:03
572+
*-*-7 0:0:0 → *-*-07 00:00:00
573+
10-15 → *-10-15 00:00:00
574+
monday *-12-* 17:00 → Mon *-12-* 17:00:00
575+
Mon,Fri *-*-3,1,2 *:30 → Mon,Fri *-*-01,02,03 *:30:00
576+
12,14,13,12:20,10,30 → *-*-* 12,13,14:10,20,30:00
577+
12..14:10,20,30 → *-*-* 12..14:10,20,30:00
578+
03-05 08:05 → *-03-05 08:05:00
579+
05:40 → *-*-* 05:40:00
580+
Sat,Sun 12-05 08:05 → Sat,Sun *-12-05 08:05:00
581+
Sat,Sun 08:05 → Sat,Sun *-*-* 08:05:00
582+
2003-03-05 05:40 → 2003-03-05 05:40:00
583+
2003-02..04-05 → 2003-02..04-05 00:00:00
584+
2003-03-05 → 2003-03-05 00:00:00
585+
03-05 → *-03-05 00:00:00
586+
hourly → *-*-* *:00:00
587+
daily → *-*-* 00:00:00
588+
monthly → *-*-01 00:00:00
589+
weekly → Mon *-*-* 00:00:00
590+
yearly → *-01-01 00:00:00
591+
annually → *-01-01 00:00:00
592+
```
593+
594+
The `schedule` can be a string or an array of string (to allow for multiple schedules)
595+
596+
Here's an example of a YAML configuration for Windows:
597+
598+
```yaml
599+
default:
600+
repository: "d:\\backup"
601+
password-file: key
602+
603+
self:
604+
inherit: default
605+
schedule:
606+
- "Mon..Fri *:00,15,30,45" # every 15 minutes on weekdays
607+
- "Sat,Sun 0,12:00" # twice a day on week-ends
608+
backup:
609+
source: "."
610+
```
611+
612+
### Scheduling commands
613+
614+
resticprofile accepts these internal commands:
615+
- schedule
616+
- unschedule
617+
- reschedule
618+
- status
619+
620+
All these commands need at least a name of a profile, that's where the schedule information is taken from.
621+
622+
Example of the schedule command under Windows (with git bash):
623+
624+
```
625+
$ resticprofile -c examples/windows.yaml -n self schedule
626+
2020/07/07 22:33:14 resticprofile 0.9.0 compiled with go1.13.4
627+
2020/07/07 22:33:14 using configuration file: examples/windows.yaml
628+
629+
Analyzing schedule 1/2
630+
========================
631+
Original form: Mon..Fri *:00,15,30,45
632+
Normalized form: Mon..Fri *-*-* *:00,15,30,45:00
633+
Next elapse: Tue Jul 7 22:45:00 BST 2020
634+
(in UTC): Tue Jul 7 21:45:00 UTC 2020
635+
From now: 11m45s left
636+
637+
Analyzing schedule 2/2
638+
========================
639+
Original form: Sat,Sun 0,12:00
640+
Normalized form: Sat,Sun *-*-* 00,12:00:00
641+
Next elapse: Sat Jul 11 00:00:00 BST 2020
642+
(in UTC): Fri Jul 10 23:00:00 UTC 2020
643+
From now: 73h26m45s left
644+
645+
2020/07/07 22:33:17 restarting resticprofile in elevated mode...
646+
2020/07/07 22:33:30 elevated user: scheduled job created
647+
```
648+
649+
To remove the schedule, use the `unschedule` command:
650+
651+
```
652+
$ resticprofile -c examples/windows.yaml -n self unschedule
653+
2020/07/07 22:36:39 resticprofile 0.9.0 compiled with go1.13.4
654+
2020/07/07 22:36:39 using configuration file: examples/windows.yaml
655+
2020/07/07 22:36:42 restarting resticprofile in elevated mode...
656+
2020/07/07 22:36:44 elevated user: scheduled job removed
657+
```
526658
527659
## Configuration file reference
528660

config/profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Profile struct {
2828
RunAfter []string `mapstructure:"run-after"`
2929
RunAfterFail []string `mapstructure:"run-after-fail"`
3030
Schedule []string `mapstructure:"schedule"`
31+
ScheduleType string `mapstructure:"schedule-type"`
3132
Environment map[string]string `mapstructure:"env"`
3233
Backup *BackupSection `mapstructure:"backup"`
3334
Retention *RetentionSection `mapstructure:"retention"`

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
1717
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
1818
github.com/adrg/xdg v0.2.1 h1:VSVdnH7cQ7V+B33qSJHTCRlNgra1607Q8PzEmnvb2Ic=
1919
github.com/adrg/xdg v0.2.1/go.mod h1:ZuOshBmzV4Ta+s23hdfFZnBsdzmoR3US0d7ErpqSbTQ=
20+
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
2021
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
22+
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
2123
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
2224
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
2325
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
@@ -420,6 +422,7 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
420422
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
421423
google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA=
422424
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
425+
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
423426
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
424427
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
425428
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=

0 commit comments

Comments
 (0)