summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbackomp30
1 files changed, 21 insertions, 9 deletions
diff --git a/backomp b/backomp
index 022665d..af44f77 100755
--- a/backomp
+++ b/backomp
@@ -160,11 +160,11 @@ ssh_run() {
fi
}
-current() {
- local str="${1}" interval="${2}"
- local s=0 val d
+parse_duration() {
+ local str="${1}"
+ local s=0 val
- while [[ "${interval}" =~ ([0-9]+)(.?) ]]; do
+ while [[ "${str}" =~ ([0-9]+)(.?) ]]; do
val="${BASH_REMATCH[1]}"
case "${BASH_REMATCH[2]}" in
d) ((s += val * 24*60*60)) ;;
@@ -173,12 +173,21 @@ current() {
*) ((s += val)) ;;
esac
- interval="${interval#*"${BASH_REMATCH[0]}"}"
+ str="${str#*"${BASH_REMATCH[0]}"}"
done
+ echo "${s}"
+}
+
+current() {
+ local str="${1}" interval="${2}" offset="${3}"
+ local s o d
+
+ s="$(parse_duration "${interval}")"
((s < 1)) && return 1
+ o="$(parse_duration "${offset}")"
d="${str:0:10} ${str:11:2}:${str:13:2}:${str:15:2}"
- (($(date -u +%s) / s == $(date -ud "${d}" +%s) / s))
+ ((($(date -u +%s) - o) / s == ($(date -ud "${d}" +%s) - o) / s))
}
exists() {
@@ -354,8 +363,8 @@ prune() {
backup() {
local src_path="${1}" dest_dir="${2}"
- local retain="${3}" interval="${4}" week_start="${5}"
- local rsync_flags="${6}" rclone_flags="${7}" ssh_flags="${8}"
+ local retain="${3}" interval="${4}" offset="${5}" week_start="${6}"
+ local rsync_flags="${7}" rclone_flags="${8}" ssh_flags="${9}"
local dest_path snaps keep
if ((!NO_BACKUP)) && [[ ! -e "${src_path}" ]]; then
@@ -371,7 +380,8 @@ backup() {
|| return 1
if ((!NO_BACKUP)) && ( [[ -z "${snaps}" ]] ||
- ! current "${snaps[0]##*/}" "${interval}" ); then
+ ! current "${snaps[0]##*/}" "${interval}" \
+ "${offset}" ); then
dest_path="${dest_dir}/$(date -u '+%Y-%m-%d-%H%M%S')"
copy "${src_path}" "${dest_path}" "${snaps[0]}" || return 1
snaps+=("${dest_path}")
@@ -402,6 +412,7 @@ backup() {
declare -A def_opts=(
['retain']= # e.g. *h or 24h7d4w12M5y or 24^h10d*M
['interval']='0'
+ ['offset']='0'
['week_start']='mon' # empty value aligns weeks to 1st of each month
['rsync_flags']='-a'
['rclone_flags']='--sftp-copy-is-hardlink'
@@ -537,6 +548,7 @@ while IFS= read -r line; do
backup "${src}" "${dest}" \
"${opts['retain']}" \
"${opts['interval']}" \
+ "${opts['offset']}" \
"${opts['week_start']}" \
"${opts['rsync_flags']}" \
"${opts['rclone_flags']}" \