Skip to content

Commit 5120bf3

Browse files
committed
Merge remote-tracking branch 'gaerfield/master'
2 parents c99e0d5 + c918f79 commit 5120bf3

26 files changed

+166
-68
lines changed

Makefile

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
PREFIX := /usr/local
2-
2+
SYSTEMD_HOME := /lib/systemd/system
33
all:
44

55
install:
6+
install -d $(DESTDIR)/etc/cron.d
7+
install -d $(DESTDIR)/etc/cron.daily
8+
install -d $(DESTDIR)/etc/cron.hourly
9+
install -d $(DESTDIR)/etc/cron.weekly
10+
install -d $(DESTDIR)/etc/cron.monthly
11+
install -m 0644 etc/zfs-auto-snapshot.cron.frequent $(DESTDIR)/etc/cron.d/zfs-auto-snapshot
12+
install etc/zfs-auto-snapshot.cron.hourly $(DESTDIR)/etc/cron.hourly/zfs-auto-snapshot
13+
install etc/zfs-auto-snapshot.cron.daily $(DESTDIR)/etc/cron.daily/zfs-auto-snapshot
14+
install etc/zfs-auto-snapshot.cron.weekly $(DESTDIR)/etc/cron.weekly/zfs-auto-snapshot
15+
install etc/zfs-auto-snapshot.cron.monthly $(DESTDIR)/etc/cron.monthly/zfs-auto-snapshot
16+
install -d $(DESTDIR)$(PREFIX)/share/man/man8
17+
install src/zfs-auto-snapshot.8 $(DESTDIR)$(PREFIX)/share/man/man8/zfs-auto-snapshot.8
18+
install -d $(DESTDIR)$(PREFIX)/sbin
19+
install src/zfs-auto-snapshot.sh $(DESTDIR)$(PREFIX)/sbin/zfs-auto-snapshot
20+
21+
systemd:
22+
install -d $(DESTDIR)$(PREFIX)$(SYSTEMD_HOME)
23+
install timers/zfs-auto-snapshot-frequent.service $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-frequent.service
24+
install timers/zfs-auto-snapshot-frequent.timer $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-frequent.timer
25+
install timers/zfs-auto-snapshot-hourly.service $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-hourly.service
26+
install timers/zfs-auto-snapshot-hourly.timer $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-hourly.timer
27+
install timers/zfs-auto-snapshot-daily.service $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-daily.service
28+
install timers/zfs-auto-snapshot-daily.timer $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-daily.timer
29+
install timers/zfs-auto-snapshot-weekly.service $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-weekly.service
30+
install timers/zfs-auto-snapshot-weekly.timer $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-weekly.timer
31+
install timers/zfs-auto-snapshot-monthly.service $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-monthly.service
32+
install timers/zfs-auto-snapshot-monthly.timer $(DESTDIR)/$(SYSTEMD_HOME)/zfs-auto-snapshot-monthly.timer
33+
install timers/zfs-auto-snapshot.target $(DESTDIR)$(PREFIX)$(SYSTEMD_HOME)/zfs-auto-snapshot.target
634
install -d $(DESTDIR)$(PREFIX)/share/man/man8
735
install src/zfs-auto-snapshot.8 $(DESTDIR)$(PREFIX)/share/man/man8/zfs-auto-snapshot.8
836
install -d $(DESTDIR)$(PREFIX)/sbin
937
install src/zfs-auto-snapshot.sh $(DESTDIR)$(PREFIX)/sbin/zfs-auto-snapshot
10-
install -d $(DESTDIR)$(PREFIX)/lib/systemd/system
11-
install timers/zfs-auto-daily.service $(DESTDIR)$(PREFIX)/lib/systemd/system/zfs-auto-daily.service
12-
install timers/zfs-auto-daily.timer $(DESTDIR)$(PREFIX)/lib/systemd/system/zfs-auto-daily.timer
13-
install timers/zfs-auto-hourly.service $(DESTDIR)$(PREFIX)/lib/systemd/system/zfs-auto-hourly.service
14-
install timers/zfs-auto-hourly.timer $(DESTDIR)$(PREFIX)/lib/systemd/system/zfs-auto-hourly.timer
15-
install timers/zfs-auto-weekly.service $(DESTDIR)$(PREFIX)/lib/systemd/system/zfs-auto-weekly.service
16-
install timers/zfs-auto-weekly.timer $(DESTDIR)$(PREFIX)/lib/systemd/system/zfs-auto-weekly.timer
17-
install timers/zfs-auto.target $(DESTDIR)$(PREFIX)/lib/systemd/system/zfs-auto.target
38+
systemctl enable zfs-auto-snapshot.target
39+
systemctl daemon-reload
40+
systemctl start zfs-auto-snapshot.target

README.md

100644100755
Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,50 @@
33
An alternative implementation of the zfs-auto-snapshot service for Linux
44
that is compatible with [ZFS on Linux](http://zfsonlinux.org/).
55

6-
My fork removes the automatic installation of cron entries that do things
7-
the user may not desire. This fork only installs the script and leaves manual
8-
crontab/systemd-timer configuration up to the user.
6+
Automatically create, rotate, and destroy periodic ZFS snapshots. This is
7+
the utility that creates the:
98

10-
This program is a posixly correct bourne shell script. It depends only on
11-
the zfs utilities, and can run in the dash shell.
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
1214

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`).
1322

14-
Installation:
15-
-------------
1623
```
17-
git clone https://github.com/ajhaydock/zfs-auto-snapshot.git
18-
cd zfs-auto-snapshot
19-
sudo make install
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
2028
```
2129

30+
## Installation using systemd
2231

23-
Scheduling:
24-
-------------
2532
I recommend scheduling this using [systemd timers](https://wiki.archlinux.org/index.php/Systemd/Timers).
2633

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

2936
You can enable the timers as follows:
37+
3038
```
31-
sudo systemctl daemon-reload
32-
sudo systemctl start zfs-auto.target && sudo systemctl enable zfs-auto.target
39+
wget https://github.com/gaerfield/zfs-auto-snapshot/archive/master.zip
40+
unzip master.zip
41+
cd zfs-auto-snapshot-master
42+
make systemd
3343
```
3444

3545
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.
3646

47+
```
48+
cp /lib/systemd/system/zfs-auto-snapshot-frequent.timer /usr/systemd/system/
49+
cp /lib/systemd/system/zfs-auto-snapshot-frequent.service /usr/systemd/system/
3750

3851
Managing Which Pools to Snapshot
3952
-------------

etc/zfs-auto-snapshot.cron.daily

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
exec zfs-auto-snapshot --quiet --syslog --label=daily --keep=31 //
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PATH="/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
2+
3+
*/15 * * * * root zfs-auto-snapshot --quiet --syslog --label=frequent --keep=4 //

etc/zfs-auto-snapshot.cron.hourly

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
exec zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 //

etc/zfs-auto-snapshot.cron.monthly

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
exec zfs-auto-snapshot --quiet --syslog --label=monthly --keep=12 //

etc/zfs-auto-snapshot.cron.weekly

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
exec zfs-auto-snapshot --quiet --syslog --label=weekly --keep=8 //

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 ': ' \

timers/zfs-auto-daily.service

Lines changed: 0 additions & 5 deletions
This file was deleted.

timers/zfs-auto-daily.timer

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)