Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add systemd branch #61

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
01ecb5e
No longer automatically add cron entries
alexhaydock Sep 25, 2016
0b42bf8
Readme updates
alexhaydock Sep 25, 2016
9f5c966
Recommend systemd timers instead of cron
alexhaydock Sep 25, 2016
98ac4fa
Update README.md
alexhaydock Sep 26, 2016
471f4f8
Manually specify OnCalendar times, rather than trusting systemd's dis…
alexhaydock Sep 26, 2016
03eac33
Timer error fix
alexhaydock Sep 26, 2016
a9b7a9e
More experimentation
alexhaydock Sep 26, 2016
3dfa16d
Tweaks
alexhaydock Sep 26, 2016
fb55521
Snapshot tweaking
alexhaydock Sep 26, 2016
d7603c4
Added info about disabling for certain zpools
alexhaydock Oct 10, 2016
2d11052
Automatically install systemd timers with Makefile
alexhaydock Dec 5, 2016
b0a6a87
Fix broken README
alexhaydock Jan 9, 2017
ad9a32d
systemd-timers instead of crons
gaerfield Feb 19, 2017
29be1c3
installation steps added
gaerfield Feb 19, 2017
054866d
markdown corrected
gaerfield Feb 19, 2017
3b0b821
renamed README to README.md instead of creating new README-file
gaerfield Feb 19, 2017
d5a611e
list-syntax corrected
gaerfield Feb 19, 2017
110e27e
RandomizedDelaySec added to make it unlikely that they fire simultane…
gaerfield Feb 19, 2017
ccbeca9
more Details in README and changed the install folder for the scripts…
gaerfield Feb 19, 2017
84050b0
correction in README
gaerfield Feb 19, 2017
1255756
Makefile should enable timers
gaerfield Feb 19, 2017
1104cba
Merge remote-tracking branch 'upstream/master'
jakelee8 Feb 19, 2017
c918f79
removed explicit script-path from systemd-services
gaerfield Feb 19, 2017
91b91c3
Install systemd units to /usr/local/lib/systemd/system/ by default
jakelee8 Feb 19, 2017
c99e0d5
Replace individually installed systemd units with zfs-auto.target
jakelee8 Feb 19, 2017
5120bf3
Merge remote-tracking branch 'gaerfield/master'
jakelee8 Feb 19, 2017
7f6178e
Clean up README.md and comments
jakelee8 Feb 19, 2017
056f9cd
Fix bad merge of zfs-auto-snapshot.sh
jakelee8 Feb 19, 2017
0378234
Auto snapshot timers are statically configured
jakelee8 Feb 19, 2017
25a4730
Remove unused etc files in systemd branch
jakelee8 Feb 19, 2017
5463d65
Update README.md with systemd branch instructions
jakelee8 Feb 19, 2017
95ff0cd
Fix permissions on install
jakelee8 Feb 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
PREFIX := /usr/local
SYSTEMD_HOME := $(PREFIX)/lib/systemd/system

all:
.PHONY: all

install:
install -d $(DESTDIR)/etc/cron.d
install -d $(DESTDIR)/etc/cron.daily
install -d $(DESTDIR)/etc/cron.hourly
install -d $(DESTDIR)/etc/cron.weekly
install -d $(DESTDIR)/etc/cron.monthly
install -m 0644 etc/zfs-auto-snapshot.cron.frequent $(DESTDIR)/etc/cron.d/zfs-auto-snapshot
install etc/zfs-auto-snapshot.cron.hourly $(DESTDIR)/etc/cron.hourly/zfs-auto-snapshot
install etc/zfs-auto-snapshot.cron.daily $(DESTDIR)/etc/cron.daily/zfs-auto-snapshot
install etc/zfs-auto-snapshot.cron.weekly $(DESTDIR)/etc/cron.weekly/zfs-auto-snapshot
install etc/zfs-auto-snapshot.cron.monthly $(DESTDIR)/etc/cron.monthly/zfs-auto-snapshot
install -d $(DESTDIR)$(PREFIX)/share/man/man8
install src/zfs-auto-snapshot.8 $(DESTDIR)$(PREFIX)/share/man/man8/zfs-auto-snapshot.8
install -d $(DESTDIR)$(PREFIX)/sbin
install src/zfs-auto-snapshot.sh $(DESTDIR)$(PREFIX)/sbin/zfs-auto-snapshot
install -m 0755 -d $(DESTDIR)$(PREFIX)/sbin $(DESTDIR)$(PREFIX)/share/man/man8
install -m 0755 src/zfs-auto-snapshot.sh $(DESTDIR)$(PREFIX)/sbin/zfs-auto-snapshot
install -m 0644 -t $(DESTDIR)$(PREFIX)/share/man/man8 src/zfs-auto-snapshot.8
install -m 0644 -t $(DESTDIR)$(SYSTEMD_HOME) \
timers/zfs-auto-snapshot-daily.service \
timers/zfs-auto-snapshot-daily.timer \
timers/zfs-auto-snapshot-frequent.service \
timers/zfs-auto-snapshot-frequent.timer \
timers/zfs-auto-snapshot-hourly.service \
timers/zfs-auto-snapshot-hourly.timer \
timers/zfs-auto-snapshot-monthly.service \
timers/zfs-auto-snapshot-monthly.timer \
timers/zfs-auto-snapshot-weekly.service \
timers/zfs-auto-snapshot-weekly.timer \
timers/zfs-auto-snapshot.target
.PHONY: install

enable:
systemctl enable --now zfs-auto-snapshot.target
.PHONY: enable
21 changes: 0 additions & 21 deletions README

This file was deleted.

88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# zfs-auto-snapshot

