diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-08-07 00:03:01 -0700 |
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2026-08-07 00:03:01 -0700 |
| commit | e6b7124f9c375cf81b532040981077bde923ec32 (patch) | |
| tree | e6ead8dc1605ba2430b5b09e948eec3cb50d8302 | |
| parent | 8ed81fc62d8d0c70177b5a8c28a6c7fd34ab6729 (diff) | |
| download | backomp-e6b7124f9c375cf81b532040981077bde923ec32.tar.gz backomp-e6b7124f9c375cf81b532040981077bde923ec32.tar.xz | |
add yearly retention bucket
| -rwxr-xr-x | backomp | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -23,8 +23,12 @@ function mstart(t) { return mktime(strftime("%Y %m 01 00 00 00", t, 1), 1) } +function ystart(t) { + return mktime(strftime("%Y 01 01 00 00 00", t, 1), 1) +} + BEGIN { - n = split("h d w M", arr) + n = split("h d w M y", arr) for (i = 1; i <= n; ++i) { b = arr[i] @@ -36,6 +40,9 @@ BEGIN { buckets[++n_buckets] = b } + if ("w" in ret) + after_w = ("M" in ret) ? "M" : "y" + split("mon tue wed thu fri sat sun", arr) for (i in arr) arr2[arr[i]] = i - 1 @@ -54,15 +61,18 @@ n_buckets { bt["d"] = flr(t, 24*60*60) bt["w"] = flr(t + wshift, 7*24*60*60) - wshift bt["M"] = mstart(t) + bt["y"] = ystart(t) for (i = 1; i <= n_buckets; ++i) { b = buckets[i] - if (b == "M" && "w" in ret) { + if (b == after_w) { if (newest_in["w"]) { - if (mstart(bt["w"] + 6*24*60*60) > bt["M"]) + v = bt["w"] + 6*24*60*60 + v = (b == "M") ? mstart(v) : ystart(v) + if (v > bt[b]) next - } else if (bt["w"] < bt["M"]) { + } else if (bt["w"] < bt[b]) { next } } @@ -366,7 +376,7 @@ backup() { ((NO_PRUNE)) && return - if [[ ! "${retain}" =~ ^( *([0-9]+|\*)\^?[hdwM])*\ *$ ]]; then + if [[ ! "${retain}" =~ ^( *([0-9]+|\*)\^?[hdwMy])*\ *$ ]]; then err "invalid \$retain setting: ${retain}" return 1 fi @@ -383,7 +393,7 @@ backup() { } declare -A def_opts=( - ['retain']= # e.g. *h or 24h7d4w12M or 24^h10d*M + ['retain']= # e.g. *h or 24h7d4w12M5y or 24^h10d*M ['interval']='0' ['week_start']='mon' ['rsync_flags']='-a' |
