4db412ef3479230c592226b04c1210c7408b6b86
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
24 # for duplicity source build
25 PATH
="$PATH:/usr/local/bin"
27 # [--retry] interval_name [max_age]
28 # takes 2 arguments specifying the name of the subfolder,
29 # and optionally, the max age of the backup
31 # this script setup by adding a user crontab. see t.org for the script
32 # it's also setup to email me only when it fails, and only for daily or weekly runs
34 # uncomment for debugging, prints all commands to stdout
38 #trap 'echo trapped error from \"$BASH_COMMAND\" returned $? line $LINENO; accumulated_errors=true' ERR
39 trap 'echo trapped err: $?; accumulated_errors=true' ERR
42 exec &>> /tmp
/small-backup.log
44 echo "BEGIN: $(date): args $*"
47 # only works with a single letter, ie 2D, not 2D12h
50 local letter
=${1##*[0-9]}
52 s
) time_wrod
=second
;;
53 m
) time_word
=minute
;;
60 echo "${1%%$letter} $time_word"
61 local x
=$
(date +%s
-d "${1%%$letter} $time_word")
66 if [[ $1 == --retry ]]; then
69 while pid
=( $
(pidof
-o %PPID
-x ${0##*/}) ) && (( ${#pid[@]} > 1 )) && (( x
< 20 )); do
73 if [[ $x == 20 ]]; then
75 echo timeout error
: existing
${0##*/} running
for over
5 minutes
>&2
79 if pid
=( $
(pidof
-o %PPID
-x ${0##*/}) ) && (( ${#pid[@]} > 1 )); then
82 echo error
: existing
${0##*/} running
>&2
90 if [[ $max_age ]]; then
91 full_backup_arg
="--full-if-older-than $(half-time $max_age)"
98 local dest
=root@li
::/root
/rdiff-backups
/${d##*/}/${interval}
100 c
="rdiff-backup $* --create-full-path $d $dest"
103 if [[ $max_age ]]; then
104 c
="rdiff-backup --force --remove-older-than $max_age $dest"
111 rbackup
/a
/bin
--exclude /a
/bin
/fai-basefiles
114 # this is populated after input_setup.sh is run on login
116 ssh root@li mkdir
-p /root
/duplicity-backups
/p
/$interval
117 source /p
/duplicity
/gpg_agent_env
118 duplicity_dest
=rsync
://root@li
//root
/duplicity-backups
/p
/$interval
121 if ((${#x[@]} > 1)); then
123 # archive-dir is sort of a persistent cache
124 duplicity
--use-agent \
125 --encrypt-sign-key E969C67B \
126 --include-globbing-filelist /p
/duplicity
/filelist \
127 --archive-dir /p
/duplicity
/archive \
129 $full_backup_arg /p
$duplicity_dest
130 if [[ $max_age ]]; then
131 duplicity
--use-agent \
132 remove-all-but-n-full
2 --force $duplicity_dest
136 # example restore command. We only need to make the first argument be a url for it to know it to do restore
137 # the archive-dir and tempdir args are not needed
138 # duplicity --use-agent --encrypt-sign-key E969C67B --archive-dir /p/duplicity/archive --tempdir /p/tmp ssh://root@li//root/duplicity-backups/p/weekly /p/duptest
143 # to restore duplicity. see man for additional options
144 # duplicity --use-agent restore ...
145 if [[ $accumulated_error ]]; then
146 eccho
"tail -n 50 of /tmp/small-backup.log:"
147 tail -n 50 /tmp
/small-backup.log