summaryrefslogtreecommitdiff
path: root/backomp
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-02-09 05:58:10 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2026-02-09 05:58:10 -0800
commitb86452f347a71b41df5024a500a962614ed86c21 (patch)
tree165b6150886b90da13073d44cd3894323510f739 /backomp
parent638d5bbc2f187ff1ef265f24658a456e72c0976a (diff)
downloadbackomp-b86452f347a71b41df5024a500a962614ed86c21.tar.gz
backomp-b86452f347a71b41df5024a500a962614ed86c21.tar.xz
move newest_in into retain; improve promotion logic
Diffstat (limited to 'backomp')
-rwxr-xr-xbackomp49
1 files changed, 25 insertions, 24 deletions
diff --git a/backomp b/backomp
index 068dade..3862a6a 100755
--- a/backomp
+++ b/backomp
@@ -7,17 +7,21 @@ function flr(n, s) {
return int(n / s) * s
}
+function mstart(t) {
+ return mktime(strftime("%Y %m 01 00 00 00", t, 1), 1)
+}
+
BEGIN {
- len = split("h d w m", arr)
- for (i = 1; i <= len; ++i) {
+ n = split("h d w m", arr)
+ for (i = 1; i <= n; ++i) {
b = arr[i]
- if (!match(opt_retain, "([*0-9]+)" b, md))
+ if (!match(opt_retain, "([*0-9]+)(\\^?)" b, md))
continue
+
ret[b] = md[1]
+ newest_in[b] = (md[2] == "^")
buckets[++n_buckets] = b
-
- newest_in[b] = !!index(opt_newest_in, b)
}
split("sun mon tue wed thu fri sat", arr)
@@ -33,23 +37,24 @@ BEGIN {
bt["h"] = flr(t, 60*60)
bt["d"] = flr(t, 24*60*60)
bt["w"] = flr(t + wshift, 7*24*60*60) - wshift
- bt["m"] = mktime(strftime("%Y %m", t, 1) " 01 00 00 00", 1)
+ bt["m"] = mstart(t)
for (i = 1; i <= n_buckets; ++i) {
b = buckets[i]
- if (b == "m" && !newest_in["w"] && bt["m"] > bt["w"])
- next
-
- if (newest_in[b] && bt[b] == last[b, b]) {
- for (j = 1; j < i; ++j) {
- if (bt[buckets[j]] == last[b, buckets[j]])
- break
- }
- if (j == i)
+ if (b == "m" && "w" in ret) {
+ if (newest_in["w"]) {
+ if (mstart(bt["w"] + 6*24*60*60) > bt["m"])
+ next
+ } else if (bt["w"] < bt["m"]) {
next
+ }
}
+ if (newest_in[b] && bt[b] == last[b, b] && (i == 1 ||
+ bt[buckets[i-1]] != last[b, buckets[i-1]]))
+ next
+
if ((b, bt[b]) in bkeep || ret[b] == "*" || bc[b]++ < ret[b])
bkeep[b, bt[b]] = $1
@@ -62,8 +67,8 @@ END {
for (i in bkeep)
++keep[bkeep[i]]
- asorti(keep)
- for (i in keep)
+ n = asorti(keep)
+ for (i = 1; i <= n; ++i)
print keep[i]
}
EOF
@@ -77,8 +82,7 @@ backup() {
dest_dir="${1}"
src_path="${2}"
retain="${3}"
- newest_in="${4}"
- week_start="${5}"
+ week_start="${4}"
[[ "$((dcount++))" -ne 0 ]] && echo
echo "[${dcount}] [${retain}] ${src_path} => ${dest_dir}"
@@ -93,9 +97,8 @@ backup() {
mapfile -t keep < <(
awk \
-v "opt_retain=${retain}" \
- -v "opt_newest_in=${newest_in}" \
-v "opt_week_start=${week_start}" \
- "${FILTER_AWK}" < <(printf '%s\n' "${snaps[@]}"))
+ -- "${FILTER_AWK}" < <(printf '%s\n' "${snaps[@]}"))
if [[ -z "${keep}" ]]; then
echo "WARNING: dirs to keep shouldn't be empty; skipping" >&2
return
@@ -114,8 +117,7 @@ backup() {
declare -A def_opts=(
['retain']='*h*d*w*m'
- ['newest_in']='h'
- ['week_start']='sun'
+ ['week_start']='mon'
)
declare -A opts
@@ -132,7 +134,6 @@ while IFS='=' read -r f1 f2; do
else
backup "${base_path}/${f1}" "${f2}" \
"${opts['retain']}" \
- "${opts['newest_in']}" \
"${opts['week_start']}"
fi
done < "${1}"