prometheus related updates
[distro-setup] / btrbk-run
1 #!/bin/bash
2 # Copyright (C) 2016 Ian Kelling
3
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16
17 # todo: if we cancel in the middle of a btrfs send, then run again
18 # immediately, the received subvolume doesn't get a Received UUID:
19 # field, and we won't mount it. Need to figure out a solution that will
20 # fix this.
21
22
23 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
24
25 source /usr/local/lib/err
26
27 usage() {
28 cat <<'EOF'
29 btrbk-run [OPTIONS] [run|resume|archive]
30 usually -t TARGET_HOST or -s SOURCE_HOST
31
32 Note, at source location, intentionally not executable, run and read
33 install-my-scripts.
34
35 EOF
36 echo "top of script file:"
37 sed -n '1,/^[# ]*end command line/{p;b};q' "$0"
38 exit $1
39 }
40
41
42
43 script_name="${BASH_SOURCE[0]}"
44 script_name="${script_name##*/}"
45 pre="${SSH_CLIENT:+$HOSTNAME} $script_name:"
46 m() { if $verbose; then printf "$pre%s\n" "$*"; fi; "$@"; }
47 e() { printf "$pre%s\n" "$*"; }
48 die() { printf "$pre%s\n" "$*" >&2; echo "exiting with status 1" >&2; exit 1; }
49 mexit() { echo "$pre: exiting with status $1"; exit $1; }
50
51 # latest $MAIL_HOST
52 if [[ -e /b/bash_unpublished/source-state ]]; then
53 source /b/bash_unpublished/source-state
54 fi
55
56 # note q is owned by root:1000
57
58 mountpoints=()
59
60 rsync_mountpoint=/q
61
62 ret=0
63 # default options
64 conf_only=false
65 dry_run=false # mostly for testing
66 rate_limit=no
67 verbose=true; verbose_arg=-v
68 if [[ $INVOCATION_ID ]]; then
69 # INVOCATION_ID means running as a systemd service. we cant show progress in this case,
70 # but if we pass the arg, it will insert mbuffer into the command.
71 progress_arg=
72 else
73 progress_arg="--progress"
74 fi
75 incremental_strict=false
76 pull_reexec=false
77
78 default_args_file=/etc/btrbk-run.conf
79 if [[ -s $default_args_file ]]; then
80 # shellcheck disable=SC2046 # we want word splitting
81 set -- $(< $default_args_file) "$@"
82 # i havent used this feature yet, so warn about it
83 echo "$0: warning: default btrbk-run options set in $default_args_file (sleeping 5 seconds):"
84 cat $default_args_file
85 sleep 5
86 fi
87
88 targets=()
89 early=false
90 cron=false
91 fast=false
92 kd_spread_maybe=false
93 orig_args=("$@")
94 temp=$(getopt -l cron,fast,pull-reexec,help 23ceikl:m:npqrs:t:vh "$@") || usage 1
95 eval set -- "$temp"
96 while true; do
97 case $1 in
98 # some behaviors specific to running under cron:
99 # - skip hosts where xprintidle haven't been idle recently
100 # - if we can't ssh to 1 or more hosts, still do the rest
101 # - if we aren't MAIL_HOST and no -m or -s, just exit
102 --cron)
103 cron=true
104 pre=
105 ;;
106 # for the rare case we want to run multiple instances at the same time
107 -2) conf_suf=2 ;;
108 -3) conf_suf=3 ;;
109 # only creates the config file, does not run btrbk
110 -c) conf_only=true ;;
111 # quit early, just btrbk, no extra remounting etc.
112 -e) early=true ;;
113 # skip various checks. when we run twice in a row for
114 # switch mail-host, no need to repeat the same checks again.
115 --fast) fast=true ;;
116 -i) incremental_strict=true ;;
117 # note this implies resume
118 -k) kd_spread_maybe=true ;;
119 # bytes per second, suffix k m g
120 -l) rate_limit=$2; shift ;;
121 # Comma separated mountpoints to backup. This has defaults set below.
122 -m) IFS=, mountpoints=($2); unset IFS; shift ;;
123 -n) dry_run=true ;;
124 # hide progress
125 -p) progress_arg= ;;
126 # internal option for rerunning under newer SOURCE_HOST version.
127 --pull-reexec) pull_reexec=true;;
128 # quiet
129 -q) verbose=false; verbose_arg=; progress_arg= ;;
130 # source host to receive a backup from
131 -s)
132 source=$2
133 bbksource=$source
134 if [[ $source == *:* ]]; then
135 bbksource="[$source]"
136 fi
137 shift
138 ;;
139 # target hosts to send to. empty is valid for just doing local
140 # snapshot. we have default hosts we will populate.
141 -t) IFS=, targets=($2); unset IFS; shift ;;
142 # verbose.
143 -v) verbose=true; verbose_arg=-v ;;
144 -h|--help) usage ;;
145 --) shift; break ;;
146 *) die "Internal error!" ;;
147 esac
148 shift
149 done
150
151 cmd_arg="$1"
152
153 if $kd_spread_maybe; then
154 if [[ $cmd_arg && $cmd_arg != resume ]]; then
155 die "dont pass -k without resume or empty run arg"
156 fi
157 cmd_arg=resume
158 fi
159
160 if [[ ! $cmd_arg ]]; then
161 cmd_arg=run
162 fi
163
164
165 std_preserve="36h 14d 8w 24m"
166 q_preserve="18h 14d 8w"
167
168 case $cmd_arg in
169 run|resume) : ;;
170
171 # This works better than the normal archive command. We have to
172 # specify the mount points, but that is what we are used to doing and
173 # we prefer it. Another difference is that archive works recursively
174 # and we don't care about that. Sometimes we may still want to run
175 # btrbk archive, but it doesn't even use the config file, so just
176 # run it directly, eg:
177 # time s btrbk -v archive /mnt/r7/amy/boot/btrbk ssh://bo/mnt/boot2/btrbk
178 archive)
179 cmd_arg=resume
180 std_preserve="999h 999d 999w 999m"
181 q_preserve="$std_preserve"
182 preserve_arg=-p
183 ;;
184 *) die "untested command arg" ;;
185 esac
186
187 if (( $# > 1 )); then
188 die: "only 1 nonoption arg is supported"
189 fi
190
191 if [[ -v targets && $source ]]; then
192 # note, this doesnt need to be the case, but
193 # we would need to think about it.
194 die "error: -t and -s are mutually exclusive"
195 fi
196
197 ### end options parsing
198
199 # remove path from earlier version of btrbk
200 rm -f /usr/sbin/btrbk
201 # note, this still works as intended if there is no /usr/bin/btrbk
202 if [[ /a/opt/btrbk/btrbk -nt /usr/bin/btrbk ]]; then
203 if [[ -e /b/distro-functions/src/package-manager-abstractions ]]; then
204 . /b/distro-functions/src/package-manager-abstractions
205 pi asciidoctor
206 fi
207 cd /a/opt/btrbk
208 m make install
209 fi
210
211 # TODO: i wonder if there should be an option to send to the default
212 # targets, plus any given on the command line.
213
214
215
216 kd_spread=false
217 # set default targets
218 if [[ ! -v targets && ! $source ]]; then
219 if $cron; then
220 if [[ $HOSTNAME != "$MAIL_HOST" ]]; then
221 if $kd_spread_maybe && [[ $HOSTNAME == kd && $MAIL_HOST == x3 ]]; then
222 if ping -q -c1 -w1 x3.office.fsf.org &>/dev/null; then
223 work_host=x3.office.fsf.org
224 elif ping -q -c1 -w1 x3wg.b8.nz &>/dev/null; then
225 work_host=x3wg.b8.nz
226 fi
227 if [[ $work_host ]]; then
228 source_state="$(ssh $work_host cat /a/bin/bash_unpublished/source-state)"
229 eval "$source_state"
230 if [[ $MAIL_HOST == x3 ]]; then
231 kd_spread=true
232 else
233 # x3 was the mail host, but it moved to some other machine
234 # without updating us yet.
235 echo "MAIL_HOST=$MAIL_HOST, nothing to do"
236 mexit 0
237 fi
238 else
239 echo "MAIL_HOST=$MAIL_HOST, nothing to do"
240 mexit 0
241 fi
242 else
243 echo "MAIL_HOST=$MAIL_HOST, nothing to do"
244 mexit 0
245 fi
246 fi
247 fi
248
249 at_work=false
250 at_home=false
251
252 case $HOSTNAME in
253 kw|kd|frodo|x2|x3|sy) : ;;
254 *)
255 die "error: no default targets for this host, use -t"
256 ;;
257 esac
258
259 case $HOSTNAME in
260 kw)
261 at_work=true
262 ;;&
263 kd|frodo)
264 at_home=true
265 ;;&
266 x2|x3|sy)
267 if [[ $(dig +short @10.2.0.1 -x 10.2.0.2 2>&1 ||:) == kd.b8.nz. ]] \
268 && ip n show 10.2.0.1 | grep . &>/dev/null; then
269 at_home=true
270 elif ping -q -c1 -w1 hal.office.fsf.org &>/dev/null \
271 && ip n show 192.168.0.26 | grep . &>/dev/null; then
272 at_work=true
273 fi
274 ;;&
275 *)
276 if $at_home; then
277 if ! $kd_spread && [[ $HOSTNAME != x3 ]]; then
278 # main work machine
279 if ping -q -c1 -w1 x3.office.fsf.org &>/dev/null; then
280 targets+=(x3.office.fsf.org)
281 elif ping -q -c1 -w1 $h.b8.nz &>/dev/null; then
282 # in case we took it home
283 targets+=(x3.b8.nz)
284 else
285 targets+=(x3wg.b8.nz)
286 fi
287 fi
288 # temporarily disabled while doing recovery
289 # for h in frodo kd; do
290 for h in kd; do
291 if [[ $HOSTNAME == "$h" ]]; then
292 continue
293 fi
294 targets+=($h.b8.nz)
295 done
296 for h in x2 sy; do
297 if [[ $HOSTNAME == "$h" ]]; then
298 continue
299 fi
300 if ping -q -c1 -w1 $h.b8.nz &>/dev/null; then
301 targets+=($h.b8.nz)
302 elif ping -q -c1 -w1 ${h}w.b8.nz &>/dev/null; then
303 targets+=(${h}w.b8.nz)
304 fi
305 done
306 elif $at_work; then
307 targets+=(i.b8.nz)
308 for h in x2 x3 kw; do
309 if [[ $HOSTNAME == "$h" ]]; then
310 continue
311 fi
312 if ping -q -c1 -w1 $h.office.fsf.org &>/dev/null; then
313 targets+=($h.office.fsf.org)
314 fi
315 done
316 else
317 targets+=(i.b8.nz)
318 fi
319 ;;
320 esac
321 fi
322
323 if [[ ${mountpoints[0]} ]]; then
324 for mp in ${mountpoints[@]}; do
325 if [[ -e /nocow/btrfs-stale/$mp ]]; then
326 die "error: $mp is stale, mount-latest-subvol first"
327 fi
328 done
329 else
330 # set default mountpoints
331 if [[ ${targets[0]} == tp ]]; then
332 prospective_mps=(/a)
333 else
334 case $HOSTNAME in
335 *)
336 prospective_mps=()
337 if [[ $source ]]; then
338 source_state="$(ssh $source cat /a/bin/bash_unpublished/source-state)"
339 eval "$source_state"
340 source_host="$(ssh $source cat /etc/hostname)"
341 if [[ $source_host == "$MAIL_HOST" ]]; then
342 prospective_mps+=(/o)
343 fi
344 if [[ $source_host == "$HOST2" ]]; then
345 prospective_mps+=(/a /ar /qr /q)
346 fi
347 else
348 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
349 prospective_mps+=(/o)
350 fi
351 if [[ $HOSTNAME == "$HOST2" ]]; then
352 prospective_mps+=(/a /ar /qr /q)
353 fi
354 if $kd_spread; then
355 prospective_mps=(/a /ar /o /qr /q)
356 fi
357 fi
358 # note: put q last just in case its specific retention options were to
359 # affect other config sections. I havent tested if that is the case.
360 ;;
361 esac
362 fi
363 for mp in ${prospective_mps[@]}; do # default mountpoints to sync
364 if [[ -e /nocow/btrfs-stale/$mp ]]; then
365 e "warning: $mp stale, not adding to default mountpoints"
366 continue
367 fi
368 if awk '{print $2}' /etc/fstab | grep -xF $mp &>/dev/null; then
369 mountpoints+=($mp)
370 fi
371 done
372 fi
373
374 if (( ! ${#mountpoints[@]} )); then
375 die didnt get mountpoint arg and had no defaults
376 fi
377
378 ##### end command line parsing ########
379
380 #### begin pre-checks #####
381
382 # todo: this has a timing problem, since btrbk.timer could activate the service after this check.
383 if ! $fast && [[ $source ]]; then
384 if [[ $(ssh $source ps --no-headers -o comm 1) == systemd ]]; then
385 status=$(ssh $source systemctl is-active btrbk.service) || : # normally returns 3
386 case $status in
387 inactive|failed) : ;;
388 *)
389 echo "$0: error: cron btrbk is running on source. exiting out of caution"
390 mexit 1
391 esac
392 fi
393 fi
394
395 if ! command -v btrbk &>/dev/null; then
396 die "error: no btrbk binary found"
397 fi
398
399
400 #### end pre-checks #####
401
402 mkdir -p /var/log/btrbk
403 # The journal doesnt go back to my oldest backups, and I've found myself
404 # wanting older logs. Not going to bother expiring old logs, since it is
405 # fine if they go back years.
406 log_path=/var/log/btrbk/$(date +%F_%T%:::z).log
407 echo copying output to $log_path
408 exec &> >(ts "%F %T" | tee -a $log_path)
409
410
411 if $verbose; then
412 printf "$pre options: conf_only=%s\ndry_run=%s\nrate_limit=%s\nverbose=%s\ncmd_arg=%s" "$conf_only" "$dry_run" "$rate_limit" "$verbose" "$cmd_arg"
413 fi
414
415 if [[ -v targets ]]; then
416 echo "targets: ${targets[*]}"
417 fi
418
419 if [[ $source ]]; then
420 echo "source: $source"
421 fi
422
423 echo "mountpoints: ${mountpoints[*]}"
424
425
426
427 # pull_reexec stops us from getting into an infinite loop if there is some
428 # kind of weird problem
429 pulla=false
430 for m in "${mountpoints[@]}"; do
431 if [[ $m == /a ]]; then
432 pulla=true
433 break
434 fi
435 done
436 if ! $pull_reexec && [[ $source ]] && $pulla ; then
437 tmpf=$(mktemp)
438 m rsync -ra $source:/usr/local/bin/{mount-latest-subvol,check-subvol-stale} /usr/local/bin
439 m rsync -ra $source:/usr/local/lib/err /usr/local/lib
440 m scp $source:/a/bin/distro-setup/btrbk-run $tmpf
441 if ! diff -q $tmpf ${BASH_SOURCE[0]}; then
442 e "found different version on host $source. reexecing"
443 install -T $tmpf /usr/local/bin/btrbk-run
444 m /usr/local/bin/btrbk-run --pull-reexec "${orig_args[@]}"
445 mexit 0
446 fi
447 fi
448
449
450 if ! $fast; then
451 # if our mountpoints are from stale snapshots,
452 # it doesn't make sense to do a backup.
453 m check-subvol-stale ${mountpoints[@]} || die "found stale mountpoints in ${mountpoints[*]}"
454
455 # for an initial run, btrbk requires the dir to exist.
456 mkdir -p /mnt/{root,o}/btrbk
457 fi
458 local_zone=$(date +%z)
459
460 if [[ $source ]]; then
461 if $fast; then
462 zone=$local_zone
463 else
464 if ! zone=$(ssh root@$source date +%z); then
465 if $conf_only; then
466 echo "$0: warning: failed to ssh to root@$source"
467 else
468 die failed to ssh to root@$source
469 fi
470 fi
471 if [[ $zone != "$local_zone" ]]; then
472 die "error: dont confuse yourself with multiple time zones. $h has different timezone than localhost"
473 fi
474 fi
475 else
476
477 sshable=()
478 sshfail=()
479 for h in ${targets[@]}; do
480 if $fast || $conf_only; then
481 # Use some typical values in this case
482 root_size=$(( 1024 * 1024 * 2000 )) #2tb
483 percent_used=10
484 zone=$(date +%z)
485 elif remote_str=$(timeout -s 9 6 ssh root@$h "mkdir -p /mnt/root/btrbk /mnt/o/btrbk && date +%z && df --output=size,pcent / | tail -n1"); then
486 mapfile -t tmp_array <<<"$remote_str"
487 zone="${tmp_array[0]}"
488 IFS=" " read -r root_size percent_used <<<"${tmp_array[1]}"
489 percent_used=${percent_used%%%}
490
491 if (( ${#tmp_array[@]} != 2 )); then
492 die "error: didnt get 2 lines in test ssh to target $h. investigate"
493 fi
494 case $percent_used in
495 [0-9]|[1-9][0-9]) : ;;
496 *)
497 die "error: didnt get percent disk use in test ssh to target $h. investigate"
498 ;;
499 esac
500 else
501 sshfail+=($h)
502 continue
503 fi
504
505 # we may be booted into a bootstrap fs or something
506 min_root_kb=$(( 1024 * 1024 * 200 )) # 200 gb
507 if (( root_size < min_root_kb )); then
508 continue
509 fi
510
511 if (( percent_used >= 98 )); then
512 die "error: filesystem on target $h is $percent_used % full"
513 fi
514
515 # on sy, xprintidle is resetting every 12 seconds even when not
516 # idle, i dunno why, instead we are checking if the screen is locked,
517 # which is good enough.
518 #
519 # This is a separate ssh because the command can fail and thatis ok.
520 if $cron; then
521 locked=false
522 if lock_info=$(timeout -s 9 6 ssh $h DISPLAY=:0 xscreensaver-command -time); then
523 if [[ $lock_info != *non-blanked* ]]; then
524 locked=true
525 fi
526 else
527 locked=true
528 fi
529 if ! $locked; then
530 # Ignore this host. i sometimes use a non-main machine for
531 # testing or web browsing, knowing that everything will be wiped
532 # by the next backup, but I dont want it to happen as Im using
533 # it from cronjob.
534 e "warning: $h: seems to be actively in use, skipping for now"
535 continue
536 fi
537 fi
538 sshable+=($h)
539 if [[ $zone != "$local_zone" ]]; then
540 die "error: dont confuse yourself with multiple time zones. $h has different timezone than localhost"
541 fi
542 done
543 if [[ ! ${sshable[*]} ]] || { ! $cron && [[ ${sshfail[*]} ]]; }; then
544 die "failed to ssh to hosts: ${sshfail[*]}"
545 else
546 if [[ ${sshfail[*]} ]]; then
547 ret=1
548 e "error: failed to ssh to ${sshfail[*]} but continuing with other hosts"
549 fi
550 targets=(${sshable[@]})
551 fi
552 fi
553
554
555 cat >/etc/btrbk$conf_suf.conf <<EOF
556 ssh_identity /q/root/h
557 #ssh_identity /root/.ssh/home
558
559 # Just a guess that local7 is a good facility to pick.
560 # It's a bit odd that the transaction log has to be logged to
561 # a file or syslog, while other output is sent to std out.
562 # The man does not mention a way for them to be together, but
563 # I dunno if setting a log level like warn might also output
564 # transaction info.
565 transaction_syslog local7
566
567 # trying this out
568 #stream_compress zstd
569
570 # so we only run one at a time
571 lockfile /var/lock/btrbk$conf_suf.lock
572
573 # default format of short does not accomidate hourly preservation setting
574 timestamp_format long-iso
575
576 # only make a snapshot if things have changed
577 snapshot_create onchange
578 # I could make this different from target_preserve,
579 # if one disk had less space.
580 # for now, keeping them equal.
581 snapshot_preserve $std_preserve
582 snapshot_preserve_min 6h
583 snapshot_dir btrbk
584 # so, total backups = ~58
585 target_preserve $std_preserve
586 target_preserve_min 6h
587
588 # i tried this when investigating: clone no source subvolume found error
589 #incremental_prefs sro:1 srn:1 sao san:1 aro:1 arn:1
590
591 # if something fails and it's not obvious, try doing
592 # btrbk -l debug -v dryrun
593
594 rate_limit $rate_limit
595 EOF
596
597 if $incremental_strict; then
598 cat >>/etc/btrbk$conf_suf.conf <<EOF
599 incremental strict
600 EOF
601 fi
602
603 qconf() {
604 case $sub in
605 q)
606 # q has sensitive data i dont want to backup for so long
607 cat >>/etc/btrbk$conf_suf.conf <<EOF
608 snapshot_preserve $q_preserve
609 snapshot_preserve_min 2h
610 snapshot_dir btrbk
611 target_preserve $q_preserve
612 target_preserve_min 2h
613 EOF
614 ;;
615 esac
616
617 }
618
619 # make /q be last
620 mp_count=${#mountpoints[@]}
621 for (( i=0; i < mp_count - 1 ; i++ )); do
622 if [[ ${mountpoints[i]} == /q ]]; then
623 unset "mountpoints[i]"
624 mountpoints+=(/q)
625 fi
626 done
627
628 for m in ${mountpoints[@]}; do
629 case $m in
630 /o)
631 vol=/mnt/o
632 ;;
633 *)
634 vol=/mnt/root
635 ;;
636 esac
637
638 sub=${m#/}
639 if [[ $source ]]; then
640 cat >>/etc/btrbk$conf_suf.conf <<EOF
641 volume ssh://$bbksource$vol
642 subvolume $sub
643 EOF
644 qconf
645 cat >>/etc/btrbk$conf_suf.conf <<EOF
646 target send-receive $vol/btrbk
647 EOF
648 fi
649 if (( ${#targets[@]} )); then
650 cat >>/etc/btrbk$conf_suf.conf <<EOF
651 volume $vol
652 subvolume $sub
653 EOF
654 qconf
655 for tg in ${targets[@]}; do
656 # handle ipv6
657 if [[ $tg == *:* ]]; then
658 tg="[$tg]"
659 fi
660 cat >>/etc/btrbk$conf_suf.conf <<EOF
661 target send-receive ssh://$tg$vol/btrbk
662 EOF
663 done
664 fi
665 done
666
667 # todo: umount first to ensure we don't have any errors
668 # todo: do some kill fuser stuff to make umount more reliable
669
670
671 if $conf_only; then
672 mexit 0
673 fi
674
675
676
677 if $dry_run; then
678 m btrbk -c /etc/btrbk$conf_suf.conf -v -n $cmd_arg
679 mexit 0
680 fi
681 # -q and just using the syslog option seemed nice,
682 # but it doesn't show when a send has a parent and when it doesn't.
683 m btrbk -c /etc/btrbk$conf_suf.conf $preserve_arg $verbose_arg $progress_arg $cmd_arg
684
685 if $early; then
686 exit 0
687 fi
688
689 # todo: tp not valid anymore.
690 # if we have it, sync to systems which don't
691 if mountpoint $rsync_mountpoint >/dev/null; then
692 for tg in ${targets[@]}; do
693 case $tg in
694 tp)
695 dirs=(/p/c/machine_specific/tp)
696 for x in /p/c/machine_specific/*.hosts; do
697 if grep -qxF $tg $x; then
698 dirs+=(${x%.hosts})
699 fi
700 done
701 m rsync -aSAXPH --specials --devices --delete --relative ${dirs[@]} root@$tg:/
702 ;;
703 esac
704 done
705 fi
706
707 subvols=()
708 for mp in "${mountpoints[@]}"; do
709 subvols+=("${mp##*/}")
710 done
711 if [[ $source ]]; then
712 m mount-latest-subvol "${subvols[@]}"
713 else
714 for tg in ${targets[@]}; do
715 m /a/exe/mount-latest-remote "$tg" "${subvols[@]}" || ret=$?
716 done
717 fi
718
719 if [[ $ret == 0 ]]; then
720 for tg in ${targets[@]}; do
721 h=$(ssh root@$tg hostname)
722 rsync -a /var/log/btrbk $tg:/var/log/btrbk/$tg
723 ssh root@$tg /usr/local/bin/mail-backup-clean
724 done
725 if [[ $source ]]; then
726 rsync -a $source:/var/log/btrbk /var/log/btrbk/$source
727 fi
728 fi
729
730 mexit $ret
731
732 # todo: move variable data we don't care about backing up
733 # to /nocow and symlink it.
734
735
736 # background on btrbk timezones. with short/long, timestamps use local time.
737 # for long, if your local time moves backwards, by moving timezones or
738 # for an hour when daylight savings changes it, you will temporarily get
739 # a more aggressive retention policy for the overlapping period, and
740 # vice versa for the opposite timezone move. The alternative is using
741 # long-iso, which puts timezone info into the timestamp, which means
742 # that instead of shifting time, you shift the start of day/week/month
743 # which is used for retention to your new local time, which means for
744 # example, if you moved forward by 8 hours, the daily/weekly/monthly
745 # retention will be 8 hours more aggressive since midnight is at a new
746 # time, unless you fake the timzeone using the TZ env variable.
747 # However, in the short term, there will be no inconsistencies.
748 # I don't see any problem with shifting when the day starts for
749 # retention, so I'm using long-iso.
750
751 # note to create a long-iso timestamp: date +%Y%m%dT%H%M%S%z