diff --git a/Makefile b/Makefile index 4b02b40..7ad0293 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README b/README deleted file mode 100644 index dd3d6bc..0000000 --- a/README +++ /dev/null @@ -1,21 +0,0 @@ -zfs-auto-snapshot: - -An alternative implementation of the zfs-auto-snapshot service for Linux -that is compatible with zfs-linux and zfs-fuse. - -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. - - -Installation: -------------- - -wget https://github.com/zfsonlinux/zfs-auto-snapshot/archive/master.zip -unzip master.zip -cd zfs-auto-snapshot-master -make install diff --git a/README.md b/README.md new file mode 100644 index 0000000..9d20f7b --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/etc/zfs-auto-snapshot.cron.daily b/etc/zfs-auto-snapshot.cron.daily deleted file mode 100644 index fab4e7f..0000000 --- a/etc/zfs-auto-snapshot.cron.daily +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec zfs-auto-snapshot --quiet --syslog --label=daily --keep=31 // diff --git a/etc/zfs-auto-snapshot.cron.frequent b/etc/zfs-auto-snapshot.cron.frequent deleted file mode 100644 index e87f818..0000000 --- a/etc/zfs-auto-snapshot.cron.frequent +++ /dev/null @@ -1,3 +0,0 @@ -PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin" - -*/15 * * * * root zfs-auto-snapshot --quiet --syslog --label=frequent --keep=4 // diff --git a/etc/zfs-auto-snapshot.cron.hourly b/etc/zfs-auto-snapshot.cron.hourly deleted file mode 100644 index dc39e11..0000000 --- a/etc/zfs-auto-snapshot.cron.hourly +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 // diff --git a/etc/zfs-auto-snapshot.cron.monthly b/etc/zfs-auto-snapshot.cron.monthly deleted file mode 100644 index 27e2ead..0000000 --- a/etc/zfs-auto-snapshot.cron.monthly +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec zfs-auto-snapshot --quiet --syslog --label=monthly --keep=12 // diff --git a/etc/zfs-auto-snapshot.cron.weekly b/etc/zfs-auto-snapshot.cron.weekly deleted file mode 100644 index 6180e2b..0000000 --- a/etc/zfs-auto-snapshot.cron.weekly +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exec zfs-auto-snapshot --quiet --syslog --label=weekly --keep=8 // diff --git a/timers/zfs-auto-snapshot-daily.service b/timers/zfs-auto-snapshot-daily.service new file mode 100644 index 0000000..1c302e4 --- /dev/null +++ b/timers/zfs-auto-snapshot-daily.service @@ -0,0 +1,5 @@ +[Unit] +Description=ZFS daily snapshot service + +[Service] +ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=daily --keep=31 // diff --git a/timers/zfs-auto-snapshot-daily.timer b/timers/zfs-auto-snapshot-daily.timer new file mode 100644 index 0000000..e774bff --- /dev/null +++ b/timers/zfs-auto-snapshot-daily.timer @@ -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 diff --git a/timers/zfs-auto-snapshot-frequent.service b/timers/zfs-auto-snapshot-frequent.service new file mode 100644 index 0000000..4e09ba6 --- /dev/null +++ b/timers/zfs-auto-snapshot-frequent.service @@ -0,0 +1,4 @@ +Description=ZFS frequent snapshot service + +[Service] +ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=frequent --keep=4 // diff --git a/timers/zfs-auto-snapshot-frequent.timer b/timers/zfs-auto-snapshot-frequent.timer new file mode 100644 index 0000000..78d3df7 --- /dev/null +++ b/timers/zfs-auto-snapshot-frequent.timer @@ -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 diff --git a/timers/zfs-auto-snapshot-hourly.service b/timers/zfs-auto-snapshot-hourly.service new file mode 100644 index 0000000..1f26493 --- /dev/null +++ b/timers/zfs-auto-snapshot-hourly.service @@ -0,0 +1,5 @@ +[Unit] +Description=ZFS hourly snapshot service + +[Service] +ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 // diff --git a/timers/zfs-auto-snapshot-hourly.timer b/timers/zfs-auto-snapshot-hourly.timer new file mode 100644 index 0000000..9d7c177 --- /dev/null +++ b/timers/zfs-auto-snapshot-hourly.timer @@ -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 diff --git a/timers/zfs-auto-snapshot-monthly.service b/timers/zfs-auto-snapshot-monthly.service new file mode 100644 index 0000000..db34f11 --- /dev/null +++ b/timers/zfs-auto-snapshot-monthly.service @@ -0,0 +1,4 @@ +Description=ZFS monthly snapshot service + +[Service] +ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=monthly --keep=12 // diff --git a/timers/zfs-auto-snapshot-monthly.timer b/timers/zfs-auto-snapshot-monthly.timer new file mode 100644 index 0000000..46aecce --- /dev/null +++ b/timers/zfs-auto-snapshot-monthly.timer @@ -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 diff --git a/timers/zfs-auto-snapshot-weekly.service b/timers/zfs-auto-snapshot-weekly.service new file mode 100644 index 0000000..e41d26b --- /dev/null +++ b/timers/zfs-auto-snapshot-weekly.service @@ -0,0 +1,5 @@ +[Unit] +Description=ZFS weekly snapshot service + +[Service] +ExecStart=/usr/local/sbin/zfs-auto-snapshot --quiet --syslog --label=weekly --keep=8 // diff --git a/timers/zfs-auto-snapshot-weekly.timer b/timers/zfs-auto-snapshot-weekly.timer new file mode 100644 index 0000000..1ad94e2 --- /dev/null +++ b/timers/zfs-auto-snapshot-weekly.timer @@ -0,0 +1,7 @@ +[Unit] +Description=ZFS weekly snapshot timer + +[Timer] +OnCalendar=weekly +Persistent=true +RandomizedDelaySec=600 diff --git a/timers/zfs-auto-snapshot.target b/timers/zfs-auto-snapshot.target new file mode 100644 index 0000000..7565694 --- /dev/null +++ b/timers/zfs-auto-snapshot.target @@ -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