Compare commits

..

No commits in common. "86d600864de9529922287430cc52acddb9b5fab4" and "5106197dc6b75d3dfaa4ebb5fdf5f898f69105ee" have entirely different histories.

2 changed files with 26 additions and 13 deletions

View File

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