Skip to content

Commit ad9a32d

Browse files
committed
systemd-timers instead of crons
1 parent 62f5f7d commit ad9a32d

13 files changed

+142
-7
lines changed

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,20 @@ install:
1717
install src/zfs-auto-snapshot.8 $(DESTDIR)$(PREFIX)/share/man/man8/zfs-auto-snapshot.8
1818
install -d $(DESTDIR)$(PREFIX)/sbin
1919
install src/zfs-auto-snapshot.sh $(DESTDIR)$(PREFIX)/sbin/zfs-auto-snapshot
20+
21+
systemd:
22+
install -d $(DESTDIR)/etc/systemd/system/
23+
install timers/zfs-auto-snapshot-frequent.service $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-frequent.service
24+
install timers/zfs-auto-snapshot-frequent.timer $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-frequent.timer
25+
install timers/zfs-auto-snapshot-hourly.service $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-hourly.service
26+
install timers/zfs-auto-snapshot-hourly.timer $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-hourly.timer
27+
install timers/zfs-auto-snapshot-daily.service $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-daily.service
28+
install timers/zfs-auto-snapshot-daily.timer $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-daily.timer
29+
install timers/zfs-auto-snapshot-weekly.service $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-weekly.service
30+
install timers/zfs-auto-snapshot-weekly.timer $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-weekly.timer
31+
install timers/zfs-auto-snapshot-monthly.service $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-monthly.service
32+
install timers/zfs-auto-snapshot-monthly.timer $(DESTDIR)/etc/systemd/system/zfs-auto-snapshot-monthly.timer
33+
install -d $(DESTDIR)$(PREFIX)/share/man/man8
34+
install src/zfs-auto-snapshot.8 $(DESTDIR)$(PREFIX)/share/man/man8/zfs-auto-snapshot.8
35+
install -d $(DESTDIR)$(PREFIX)/sbin
36+
install src/zfs-auto-snapshot.sh $(DESTDIR)$(PREFIX)/sbin/zfs-auto-snapshot

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# zfs-auto-snapshot
2+
3+
An alternative implementation of the zfs-auto-snapshot service for Linux
4+
that is compatible with zfs-linux and zfs-fuse.
5+
6+
Automatically create, rotate, and destroy periodic ZFS snapshots. This is
7+
the utility that creates the:
8+
9+
* @zfs-auto-snap_frequent,
10+
* @zfs-auto-snap_hourly,
11+
* @zfs-auto-snap_daily,
12+
* @zfs-auto-snap_weekly, and
13+
* @zfs-auto-snap_monthly
14+
15+
snapshots if it is installed.
16+
17+
## Installation using cron
18+
19+
This program is a posixly correct bourne shell script. It depends only on
20+
the zfs utilities and cron, and can run in the dash shell (using the scripts in
21+
`etc`).
22+
23+
```
24+
wget https://github.com/zfsonlinux/zfs-auto-snapshot/archive/master.zip
25+
unzip master.zip
26+
cd zfs-auto-snapshot-master
27+
make install
28+
```
29+
30+
## Installation using systemd
31+
32+
As suggested by [Brian Koopman][bkoop] this target uses [systemd-timers][dtim]
33+
instead of cron.
34+
35+
```
36+
wget https://github.com/gaerfield/zfs-auto-snapshot/archive/master.zip
37+
unzip master.zip
38+
cd zfs-auto-snapshot-master
39+
make systemd
40+
```
41+
42+
[bkoop]: https://briankoopman.com/zfs-automated-snapshots/
43+
[dtim]: https://wiki.archlinux.org/index.php/Systemd/Timers

src/zfs-auto-snapshot.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#
2121

2222
# Set the field separator to a literal tab and newline.
23-
IFS="
23+
IFS="
2424
"
2525

2626
# Set default program options.
@@ -74,7 +74,7 @@ print_usage ()
7474
-v, --verbose Print info messages.
7575
--destroy-only Only destroy older snapshots, do not create new ones.
7676
name Filesystem and volume names, or '//' for all ZFS datasets.
77-
"
77+
"
7878
}
7979

8080

@@ -174,7 +174,7 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
174174
else
175175
WARNING_COUNT=$(( $WARNING_COUNT + 1 ))
176176
continue
177-
fi
177+
fi
178178
fi
179179

180180
# Retain at most $opt_keep number of old snapshots of this filesystem,
@@ -191,7 +191,7 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
191191
KEEP=$(( $KEEP - 1 ))
192192
if [ "$KEEP" -le '0' ]
193193
then
194-
if do_run "zfs destroy -d $FLAGS '$jj'"
194+
if do_run "zfs destroy -d $FLAGS '$jj'"
195195
then
196196
DESTRUCTION_COUNT=$(( $DESTRUCTION_COUNT + 1 ))
197197
else
@@ -297,7 +297,7 @@ do
297297
shift 1
298298
;;
299299
(--sep)
300-
case "$2" in
300+
case "$2" in
301301
([[:alnum:]_.:\ -])
302302
:
303303
;;
@@ -345,7 +345,7 @@ if [ "$#" -eq '0' ]
345345
then
346346
print_log error "The filesystem argument list is empty."
347347
exit 133
348-
fi
348+
fi
349349

350350
# Count the number of times '//' appears on the command line.
351351
SLASHIES='0'
@@ -402,7 +402,7 @@ done
402402
ZPOOLS_SCRUBBING=$(echo "$ZPOOL_STATUS" | awk -F ': ' \
403403
'$1 ~ /^ *pool$/ { pool = $2 } ; \
404404
$1 ~ /^ *scan$/ && $2 ~ /scrub in progress/ { print pool }' \
405-
| sort )
405+
| sort )
406406

407407
# Get a list of pools that cannot do a snapshot.
408408
ZPOOLS_NOTREADY=$(echo "$ZPOOL_STATUS" | awk -F ': ' \
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Unit]
2+
Description=ZFS daily snapshot service
3+
4+
[Service]
5+
ExecStart=/usr/bin/zfs-auto-snapshot --quiet --syslog --label=daily --keep=31 //
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# See systemd.timers and systemd.time manpages for details
2+
[Unit]
3+
Description=ZFS daily snapshot timer
4+
5+
[Timer]
6+
OnCalendar=daily
7+
Persistent=true
8+
9+
[Install]
10+
WantedBy=timers.target
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Unit]
2+
Description=ZFS frequent snapshot service
3+
4+
[Service]
5+
ExecStart=/usr/bin/zfs-auto-snapshot --quiet --syslog --label=frequent --keep=4 //
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# See systemd.timers and systemd.time manpages for details
2+
[Unit]
3+
Description=ZFS frequent snapshot timer
4+
5+
[Timer]
6+
OnCalendar=*:0/15
7+
Persistent=true
8+
9+
[Install]
10+
WantedBy=timers.target
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Unit]
2+
Description=ZFS hourly snapshot service
3+
4+
[Service]
5+
ExecStart=/usr/bin/zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 //
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# See systemd.timers and systemd.time manpages for details
2+
[Unit]
3+
Description=ZFS hourly snapshot timer
4+
5+
[Timer]
6+
OnCalendar=hourly
7+
Persistent=true
8+
9+
[Install]
10+
WantedBy=timers.target
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Unit]
2+
Description=ZFS monthly snapshot service
3+
4+
[Service]
5+
ExecStart=/usr/bin/zfs-auto-snapshot --quiet --syslog --label=monthly --keep=12 //

0 commit comments

Comments
 (0)