3 # Configure & run btrbk & related work on Ian's computers.
4 # Copyright (C) 2024 Ian Kelling
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # SPDX-License-Identifier: GPL-3.0-or-later
22 # todo: if we cancel in the middle of a btrfs send, then run again
23 # immediately, the received subvolume doesn't get a Received UUID:
24 # field, and we won't mount it. Need to figure out a solution that will
28 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
30 set -e; .
/usr
/local
/lib
/bash-bear
; set +e
35 btrbk-run [OPTIONS] [run|resume|archive]
36 usually -t TARGET_HOST or -s SOURCE_HOST
38 Note, at source location, intentionally not executable, run and read
42 echo "top of script file:"
43 sed -n '1,/^[# ]*end command line/{p;b};q' "$0"
53 script_name
="${BASH_SOURCE[0]}"
54 script_name
="${script_name##*/}"
58 if [[ ! $log_path ]]; then
59 mkdir
-p /var
/log
/btrbk
60 log_path
=/var
/log
/btrbk
/$
(date +%F_
%T
%:::z
).log
64 if $dry_run ||
$conf_only; then
65 printf "$pre dry-run: %s\n" "$*"
68 printf "$pre running: %s\n" "$*" |
& pee
cat 'ts "%F %T" >>'$log_path
69 "$@" |
& pee
cat 'ts "%F %T" >>'$log_path
72 m
() { if $verbose; then printf "$pre %s\n" "$*"; fi; "$@"; }
73 e
() { printf "$pre %s\n" "$*"; }
79 printf "$pre running: %s\n" "$*" | pee
cat 'ts "%F %T" >>'$log_path
80 e logging to
$log_path
81 "$@" |
& ts
"%F %T" >>$log_path || exit_code
=$?
82 printf "$pre exit code:%s of %s\n" "$exit_code" "$*" | pee
cat 'ts "%F %T" >>'$log_path
83 if (( exit_code
> 0 )); then
84 e
"error: command exit code: $exit_code. exiting after tail -n50 $log_path"
90 die
() { printf "$pre error: %s\n" "$*" >&2; echo "$pre exiting with status 1" >&2; exit 1; }
91 mexit
() { echo "$pre exiting with status $1"; exit $1; }
93 uninstalled-file-die
() {
94 die
"file $1 is not latest. run install-my-scripts or rerun with -f"
106 if [[ $
(timeout
1 dig +short @
10.2.0.1 -x 10.2.0.2 2>&1 ||
:) == kd.b8.nz.
]] \
107 && ip n show
10.2.0.1 |
grep .
&>/dev
/null
; then
108 # note: logic duplicated in 11-iank
110 elif ping -q -c1 -w1 hal.office.fsf.org
&>/dev
/null \
111 && ip n show
192.168.0.26 |
grep .
&>/dev
/null
; then
118 exit-if-no-default-targets
() {
119 if ! $force && [[ $HOSTNAME != "$MAIL_HOST" ]]; then
120 echo "MAIL_HOST=$MAIL_HOST, nothing to do"
124 kw|kd|frodo|x2|x3|sy|so
) : ;;
126 die
"error: no default targets for this host, use -t"
133 if ping -q -c1 -w1 x3.office.fsf.org
&>/dev
/null
; then
134 targets
+=(x3.office.fsf.org
)
135 elif ping -q -c1 -w1 x3.b8.nz
&>/dev
/null
; then
136 # in case we took it home
138 elif ping -q -c1 -w1 x3w.b8.nz
&>/dev
/null
; then
141 targets
+=(x3wg.b8.nz
)
145 add-wireless-target
() {
151 # c = cabled, w = wireless
152 if ping -q -c1 -w1 ${host}c.b8.nz
&>/dev
/null
; then
153 targets
+=(${host}c.b8.nz
)
154 elif ping -q -c1 -w1 $host.b8.nz
&>/dev
/null
; then
155 targets
+=($host.b8.nz
)
156 elif ping -q -c1 -w1 ${host}w.b8.nz
&>/dev
/null
; then
157 targets
+=(${host}w.b8.nz
)
165 # q has sensitive data i dont want to backup for so long
166 cat >>/etc
/btrbk
$conf_suf.conf
<<EOF
167 snapshot_preserve $q_preserve
168 snapshot_preserve_min 2h
170 target_preserve $q_preserve
171 target_preserve_min 2h
180 if [[ -e /b
/bash_unpublished
/source-state
]]; then
181 source /b
/bash_unpublished
/source-state
184 # note q is owned by root:1000
193 dry_run
=false
# mostly for testing
195 verbose
=true
; verbose_arg
="-l trace"
197 if [[ $PPID == 1 ]]; then
198 # running as a service. we cant show progress in this case,
199 # but if we pass the arg, it will insert mbuffer into the command.
202 progress_arg
="--progress"
204 incremental_strict
=false
207 default_args_file
=/etc
/btrbk-run.conf
208 if [[ -s $default_args_file ]]; then
209 # shellcheck disable=SC2046 # we want word splitting
210 set -- $
(< $default_args_file) "$@"
211 # i havent used this feature yet, so warn about it
212 echo "$0: warning: default btrbk-run options set in $default_args_file (sleeping 5 seconds):"
213 cat $default_args_file
217 once_args_file
=/etc
/btrbk-run-once.conf
218 if mv -f $once_args_file $once_args_file-tmp 2> >(sed '/No such file or directory/d'); then
219 # shellcheck disable=SC2046 # we want word splitting
220 set -- $
(< $once_args_file-tmp) "$@"
221 # i havent used this feature yet, so warn about it
222 echo "$0: btrbk-run options set in $once_args_file:"
223 cat $once_args_file-tmp
224 rm -f $once_args_file-tmp
232 check_installed
=false
234 temp
=$
(getopt
-l check-installed
,fast
,pull-reexec
,help 23acefikl
:m
:npqrs
:t
:vh
"$@") || usage
1
238 # for the rare case we want to run multiple instances at the same time
243 mountpoints
=(/a
/o
/qr
/qd
/q
)
245 # only creates the config file, does not run btrbk
246 -c) conf_only
=true
;;
250 # quit early, just btrbk, no extra remounting etc.
252 # avoids some default behaviors:
253 # - no skipping hosts where xprintidle haven't been idle recently
254 # - exit if we can't ssh to 1 or more hosts
255 # - still set default hosts despite MAIL_HOST status
257 # skip various checks. when we run twice in a row for
258 # switch mail-host, no need to repeat the same checks again.
260 -i) incremental_strict
=true
;;
261 # note this implies resume and -p because it is just meant to make
262 # other hosts have the same snapshots, not do any expiry or new
264 -k) kd_spread
=true
;;
265 # bytes per second, suffix k m g
266 -l) rate_limit
=$2; shift ;;
267 # Comma separated mountpoints to backup. This has defaults set below.
268 -m) IFS
=, mountpoints
=($2); unset IFS
; shift ;;
270 # preserve existing snapshots and backups
271 -p) preserve_arg
=-p ;;
272 # internal option for rerunning under newer SOURCE_HOST version.
273 --pull-reexec) pull_reexec
=true
;;
275 -q) verbose
=false
; verbose_arg
=; progress_arg
= ;;
276 # source host to receive a backup from
280 if [[ $source == *:* ]]; then
281 bbksource
="[$source]"
285 # target hosts to send to. empty is valid for just doing local
286 # snapshot. we have default hosts we will populate.
287 -t) IFS
=, targets
=($2); unset IFS
; shift ;;
290 verbose
=true
; verbose_arg
="-l trace"
294 *) die
"Internal error!" ;;
303 if ! $force && { $check_installed ||
[[ ! $source ]]; } ; then
309 for f
in ${install_bin_files[@]}; do
310 if ! diff -q /a
/bin
/ds
/$f /usr
/local
/bin
/$f; then
311 uninstalled-file-die
$f
314 if ! diff -q /a
/bin
/bash-bear-trap
/bash-bear
/usr
/local
/lib
/bash-bear
; then
315 uninstalled-file-die bash-bear
317 if $check_installed; then
324 if [[ $cmd_arg && $cmd_arg != resume
]]; then
325 die
"dont pass -k without resume or empty run arg"
327 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
328 die
"something went wrong, -k not meant to be run on MAIL_HOST"
330 if [[ $HOSTNAME != kd
]]; then
331 die
"something went wrong, -k only meant to run on kd"
335 add-wireless-target sy so
338 if [[ ! $cmd_arg ]]; then
343 std_preserve
="36h 14d 8w 24m"
344 q_preserve
="18h 14d 8w"
349 # This works better than the normal archive command. We have to
350 # specify the mount points, but that is what we are used to doing and
351 # we prefer it. Another difference is that archive works recursively
352 # and we don't care about that. Sometimes we may still want to run
353 # btrbk archive, but it doesn't even use the config file, so just
354 # run it directly, eg:
355 # time s btrbk -v archive /mnt/r7/amy/boot/btrbk ssh://bo/mnt/boot2/btrbk
358 std_preserve
="999h 999d 999w 999m"
359 q_preserve
="$std_preserve"
362 *) die
"untested command arg" ;;
365 if (( $# > 1 )); then
366 die
: "only 1 nonoption arg is supported"
369 if [[ -v targets
&& $source ]]; then
370 # note, this doesnt need to be the case, but
371 # we would need to think about it.
372 die
"error: -t and -s are mutually exclusive"
375 ### end options parsing
377 # remove path from earlier version of btrbk
378 rm -f /usr
/sbin
/btrbk
379 # note, this still works as intended if there is no /usr/bin/btrbk
380 if [[ /a
/opt
/btrbk
/btrbk
-nt /usr
/bin
/btrbk
]]; then
381 if [[ -e /b
/distro-functions
/src
/package-manager-abstractions
]]; then
382 .
/b
/distro-functions
/src
/package-manager-abstractions
390 # TODO: i wonder if there should be an option to send to the default
391 # targets, plus any given on the command line.
398 # set default targets
399 if [[ ! -v targets
&& ! $source ]]; then
400 exit-if-no-default-targets
403 if ! $kd_spread && [[ $HOSTNAME != x3
]]; then
406 if [[ $HOSTNAME != kd
]]; then
409 wireless_home_hosts
=(
414 for h
in ${wireless_home_hosts[@]}; do
415 if [[ $HOSTNAME != "$h" ]]; then
421 for h
in x2 x3 kw
; do
422 if [[ $HOSTNAME == "$h" ]]; then
425 if ping -q -c1 -w1 $h.office.fsf.org
&>/dev
/null
; then
426 targets
+=($h.office.fsf.org
)
434 if [[ ${mountpoints[0]} ]]; then
435 for mp
in ${mountpoints[@]}; do
436 if [[ -e /nocow
/btrfs-stale
/$mp ]]; then
437 die
"error: $mp is stale, mount-latest-subvol first"
441 # set default mountpoints
442 if [[ ${targets[0]} == tp
]]; then
448 if [[ $source ]]; then
449 source_state
="$(ssh $source 'cat /a/bin/bash_unpublished/source-state; echo source_host=$HOSTNAME')"
451 # shellcheck disable=SC2154 # assigned in the above eval.
452 if [[ $source_host == "$MAIL_HOST" ]]; then
453 prospective_mps
+=(/o
)
455 if [[ $source_host == "$HOST2" ]]; then
456 prospective_mps
+=(/a
/qr
/qd
/q
)
459 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
460 prospective_mps
+=(/o
)
462 if [[ $HOSTNAME == "$HOST2" ]]; then
463 prospective_mps
+=(/a
/qr
/qd
/q
)
466 prospective_mps
=(/a
/o
/qr
/qd
/q
)
469 # note: put q last just in case its specific retention options were to
470 # affect other config sections. I havent tested if that is the case.
474 for mp
in ${prospective_mps[@]}; do # default mountpoints to sync
475 if [[ -e /nocow
/btrfs-stale
/$mp ]]; then
476 e
"warning: $mp stale, not adding to default mountpoints"
479 if awk '{print $2}' /etc
/fstab |
grep -xF $mp &>/dev
/null
; then
485 tmp
=$
(( ${#mountpoints[@]} == 0 ))
487 die didnt get mountpoint arg and had no defaults
490 ##### end command line parsing ########
492 #### begin pre-checks #####
494 # todo: this has a timing problem, since btrbk.timer could activate the service after this check.
495 if ! $fast && [[ $source ]]; then
496 if [[ $
(ssh $source ps
--no-headers -o comm 1) == systemd
]]; then
497 status
=$
(ssh $source systemctl is-active btrbk.service
) ||
: # normally returns 3
499 inactive|failed
) : ;;
501 echo "$0: error: btrbk is running on source. exiting out of caution"
507 if ! command -v btrbk
&>/dev
/null
; then
508 die
"error: no btrbk binary found"
511 # pull_reexec stops us from getting into an infinite loop if there is some
512 # kind of weird problem
514 for m
in "${mountpoints[@]}"; do
515 if [[ $m == /a
]]; then
521 if ! $pull_reexec && [[ $source ]] && $pulla && ! $force ; then
522 ssh root@
$source btrbk-run
--check-installed
525 #### end pre-checks #####
530 # print some non-default opts
533 if ! $conf_only; then
534 opts_show
+=(conf_only
=true
)
537 opts_show
+=(dry_run
=true
)
539 if [[ $rate_limit != no
]]; then
540 opts_show
+=("rate_limit=$rate_limit")
542 if [[ $cmd_arg != run
]]; then
543 opts_show
+=(cmd_arg
=$cmd_arg)
545 if (( ${#opts_show[@]} >= 1 )); then
547 for opt
in ${opts_show[@]}; do
560 if ! $pull_reexec && [[ $source ]] && $pulla ; then
562 m rsync
-ra $source:/usr
/local
/bin
/{mount-latest-subvol
,check-subvol-stale
} /usr
/local
/bin
563 m rsync
-ra $source:/usr
/local
/lib
/bash-bear
/usr
/local
/lib
564 m scp
$source:/a
/bin
/distro-setup
/btrbk-run
$tmpf
565 if ! diff -q $tmpf ${BASH_SOURCE[0]}; then
566 e
"found different version on host $source. reexecing"
567 install -T $tmpf /usr
/local
/bin
/btrbk-run
568 m
/usr
/local
/bin
/btrbk-run
--pull-reexec "${orig_args[@]}"
574 if [[ -v targets
]]; then
575 echo "targets: ${targets[*]}"
577 if [[ $source ]]; then
578 echo "source: $source"
580 echo "mountpoints: ${mountpoints[*]}"
583 # todo: check if we have no snapshots yet, because I always want to run
584 # archive instead of run. Likely, I should give an error unless a cli
585 # override is passed. perhaps check-subvol-stale could give the error.
586 # see the error message "no snapshots found" in that file.
588 # if our mountpoints are from stale snapshots,
589 # it doesn't make sense to do a backup.
590 m check-subvol-stale
${mountpoints[@]} || die
"found stale mountpoints in ${mountpoints[*]}"
592 # for an initial run, btrbk requires the dir to exist.
593 mkdir
-p /mnt
/{root
,o
}/btrbk
595 local_zone
=$
(date +%z
)
597 if [[ $source ]]; then
601 if ! zone
=$
(ssh root@
$source date +%z
); then
603 echo "$0: warning: failed to ssh to root@$source"
605 die failed to
ssh to root@
$source
608 if [[ $zone != "$local_zone" ]]; then
609 die
"error: dont confuse yourself with multiple time zones. $h has different timezone than localhost"
616 remote_str_cmd
="mkdir -p /mnt/root/btrbk /mnt/o/btrbk && \
618 df --output=size,pcent / | tail -n1"
620 for h
in ${targets[@]}; do
621 if $fast ||
$conf_only; then
622 # Use some typical values in this case
623 root_size
=$
(( 1024 * 1024 * 2000 )) #2tb
626 elif remote_str
=$
(timeout
-s 9 6 ssh root@
$h "$remote_str_cmd"); then
627 mapfile
-t tmp_array
<<<"$remote_str"
628 zone
="${tmp_array[0]}"
629 IFS
=" " read -r root_size percent_used
<<<"${tmp_array[1]}"
630 percent_used
=${percent_used%%%}
632 tmp
=$
(( ${#tmp_array[@]} != 2 ))
634 die
"error: didnt get 2 lines in test ssh to target $h. investigate"
636 case $percent_used in
637 [0-9]|
[1-9][0-9]) : ;;
639 die
"error: didnt get percent disk use in test ssh to target $h. investigate"
647 # we may be booted into a bootstrap fs or something
648 min_root_kb
=$
(( 1024 * 1024 * 200 )) # 200 gb
649 tmp
=$
(( root_size
< min_root_kb
))
651 e
"warning: $h: root_size=$root_size < 200gb, perhaps it is booted to bootstrap vol. skipping for now"
655 tmp
=$
(( percent_used
>= 98 ))
657 die
"error: filesystem on target $h is $percent_used % full"
660 # on sy, xprintidle is resetting every 12 seconds even when not
661 # idle, i dunno why, instead we are checking if the screen is locked,
662 # which is good enough.
664 # This is a separate ssh because the command can fail and thatis ok.
667 if lock_info
=$
(timeout
-s 9 6 ssh $h DISPLAY
=:0 xscreensaver-command
-time); then
668 if [[ $lock_info != *non-blanked
* ]]; then
675 # Ignore this host. i sometimes use a non-main machine for
676 # testing or web browsing, knowing that everything will be wiped
677 # by the next backup, but I dont want it to happen as Im using
679 e
"warning: $h: seems to be actively in use, skipping for now"
684 if [[ $zone != "$local_zone" ]]; then
685 die
"error: dont confuse yourself with multiple time zones. $h has different timezone than localhost"
688 if [[ ! ${sshable[*]} ]] || { $force && [[ ${sshfail[*]} ]]; }; then
689 die
"see skipped host warning above or sshfail hosts: ${sshfail[*]}"
691 if [[ ${sshfail[*]} ]]; then
693 e
"error: failed to ssh to ${sshfail[*]} but continuing with other hosts"
695 targets
=(${sshable[@]})
700 cat >/etc
/btrbk
$conf_suf.conf
<<EOF
701 ssh_identity /q/root/h
702 #ssh_identity /root/.ssh/home
705 #stream_compress zstd
707 # so we only run one at a time
708 lockfile /var/lock/btrbk$conf_suf.lock
710 # default format of short does not accomidate hourly preservation setting
711 timestamp_format long-iso
713 # only make a snapshot if things have changed
714 snapshot_create onchange
715 # I could make this different from target_preserve,
716 # if one disk had less space.
717 # for now, keeping them equal.
718 snapshot_preserve $std_preserve
719 snapshot_preserve_min 6h
721 # so, total backups = ~58
722 target_preserve $std_preserve
723 target_preserve_min 6h
725 # it seems very likely that not doing this could result in clone source not found
726 # errors, for example when expiry happens differently on different hosts,
727 # also, as btrbk does by default, if a failed send happens, on the next run it
728 # will warn about a stray subvolume, but then create a backup of a newer subvol
729 # and use an older subvol as the parent.
730 incremental_prefs sao:1
732 # if something fails and it's not obvious, try doing
733 # btrbk -l trace -v dryrun
735 rate_limit $rate_limit
738 if $incremental_strict; then
739 cat >>/etc
/btrbk
$conf_suf.conf
<<EOF
746 mp_count
=${#mountpoints[@]}
747 for (( i
=0; i
< mp_count
- 1 ; i
++ )); do
748 if [[ ${mountpoints[i]} == /q
]]; then
749 unset "mountpoints[i]"
758 declare -A source_snaps
760 for m
in ${mountpoints[@]}; do
771 snap_list_cmds
+=("echo $vol/btrbk/$sub.*;")
773 if [[ $source ]]; then
774 tmp_a
=($vol/btrbk
/$sub.
*)
775 tg_snaps
+=("${tmp_a[*]}")
776 cat >>/etc
/btrbk
$conf_suf.conf
<<EOF
777 volume ssh://$bbksource$vol
781 cat >>/etc
/btrbk
$conf_suf.conf
<<EOF
782 target send-receive $vol/btrbk
784 else # we have targets
785 for snap
in "$vol/btrbk/$sub."*; do
786 source_snaps
[$snap]=t
789 cat >>/etc
/btrbk
$conf_suf.conf
<<EOF
794 for tg
in ${targets[@]}; do
796 if [[ $tg == *:* ]]; then
799 cat >>/etc
/btrbk
$conf_suf.conf
<<EOF
800 target send-receive ssh://$tg$vol/btrbk
806 # Delete any subvols on the receiving host that don't exist on the
807 # sending host. Otherwise, the receiving host could have snapshots that
808 # aren't on the sending side, and thus become odd leaf subvols, and then
809 # btrbk could try to use them when we sync back, creating a weird tree
810 # instead of linear parent/child relationship. Maybe this could lead to
811 # a missing source subvol error, so lets avoid it.
813 get-orphan-tg-snaps
() {
815 for (( i
=0; i
< ${#mountpoints[@]}; i
++ )); do
816 orphan_start_count
=${#orphan_tg_snaps[@]}
818 for tg_snap
in ${tg_snaps[$i]}; do
819 tg_snap_count
=$
(( tg_snap_count
+ 1 ))
820 if [[ ! ${source_snaps[$tg_snap]} ]]; then
821 orphan_tg_snaps
+=("$tg_snap")
824 orphan_mp_count
=$
(( ${#orphan_tg_snaps[@]} - orphan_start_count
))
826 tmp
=$
(( tg_snap_count
> 1 && tg_snap_count
== orphan_mp_count
))
828 die
"something went wrong checking orphans on $tg: for mountpoint ${mountpoints[$i]}, $orphan_mp_count"
833 if [[ $source ]]; then
834 for snap
in $
(ssh root@
$source "shopt -s nullglob; ${snap_list_cmds[*]}"); do
835 source_snaps
[$snap]=t
838 tmp
=$
(( ${#orphan_tg_snaps[*]} >= 1 ))
840 d btrfs sub del
${orphan_tg_snaps[*]}
842 else # we have targets
843 for tg
in ${targets[@]}; do
844 tmp_str
=$
(ssh root@
$tg "shopt -s nullglob; ${snap_list_cmds[*]}")
845 mapfile
-t tg_snaps
<<<"$tmp_str"
847 tmp
=$
(( ${#orphan_tg_snaps[*]} >= 1 ))
849 d
ssh root@
$tg "btrfs sub del ${orphan_tg_snaps[*]}"
854 # todo: umount first to ensure we don't have any errors
855 # todo: do some kill fuser stuff to make umount more reliable
865 m btrbk
-c /etc
/btrbk
$conf_suf.conf
-v -n $cmd_arg
868 # -q and just using the syslog option seemed nice,
869 # but it doesn't show when a send has a parent and when it doesn't.
870 logq btrbk
-c /etc
/btrbk
$conf_suf.conf
$preserve_arg $verbose_arg $progress_arg $cmd_arg
876 # todo: tp not valid anymore.
877 # if we have it, sync to systems which don't
878 if mountpoint
$rsync_mountpoint >/dev
/null
; then
879 for tg
in ${targets[@]}; do
882 dirs=(/p
/c
/machine_specific
/tp
)
883 for x
in /p
/c
/machine_specific
/*.hosts
; do
884 if grep -qxF $tg $x; then
888 m rsync
-aSAXPH --specials --devices --delete --relative ${dirs[@]} root@
$tg:/
895 for mp
in "${mountpoints[@]}"; do
896 subvols
+=("${mp##*/}")
898 if [[ $source ]]; then
899 d mount-latest-subvol
"${subvols[@]}"
901 for tg
in ${targets[@]}; do
902 d
/a
/exe
/mount-latest-remote
"$tg" "${subvols[@]}" || ret
=$?
906 # todo, we get hostnames earlier, reuse that.
907 if [[ $ret == 0 ]]; then
908 for tg
in ${targets[@]}; do
909 h
=$
(ssh $tg hostname
)
910 if [[ $h == kd
&& $HOSTNAME == x3
&& $HOSTNAME == "$MAIL_HOST" ]]; then
911 d
ssh root@
$tg 'btrbk-spread-wrap &>/dev/null </dev/null &'
913 rsync
--mkpath -a -f"- */" -f"+ *" /var
/log
/btrbk
/ root@
$tg:/var
/log
/btrbk
/$tg
914 cmd
=/usr
/local
/bin
/mail-backup-clean
915 ssh root@
$tg "if test -x $cmd; then $cmd; fi"
917 if [[ $source ]]; then
918 rsync
--mkpath -a -f"- */" -f"+ *" $source:/var
/log
/btrbk
/ /var
/log
/btrbk
/$source
924 # todo: move variable data we don't care about backing up
925 # to /nocow and symlink it.
928 # background on btrbk timezones. with short/long, timestamps use local time.
929 # for long, if your local time moves backwards, by moving timezones or
930 # for an hour when daylight savings changes it, you will temporarily get
931 # a more aggressive retention policy for the overlapping period, and
932 # vice versa for the opposite timezone move. The alternative is using
933 # long-iso, which puts timezone info into the timestamp, which means
934 # that instead of shifting time, you shift the start of day/week/month
935 # which is used for retention to your new local time, which means for
936 # example, if you moved forward by 8 hours, the daily/weekly/monthly
937 # retention will be 8 hours more aggressive since midnight is at a new
938 # time, unless you fake the timzeone using the TZ env variable.
939 # However, in the short term, there will be no inconsistencies.
940 # I don't see any problem with shifting when the day starts for
941 # retention, so I'm using long-iso.
943 # note to create a long-iso timestamp: date +%Y%m%dT%H%M%S%z