profile
viewpoint

Ask questions[bug] Week retention not working

Thanks for writing and maintaining this. I am testing it with success so far, before using it in production. But I have a problem with retention as it seems not to behave as I would except, if I understand the help correctly. In particular, the "week" retention.

For example, these snapshots are tagged/not-tagged using 4 leafs, 3 days, 4 weeks, 12 months and 5 years:

2021/06/26/152400 not tagged
2021/06/26/142400 not tagged
2021/06/24/152400 not tagged
2021/06/24/142400 not tagged
2021/06/23/152400 not tagged
2021/06/22/152400 tagged
2021/06/21/152400 tagged
2021/06/21/142400 tagged
2021/06/20/152400 tagged
2021/06/20/142400 tagged
2021/06/19/152400 tagged
2021/06/19/142400 tagged
2021/06/14/152400 tagged
2021/06/13/152400 tagged
2021/06/12/152400 tagged

I would except (13 and 20 are Sunday):

2021/06/26/152400 not tagged
2021/06/26/142400 not tagged
2021/06/24/152400 not tagged
2021/06/24/142400 not tagged
2021/06/23/152400 not tagged
2021/06/22/152400 tagged
2021/06/21/152400 tagged
2021/06/21/142400 tagged
2021/06/20/152400 not tagged
2021/06/20/142400 tagged
2021/06/19/152400 tagged
2021/06/19/142400 tagged
2021/06/14/152400 tagged
2021/06/13/152400 not tagged
2021/06/12/152400 tagged

To obtain this result, I replaced:

[[ -n "$lw" ]] && (( $(date -d "$lw UTC" +%s) - $(date -d "$y/$m/$d UTC" +%s) / (60 * 60 * 24) > 6 )) \
&& (( tag &= retention[weeks]-- < 1 ))
lw=$(date -d "$y/$m/$d -$(date -d $y/$m/$d +%u) days +$weekstart day" +'%F')

by

cw=$(date -d "$y/$m/$d" +'%Y%V')
(( $lw != $cw && (lw = cw, tag &= retention[weeks]-- < 1) ))
  • I replace your calculation with a variable keeping the last week (lw) saved and using date to get the current week number (cw)
  • Replacing +'%Y%V' by +'%Y%U' would use Sunday as first day of the week instead of Monday
  • I defined lw='000000' before the loop

To test my code, I added this code at the end of the backup script:

echo """/2021/06/26/152400
/2021/06/26/142400
/2021/06/24/152400
/2021/06/24/142400
/2021/06/23/152400
/2021/06/22/152400
/2021/06/21/152400
/2021/06/21/142400
/2021/06/20/152400
/2021/06/20/142400
/2021/06/19/152400
/2021/06/19/142400
/2021/06/14/152400
/2021/06/13/152400
/2021/06/12/152400""" | sort -dr | tokenize_path | check_retention --all | rotate_test

Does this make sense to you (if yes I can submit a PR)? Am I missing something?

3coma3/btrfs-backup

Answer questions vejnar

Hi @3coma3. Thanks for fixing this so fast! Problem I was having is solved.

My review for the patch:

  • I understand keeping 1 and 7 for compatibility but I wouldn't add so many more names (s, sun etc) for the config. I think sunday and monday are enough.
  • Add a comment to indicate this section of code checks the week number.
useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List