mirror of
https://github.com/zfsonlinux/zfs-auto-snapshot.git
synced 2025-08-16 07:38:12 +02:00
Compare commits
9 Commits
upstream/1
...
upstream/1
Author | SHA1 | Date | |
---|---|---|---|
cc9f1802ed | |||
d77af5a902 | |||
b5bf1149ca | |||
5fc395c2bb | |||
d99147db7a | |||
c8507a0da9 | |||
74359e51a7 | |||
afdae86271 | |||
4b7609791b |
10
Makefile
10
Makefile
@ -2,6 +2,14 @@ all:
|
|||||||
|
|
||||||
install:
|
install:
|
||||||
install -d $(DESTDIR)$(PREFIX)/etc/cron.d
|
install -d $(DESTDIR)$(PREFIX)/etc/cron.d
|
||||||
install etc/zfs-auto-snapshot.cron $(DESTDIR)$(PREFIX)/etc/cron.d/zfs-auto-snapshot
|
install -d $(DESTDIR)$(PREFIX)/etc/cron.daily
|
||||||
|
install -d $(DESTDIR)$(PREFIX)/etc/cron.hourly
|
||||||
|
install -d $(DESTDIR)$(PREFIX)/etc/cron.weekly
|
||||||
|
install -d $(DESTDIR)$(PREFIX)/etc/cron.monthly
|
||||||
|
install etc/zfs-auto-snapshot.cron.frequent $(DESTDIR)$(PREFIX)/etc/cron.d/zfs-auto-snapshot
|
||||||
|
install etc/zfs-auto-snapshot.cron.hourly $(DESTDIR)$(PREFIX)/etc/cron.hourly/zfs-auto-snapshot
|
||||||
|
install etc/zfs-auto-snapshot.cron.daily $(DESTDIR)$(PREFIX)/etc/cron.daily/zfs-auto-snapshot
|
||||||
|
install etc/zfs-auto-snapshot.cron.weekly $(DESTDIR)$(PREFIX)/etc/cron.weekly/zfs-auto-snapshot
|
||||||
|
install etc/zfs-auto-snapshot.cron.monthly $(DESTDIR)$(PREFIX)/etc/cron.monthly/zfs-auto-snapshot
|
||||||
install -d $(DESTDIR)$(PREFIX)/sbin
|
install -d $(DESTDIR)$(PREFIX)/sbin
|
||||||
install src/zfs-auto-snapshot.sh $(DESTDIR)$(PREFIX)/sbin/zfs-auto-snapshot
|
install src/zfs-auto-snapshot.sh $(DESTDIR)$(PREFIX)/sbin/zfs-auto-snapshot
|
||||||
|
10
README
10
README
@ -1,4 +1,12 @@
|
|||||||
An alternative implementation of the zfs-auto-snapshot service for Linux.
|
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
|
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.
|
the zfs utilities and cron, and can run in the dash shell.
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
|
||||||
|
|
||||||
*/15 * * * * root zfs-auto-snapshot -q -g --label=frequent --keep=4 //
|
|
||||||
@hourly root zfs-auto-snapshot -q -g --label=hourly --keep=24 //
|
|
||||||
@daily root zfs-auto-snapshot -q -g --label=daily --keep=31 //
|
|
||||||
@weekly root zfs-auto-snapshot -q -g --label=weekly --keep=4 //
|
|
||||||
@monthly root zfs-auto-snapshot -q -g --label=monthly --keep=12 //
|
|
2
etc/zfs-auto-snapshot.cron.daily
Normal file
2
etc/zfs-auto-snapshot.cron.daily
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
exec zfs-auto-snapshot --quiet --syslog --label=daily --keep=31 //
|
3
etc/zfs-auto-snapshot.cron.frequent
Normal file
3
etc/zfs-auto-snapshot.cron.frequent
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
||||||
|
|
||||||
|
*/15 * * * * root zfs-auto-snapshot -q -g --label=frequent --keep=4 //
|
2
etc/zfs-auto-snapshot.cron.hourly
Normal file
2
etc/zfs-auto-snapshot.cron.hourly
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
exec zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 //
|
2
etc/zfs-auto-snapshot.cron.monthly
Normal file
2
etc/zfs-auto-snapshot.cron.monthly
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
exec zfs-auto-snapshot --quiet --syslog --label=monthly --keep=12 //
|
2
etc/zfs-auto-snapshot.cron.weekly
Normal file
2
etc/zfs-auto-snapshot.cron.weekly
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
exec zfs-auto-snapshot --quiet --syslog --label=weekly --keep=8 //
|
@ -51,7 +51,7 @@ SNAPSHOTS_OLD=''
|
|||||||
print_usage ()
|
print_usage ()
|
||||||
{
|
{
|
||||||
echo "Usage: $0 [options] [-l label] <'//' | name [name...]>
|
echo "Usage: $0 [options] [-l label] <'//' | name [name...]>
|
||||||
--default-exclude Exclude objects if com.sun:auto-snapshot is unset.
|
--default-exclude Exclude datasets if com.sun:auto-snapshot is unset.
|
||||||
-d, --debug Print debugging messages.
|
-d, --debug Print debugging messages.
|
||||||
-e, --event=EVENT Set the com.sun:auto-snapshot-desc property to EVENT.
|
-e, --event=EVENT Set the com.sun:auto-snapshot-desc property to EVENT.
|
||||||
-n, --dry-run Print actions without actually doing anything.
|
-n, --dry-run Print actions without actually doing anything.
|
||||||
@ -67,7 +67,7 @@ print_usage ()
|
|||||||
-g, --syslog Write messages into the system log.
|
-g, --syslog Write messages into the system log.
|
||||||
-r, --recursive Snapshot named filesystem and all descendants.
|
-r, --recursive Snapshot named filesystem and all descendants.
|
||||||
-v, --verbose Print info messages.
|
-v, --verbose Print info messages.
|
||||||
name Filesystem and volume names, or '//' for all ZFS objects.
|
name Filesystem and volume names, or '//' for all ZFS datasets.
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ do
|
|||||||
while test "${#opt_prefix}" -gt '0'
|
while test "${#opt_prefix}" -gt '0'
|
||||||
do
|
do
|
||||||
case $opt_prefix in
|
case $opt_prefix in
|
||||||
([![:alnum:]_-.:\ ]*)
|
([![:alnum:]_.:\ -]*)
|
||||||
print_log error "The $1 parameter must be alphanumeric."
|
print_log error "The $1 parameter must be alphanumeric."
|
||||||
exit 130
|
exit 130
|
||||||
;;
|
;;
|
||||||
@ -278,7 +278,7 @@ do
|
|||||||
;;
|
;;
|
||||||
(--sep)
|
(--sep)
|
||||||
case "$2" in
|
case "$2" in
|
||||||
([[:alnum:]_-.:\ ])
|
([[:alnum:]_.:\ -])
|
||||||
:
|
:
|
||||||
;;
|
;;
|
||||||
('')
|
('')
|
||||||
@ -358,26 +358,26 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Get a list of pools that are being scrubbed.
|
# Get a list of pools that are being scrubbed.
|
||||||
ZPOOLS_SCRUBBING=$(echo "$ZFS_STATUS" | awk -F ': ' \
|
ZPOOLS_SCRUBBING=$(echo "$ZPOOL_STATUS" | awk -F ': ' \
|
||||||
'$1 ~ /^ *pool$/ { pool = $2 } ; \
|
'$1 ~ /^ *pool$/ { pool = $2 } ; \
|
||||||
$1 ~ /^ *scan$/ && $2 ~ /scrub in progress/ { print pool }' \
|
$1 ~ /^ *scan$/ && $2 ~ /scrub in progress/ { print pool }' \
|
||||||
| sort )
|
| sort )
|
||||||
|
|
||||||
# Get a list of pools that cannot do a snapshot.
|
# Get a list of pools that cannot do a snapshot.
|
||||||
ZPOOLS_NOTREADY=$(echo "$ZFS_STATUS" | awk -F ': ' \
|
ZPOOLS_NOTREADY=$(echo "$ZPOOL_STATUS" | awk -F ': ' \
|
||||||
'$1 ~ /^ *pool$/ { pool = $2 } ; \
|
'$1 ~ /^ *pool$/ { pool = $2 } ; \
|
||||||
$1 ~ /^ *state$/ && $2 !~ /ONLINE|DEGRADED/ { print pool } ' \
|
$1 ~ /^ *state$/ && $2 !~ /ONLINE|DEGRADED/ { print pool } ' \
|
||||||
| sort)
|
| sort)
|
||||||
|
|
||||||
# Get a list of objects for which snapshots are explicitly disabled.
|
# Get a list of datasets for which snapshots are explicitly disabled.
|
||||||
NOAUTO=$(echo "$ZFS_LIST" | awk -F '\t' \
|
NOAUTO=$(echo "$ZFS_LIST" | awk -F '\t' \
|
||||||
'tolower($2) ~ /false/ || tolower($3) ~ /false/ {print $1}')
|
'tolower($2) ~ /false/ || tolower($3) ~ /false/ {print $1}')
|
||||||
|
|
||||||
# If the --default-exclude flag is set, then exclude all objects that lack
|
# If the --default-exclude flag is set, then exclude all datasets that lack
|
||||||
# an explicit com.sun:auto-snapshot* property. Otherwise, include them.
|
# an explicit com.sun:auto-snapshot* property. Otherwise, include them.
|
||||||
if [ -n "$opt_default_exclude" ]
|
if [ -n "$opt_default_exclude" ]
|
||||||
then
|
then
|
||||||
# Get a list of objects for which snapshots are explicitly enabled.
|
# Get a list of datasets for which snapshots are explicitly enabled.
|
||||||
CANDIDATES=$(echo "$ZFS_LIST" | awk -F '\t' \
|
CANDIDATES=$(echo "$ZFS_LIST" | awk -F '\t' \
|
||||||
'tolower($2) ~ /true/ || tolower($3) ~ /true/ {print $1}')
|
'tolower($2) ~ /true/ || tolower($3) ~ /true/ {print $1}')
|
||||||
else
|
else
|
||||||
@ -386,20 +386,20 @@ else
|
|||||||
'tolower($2) !~ /false/ && tolower($3) !~ /false/ {print $1}')
|
'tolower($2) !~ /false/ && tolower($3) !~ /false/ {print $1}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Initialize the list of objects that will get a recursive snapshot.
|
# Initialize the list of datasets that will get a recursive snapshot.
|
||||||
TARGETS_RECURSIVE=''
|
TARGETS_RECURSIVE=''
|
||||||
|
|
||||||
# Initialize the list of objects that will get a non-recursive snapshot.
|
# Initialize the list of datasets that will get a non-recursive snapshot.
|
||||||
TARGETS_REGULAR=''
|
TARGETS_REGULAR=''
|
||||||
|
|
||||||
for ii in $CANDIDATES
|
for ii in $CANDIDATES
|
||||||
do
|
do
|
||||||
# Qualify object names so variable globbing works properly.
|
# Qualify dataset names so variable globbing works properly.
|
||||||
# Suppose ii=tanker/foo and jj=tank sometime during the loop.
|
# Suppose ii=tanker/foo and jj=tank sometime during the loop.
|
||||||
# Just testing "$ii" != ${ii#$jj} would incorrectly match.
|
# Just testing "$ii" != ${ii#$jj} would incorrectly match.
|
||||||
iii="$ii/"
|
iii="$ii/"
|
||||||
|
|
||||||
# Exclude objects that are not named on the command line.
|
# Exclude datasets that are not named on the command line.
|
||||||
IN_ARGS='0'
|
IN_ARGS='0'
|
||||||
for jj in "$@"
|
for jj in "$@"
|
||||||
do
|
do
|
||||||
@ -413,13 +413,13 @@ do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Exclude objects in pools that cannot do a snapshot.
|
# Exclude datasets in pools that cannot do a snapshot.
|
||||||
for jj in $ZPOOLS_NOTREADY
|
for jj in $ZPOOLS_NOTREADY
|
||||||
do
|
do
|
||||||
# Ibid regarding iii.
|
# Ibid regarding iii.
|
||||||
jjj="$jj/"
|
jjj="$jj/"
|
||||||
|
|
||||||
# Check whether the pool name is a prefix of the object name.
|
# Check whether the pool name is a prefix of the dataset name.
|
||||||
if [ "$iii" != "${iii#$jjj}" ]
|
if [ "$iii" != "${iii#$jjj}" ]
|
||||||
then
|
then
|
||||||
print_log info "Excluding $ii because pool $jj is not ready."
|
print_log info "Excluding $ii because pool $jj is not ready."
|
||||||
@ -427,13 +427,13 @@ do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Exclude objects in scrubbing pools if the --skip-scrub flag is set.
|
# Exclude datasets in scrubbing pools if the --skip-scrub flag is set.
|
||||||
test -n "$opt_skip_scrub" && for jj in $ZPOOLS_SCRUBBING
|
test -n "$opt_skip_scrub" && for jj in $ZPOOLS_SCRUBBING
|
||||||
do
|
do
|
||||||
# Ibid regarding iii.
|
# Ibid regarding iii.
|
||||||
jjj="$jj/"
|
jjj="$jj/"
|
||||||
|
|
||||||
# Check whether the pool name is a prefix of the object name.
|
# Check whether the pool name is a prefix of the dataset name.
|
||||||
if [ "$iii" != "${iii#$jjj}" ]
|
if [ "$iii" != "${iii#$jjj}" ]
|
||||||
then
|
then
|
||||||
print_log info "Excluding $ii because pool $jj is scrubbing."
|
print_log info "Excluding $ii because pool $jj is scrubbing."
|
||||||
@ -446,17 +446,17 @@ do
|
|||||||
# Ibid regarding iii.
|
# Ibid regarding iii.
|
||||||
jjj="$jj/"
|
jjj="$jj/"
|
||||||
|
|
||||||
# The --recusive switch only matters for non-wild arguments.
|
# The --recursive switch only matters for non-wild arguments.
|
||||||
if [ -z "$opt_recursive" -a "$1" != '//' ]
|
if [ -z "$opt_recursive" -a "$1" != '//' ]
|
||||||
then
|
then
|
||||||
# Snapshot this object non-recursively.
|
# Snapshot this dataset non-recursively.
|
||||||
print_log debug "Including $ii for regular snapshot."
|
print_log debug "Including $ii for regular snapshot."
|
||||||
TARGETS_REGULAR="${TARGETS_REGULAR:+$TARGETS_REGULAR }$ii" # nb: \t
|
TARGETS_REGULAR="${TARGETS_REGULAR:+$TARGETS_REGULAR }$ii" # nb: \t
|
||||||
continue 2
|
continue 2
|
||||||
# Check whether the candidate name is a prefix of any excluded object name.
|
# Check whether the candidate name is a prefix of any excluded dataset name.
|
||||||
elif [ "$jjj" != "${jjj#$iii}" ]
|
elif [ "$jjj" != "${jjj#$iii}" ]
|
||||||
then
|
then
|
||||||
# Snapshot this object non-recursively.
|
# Snapshot this dataset non-recursively.
|
||||||
print_log debug "Including $ii for regular snapshot."
|
print_log debug "Including $ii for regular snapshot."
|
||||||
TARGETS_REGULAR="${TARGETS_REGULAR:+$TARGETS_REGULAR }$ii" # nb: \t
|
TARGETS_REGULAR="${TARGETS_REGULAR:+$TARGETS_REGULAR }$ii" # nb: \t
|
||||||
continue 2
|
continue 2
|
||||||
@ -468,7 +468,7 @@ do
|
|||||||
# Ibid regarding iii.
|
# Ibid regarding iii.
|
||||||
jjj="$jj/"
|
jjj="$jj/"
|
||||||
|
|
||||||
# Check whether any included object is a prefix of the candidate name.
|
# Check whether any included dataset is a prefix of the candidate name.
|
||||||
if [ "$iii" != "${iii#$jjj}" ]
|
if [ "$iii" != "${iii#$jjj}" ]
|
||||||
then
|
then
|
||||||
print_log debug "Excluding $ii because $jj includes it recursively."
|
print_log debug "Excluding $ii because $jj includes it recursively."
|
||||||
|
Reference in New Issue
Block a user