4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
6 [[ $EUID == 0 ]] ||
exec sudo
-E "$BASH_SOURCE" "$@"
8 echo "top of script file:"
9 sed -n '1,/^[# ]*end command line/{p;b};q' "$0"
13 script_dir
=$
(dirname $
(readlink
-f "$BASH_SOURCE"))
15 # todo: finish figuring out fai / distro-setup
16 # initial fstab / subvol setup.
19 dry_run
=false
# mostly for testing
22 temp
=$
(getopt
-l help hcnrt
: "$@") || usage
1
26 -c) conf_only
=true
; shift ;;
27 -n) dry_run
=true
; dry_run_arg
=-n; shift ;;
28 -r) resume_arg
=-r; shift ;;
29 -t) IFS
=, targets
=($2); shift 2 ;;
32 *) echo "$0: Internal error!" ; exit 1 ;;
37 ##### end command line parsing ########
42 rsync
$dry_run_arg -ahi --relative --delete "$path" "root@$host:/"
46 cat >>/etc
/btrbk.conf
<<EOF
51 cat >>/etc
/btrbk.conf
<<EOF
56 cat >>/etc
/btrbk.conf
<<EOF
57 target send-receive ssh://$tg$vol/btrbk
63 if ! which btrbk
&>/dev
/null
; then
64 echo "$0: error: no btrbk binary found"
67 cat >/etc
/btrbk.conf
<<'EOF'
68 ssh_identity /root/.ssh/id_rsa
70 # so we only run one at a time
71 lockfile /var/lock/btrbk.lock
73 # default format of short does not accomidate hourly preservation setting
74 timestamp_format long-iso
76 # only make a snapshot if things have changed
77 snapshot_create onchange
78 # much less snapshots because I have less space on the
80 #snapshot_preserve 2h 2d
81 # for now, keeping them equal for simplicity sake
82 snapshot_preserve 48h 14d 8w 24m
83 snapshot_preserve_min 6h
86 # so, total backups = ~89
87 target_preserve 48h 14d 8w 24m
88 target_preserve_min 6h
90 # if something fails and it's not obvious, try doing
91 # btrbk -l debug -v dryrun
94 # note q is owned by root:1000
95 # note p is owned 1000:1000 and chmod 700
97 if awk '{print $2}' /etc
/fstab |
grep -xF /p
&>/dev
/null
; then
101 # if our mountpoints are from stale snapshots,
102 # it doesn't make sense to do a backup.
103 check-subvol-stale
${mountpoints[@]} ||
exit 1
105 if [[ ! $targets ]]; then
108 if ! timeout
-s 9 10 ssh frodo
:; then
109 targets
=($HOME_DOMAIN)
117 # for i, we just do a 1 way sync from master to backup,
118 # and manually manage any changes to that.
120 for tg
in ${targets[@]}; do
121 # for an initial run, btrbk requires the dir to exist
122 ssh root@
$tg mkdir
-p /mnt
/root
/btrbk
123 if [[ $tg == frodo
&& $HOSTNAME == treetowl
]]; then
131 for m
in ${mountpoints[@]}; do
134 for tg
in ${targets[@]}; do
151 # todo: umount first to ensure we don't have any errors
152 # todo: do some kill fuser stuff to make umount more reliable
153 # todo: run this on a systemd timer on $primary, once per hour,
154 # and if primary is, change that timer over to primary, and make
155 # sure we mount the latest
164 btrbk
-n $resume_arg run
166 # -q and just using the syslog option seemed nice,
167 # but it doesn't show when a send has a parent and when it doesn't.
168 btrbk
$resume_arg run
171 # if we have /p, rsync to targets without /p
172 if mountpoint
/p
>/dev
/null
; then
173 for tg
in ${targets[@]}; do
176 for x
in /p
/c
/machine_specific
/*.hosts
; do
177 if grep -qxF $tg $x; then
188 $script_dir/mount-latest-remote
${targets[@]}
192 # todo: move variable data we don't care about backing up
193 # to /nocow and symlink it.
196 # background on btrbk timezones. with short/long, timestamps use local time.
197 # for long, if your local time moves backwards, by moving timezones or
198 # for an hour when daylight savings changes it, you will temporarily get
199 # a more aggressive retention policy for the overlapping period, and
200 # vice versa for the opposite timezone move. The alternative is using
201 # long-iso, which puts timezone info into the timestamp, which means
202 # that instead of shifting time, you shift the start of day/week/month
203 # which is used for retention to your new local time, which means for
204 # example, if you moved forward by 8 hours, the daily/weekly/monthly
205 # retention will be 8 hours more aggressive since midnight is at a new
206 # time, unless you fake the timzeone using the TZ env variable.
207 # However, in the short term, there will be no inconsistencies.
208 # I don't see any problem with shifting when the day starts for
209 # retention, so I'm using long-iso.
211 # note to create a long-iso timestamp: date +%Y%m%dT%H%M%S%z