Compare commits
3 Commits
f1be6dc83d
...
89b9c8a416
Author | SHA1 | Date |
---|---|---|
Dave Eddy | 89b9c8a416 | |
Dave Eddy | 701762f1ec | |
Ryan Petschek | a9d24fc81a |
13
CHANGES.md
13
CHANGES.md
|
@ -6,6 +6,19 @@ Not Yet Released
|
|||
|
||||
(nothing yet)
|
||||
|
||||
`v1.5.0`
|
||||
--------
|
||||
|
||||
- Sanity check datasets existence before running
|
||||
- `-q` will hide warnings for datesets not existing
|
||||
- Based on ([#9](https://github.com/bahamas10/zfs-prune-snapshots/pull/9))
|
||||
|
||||
`v1.4.1`
|
||||
--------
|
||||
|
||||
- Allow snapshot datasets to contain spaces
|
||||
([#18](https://github.com/bahamas10/zfs-prune-snapshots/pull/18))
|
||||
|
||||
`v1.4.0`
|
||||
--------
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# Date: November 20, 2015
|
||||
# License: MIT
|
||||
|
||||
VERSION='v1.4.0'
|
||||
VERSION='v1.4.1'
|
||||
|
||||
usage() {
|
||||
local prog=${0##*/}
|
||||
|
@ -69,7 +69,7 @@ EOF
|
|||
}
|
||||
|
||||
debug() {
|
||||
((verbosity >= 1)) && echo "$@" >&2
|
||||
((verbosity >= 1)) && echo '>' "$@" >&2
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -174,6 +174,7 @@ verbosity=0
|
|||
prefix=
|
||||
suffix=
|
||||
invert=false
|
||||
quiet=false
|
||||
while getopts 'hniqlRp:s:vV' option; do
|
||||
case "$option" in
|
||||
h) usage; exit 0;;
|
||||
|
@ -182,7 +183,7 @@ while getopts 'hniqlRp:s:vV' option; do
|
|||
l) listonly=true;;
|
||||
p) prefix=$OPTARG;;
|
||||
s) suffix=$OPTARG;;
|
||||
q) exec 1>/dev/null;;
|
||||
q) quiet=true; exec 1>/dev/null;;
|
||||
R) recursive=true;;
|
||||
v) ((verbosity++));;
|
||||
V) echo "$VERSION"; exit 0;;
|
||||
|
@ -221,13 +222,10 @@ fi
|
|||
|
||||
shift
|
||||
|
||||
pools=("$@")
|
||||
destroyargs=()
|
||||
code=0
|
||||
totalused=0
|
||||
numsnapshots=0
|
||||
humanpools=${pools[*]}
|
||||
humanpools=${humanpools:-<all>}
|
||||
|
||||
if $recursive; then
|
||||
destroyargs+=('-R')
|
||||
|
@ -243,10 +241,40 @@ if ! command -v zfs &>/dev/null; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# validate pools given, print warnings if not in quiet mode
|
||||
pools=()
|
||||
for arg in "$@"; do
|
||||
debug "checking '$arg' exists"
|
||||
|
||||
error=$(zfs list "$arg" 2>&1 1>/dev/null)
|
||||
code=$?
|
||||
debug "zfs list '$arg' -> exited $code"
|
||||
|
||||
if ((code == 0)) && [[ -z $error ]]; then
|
||||
debug "adding dataset '$arg'"
|
||||
pools+=("$arg")
|
||||
else
|
||||
msg="dataset '$arg' invalid: $error"
|
||||
debug "$msg"
|
||||
if ! $quiet; then
|
||||
echo "$msg" >&2
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# it is an error if arguments were given but all datasets were invalidated
|
||||
if [[ -n $1 && -z ${pools[0]} ]]; then
|
||||
echo 'no valid dataset names provided' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
humanpools=${pools[*]}
|
||||
humanpools=${humanpools:-<all>}
|
||||
|
||||
# first pass of the pools (to calculate totals and filter unwanted datasets
|
||||
lines=()
|
||||
while read -r line; do
|
||||
read -r creation used snapshot _ <<< "$line"
|
||||
read -r creation used snapshot <<< "$line"
|
||||
|
||||
# ensure optional prefix matches
|
||||
snapname=${snapshot#*@}
|
||||
|
@ -317,7 +345,7 @@ echo "found $numsnapshots snapshots ($humantotal) on pools: $humanpools"
|
|||
# process snapshots found
|
||||
i=0
|
||||
for line in "${lines[@]}"; do
|
||||
read -r creation used snapshot _ <<< "$line"
|
||||
read -r creation used snapshot <<< "$line"
|
||||
|
||||
((i++))
|
||||
|
||||
|
|
Loading…
Reference in New Issue