An alternative implementation of the zfs-auto-snapshot service for Linux
that is compatible with [ZFS on Linux](http://zfsonlinux.org/).

Automatically create, rotate, and destroy periodic ZFS snapshots. This is
the utility that creates the:

* @zfs-auto-snap_frequent,
* @zfs-auto-snap_hourly,
* @zfs-auto-snap_daily,
* @zfs-auto-snap_weekly, and
* @zfs-auto-snap_monthly

snapshots if it is installed.

This program is a posixly correct bourne shell script. It depends only on
the zfs utilities and cron, and can run in the dash shell (using the scripts
in `etc`).

## Installation using cron

```sh
wget https://github.com/zfsonlinux/zfs-auto-snapshot/archive/master.zip
unzip master.zip
cd zfs-auto-snapshot-master
make install
```

## Installation using systemd

```sh
wget https://github.com/zfsonlinux/zfs-auto-snapshot/archive/systemd.zip
unzip systemd.zip
cd zfs-auto-snapshot-systemd
make install enable
```

### Scheduling

See [systemd timers](https://wiki.archlinux.org/index.php/Systemd/Timers).

You can find some example `.timer` files in the `timers/` directory of this
repo. They will be installed when you run `make install` from the `systemd`
git branch.

If you wish to edit the timers, you will find them in the
`/usr/local/lib/systemd/system/` directory. Save the edited timers to
`/etc/systemd/system/` directory to override the default timers.

### Managing Which Pools to Snapshot

By default, the script will snapshot all pools automatically, unless they
have the `com.sun:auto-snapshot` property set to `false`.

To check the status of this property for all of your pools and datasets, run
the following command:

```sh
sudo zfs get com.sun:auto-snapshot
```

If you see an output like the following, then snapshots are enabled on this
pool:

```
NAME PROPERTY VALUE SOURCE
archive com.sun:auto-snapshot - -
```

To disable snapshots on this pool, issue the following command:

```sh
sudo zfs set com.sun:auto-snapshot=false archive
```

We can check with `zfs get` again, and this time our output should look like the following. If we see this, we know that snapshots have been disabled on this pool:

```
NAME PROPERTY VALUE SOURCE
archive com.sun:auto-snapshot false local
```

To disable snapshots on a single dataset, the command is very similar:

```sh
sudo zfs set com.sun:auto-snapshot=false archive/dataset
```
2 changes: 0 additions & 2 deletions etc/zfs-auto-snapshot.cron.daily

This file was deleted.

3 changes: 0 additions & 3 deletions etc/zfs-auto-snapshot.cron.frequent

This file was deleted.

2 changes: 0 additions & 2 deletions etc/zfs-auto-snapshot.cron.hourly

This file was deleted.

2 changes: 0 additions & 2 deletions etc/zfs-auto-snapshot.cron.monthly

This file was deleted.

2 changes: 0 additions & 2 deletions etc/zfs-auto-snapshot.cron.weekly

This file was deleted.

5 changes: 5 additions & 0 deletions timers/zfs-auto-snapshot-daily.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Unit]
Description=ZFS daily snapshot service

[Service]
ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=daily --keep=31 //
8 changes: 8 additions & 0 deletions timers/zfs-auto-snapshot-daily.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See systemd.timer and systemd.time manpages for details
[Unit]
Description=ZFS daily snapshot timer

[Timer]
OnCalendar=daily
Persistent=true
RandomizedDelaySec=600
4 changes: 4 additions & 0 deletions timers/zfs-auto-snapshot-frequent.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Description=ZFS frequent snapshot service

[Service]
ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=frequent --keep=4 //
8 changes: 8 additions & 0 deletions timers/zfs-auto-snapshot-frequent.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See systemd.timer and systemd.time manpages for details
[Unit]
Description=ZFS frequent snapshot timer

[Timer]
OnCalendar=*:0/15
Persistent=true
RandomizedDelaySec=60
5 changes: 5 additions & 0 deletions timers/zfs-auto-snapshot-hourly.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Unit]
Description=ZFS hourly snapshot service

[Service]
ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 //
8 changes: 8 additions & 0 deletions timers/zfs-auto-snapshot-hourly.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See systemd.timer and systemd.time manpages for details
[Unit]
Description=ZFS hourly snapshot timer

[Timer]
OnCalendar=hourly
Persistent=true
RandomizedDelaySec=59
4 changes: 4 additions & 0 deletions timers/zfs-auto-snapshot-monthly.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Description=ZFS monthly snapshot service

[Service]
ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=monthly --keep=12 //
8 changes: 8 additions & 0 deletions timers/zfs-auto-snapshot-monthly.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See systemd.timer and systemd.time manpages for details
[Unit]
Description=ZFS monthly snapshot timer

[Timer]
OnCalendar=monthly
Persistent=true
RandomizedDelaySec=600
5 changes: 5 additions & 0 deletions timers/zfs-auto-snapshot-weekly.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Unit]
Description=ZFS weekly snapshot service

[Service]
ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=weekly --keep=8 //
7 changes: 7 additions & 0 deletions timers/zfs-auto-snapshot-weekly.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Unit]
Description=ZFS weekly snapshot timer

[Timer]
OnCalendar=weekly
Persistent=true
RandomizedDelaySec=600
11 changes: 11 additions & 0 deletions timers/zfs-auto-snapshot.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See systemd.target and systemd.unit manpages for details
[Unit]
Description=Automatically create, rotate, and destroy periodic ZFS snapshots.
Requires=zfs-auto-snapshot-frequent.timer
Requires=zfs-auto-snapshot-daily.timer
Requires=zfs-auto-snapshot-hourly.timer
Requires=zfs-auto-snapshot-weekly.timer
Requires=zfs-auto-snapshot-monthly.timer

[Install]
WantedBy=timers.target