Compare commits

..

3 Commits

Author SHA1 Message Date
Philipp Woelfel
86d600864d cleanup unnecessary code / print number processed datasets 2025-11-15 23:58:06 -07:00
Philipp Woelfel
fc482a088b typesetting fix 2025-11-15 23:50:39 -07:00
Philipp Woelfel
bcae740611 Improved documentation 2025-11-15 23:50:05 -07:00
2 changed files with 13 additions and 26 deletions

View File

@ -18,17 +18,16 @@ Script to check zfs snapshot counts and age of oldest most recent snapshot. Spec
## Options ## Options
```bash - `-d, --dataset <dataset>`: Dataset to check (required; can be repeated for multiple)
-d, --dataset <dataset> Dataset to check (required, repeat for multiple) - `-p, --prefix <prefix>`: Snapshot prefix (default: `zrepl_`)
-e, --exclude <dataset> Exclude dataset (repeat for multiple) - `-f, --format <format>`: Timestamp format (see [below](#timestamp-formats--f))
-p, --prefix <prefix> Snapshot prefix (default: zrepl_) - `-s, --max-snapshots <num>`: Max snapshots per dataset
-f, --format <format> Timestamp format (see [below](#timestamp-formats--f)) - `-m, --max-age <duration>`: Max age (e.g., 31s, 17m, 24h)
-s, --max-snapshots <num> Max snapshots per dataset - `-r, --recursive`: Include sub-datasets
-m, --max-age <duration> Max age (e.g., 31s, 17m, 24h) - `-e, --exclude <dataset>`: Exclude dataset (can be repeated for multiple)
-r, --recursive Include sub-datasets - `-v, --verbose`: Show detailed table
-v, --verbose Show detailed table - `-n, --err-for-no-snapshots`: Error if no snapshots found
-n, --err-for-no-snapshots Error if no snapshots found - `-h, --help`: Show help message
```
## Timestamp Formats (`-f`) ## Timestamp Formats (`-f`)

View File

@ -17,7 +17,7 @@ ERR_FOR_NO_SNAPSHOTS=false
FORMAT="" FORMAT=""
usage() { usage() {
echo "Usage: $0 -d|--dataset <dataset> [-d|--dataset <dataset>...] [-p|--prefix <prefix>] [-f|--format <format>] [-m <duration>] [-s|--max-snapshots <num>] [-e|--exclude <dataset>] [-r|--recursive] [-v|--verbose] [-n|--err-for-no-snapshots]" echo "Usage: $0 -d|--dataset <dataset> [-d|--dataset <dataset>...] [-p|--prefix <prefix>] [-f|--format <format>] [-m <duration>] [-s|--max-snapshots <num>] [-e|--exclude <dataset>] [-r|--recursive] [-v|--verbose] [-n|--err-for-no-snapshots] [-h|--help]"
echo " -d, --dataset ZFS dataset to check (can be specified multiple times)" echo " -d, --dataset ZFS dataset to check (can be specified multiple times)"
echo " -e, --exclude Dataset to exclude (can be specified multiple times)" echo " -e, --exclude Dataset to exclude (can be specified multiple times)"
echo " -p, --prefix Snapshot prefix (default: zrepl_)" echo " -p, --prefix Snapshot prefix (default: zrepl_)"
@ -27,6 +27,7 @@ usage() {
echo " -r, --recursive Include all sub-datasets of specified datasets" echo " -r, --recursive Include all sub-datasets of specified datasets"
echo " -v, --verbose Print per-dataset snapshot count and age" echo " -v, --verbose Print per-dataset snapshot count and age"
echo " -n, --err-for-no-snapshots Return error if any dataset has no snapshots" echo " -n, --err-for-no-snapshots Return error if any dataset has no snapshots"
echo " -h, --help Show this help message"
exit 1 exit 1
} }
@ -44,20 +45,6 @@ duration_to_seconds() {
esac esac
} }
# timestamp_to_epoch() {
# # Format: YYYYMMDD_HHMMSS_mmm
# local timestamp="$1"
# local year="${timestamp:0:4}"
# local month="${timestamp:4:2}"
# local day="${timestamp:6:2}"
# local hour="${timestamp:9:2}"
# local minute="${timestamp:11:2}"
# local second="${timestamp:13:2}"
# # Convert to epoch using date command (assuming UTC)
# date -u -d "${year}-${month}-${day} ${hour}:${minute}:${second}" +%s 2>/dev/null
# }
# Format age in seconds to human-readable format # Format age in seconds to human-readable format
format_age() { format_age() {
local total_seconds="$1" local total_seconds="$1"
@ -356,6 +343,7 @@ if [[ "$VERBOSE" == "true" ]]; then
echo "" echo ""
fi fi
echo "Datasets processed: ${#DATASETS_TO_PROCESS[@]}"
echo "Max snapshots: $MAX_SNAPSHOT_COUNT ($MAX_SNAPSHOT_DATASET)" echo "Max snapshots: $MAX_SNAPSHOT_COUNT ($MAX_SNAPSHOT_DATASET)"
echo "Oldest most recent snapshot age: $TIME_DIFF_FORMATTED ($OLDEST_SNAPSHOT_DATASET)" echo "Oldest most recent snapshot age: $TIME_DIFF_FORMATTED ($OLDEST_SNAPSHOT_DATASET)"