3 # for duplicity source build
4 PATH
="$PATH:/usr/local/bin"
6 # [--retry] interval_name [max_age]
7 # takes 2 arguments specifying the name of the subfolder,
8 # and optionally, the max age of the backup
10 # this script setup by adding a user crontab. see t.org for the script
11 # it's also setup to email me only when it fails, and only for daily or weekly runs
13 # uncomment for debugging, prints all commands to stdout
17 #trap 'echo trapped error from \"$BASH_COMMAND\" returned $? line $LINENO; accumulated_errors=true' ERR
18 trap 'echo trapped err: $?; accumulated_errors=true' ERR
21 exec &>> /tmp
/small-backup.log
23 echo "BEGIN: $(date): args $*"
26 # only works with a single letter, ie 2D, not 2D12h
29 local letter
=${1##*[0-9]}
31 s
) time_wrod
=second
;;
32 m
) time_word
=minute
;;
39 echo "${1%%$letter} $time_word"
40 local x
=$
(date +%s
-d "${1%%$letter} $time_word")
45 if [[ $1 == --retry ]]; then
48 while pid
=( $
(pidof
-o %PPID
-x ${0##*/}) ) && (( ${#pid[@]} > 1 )) && (( x
< 20 )); do
52 if [[ $x == 20 ]]; then
54 echo timeout error
: existing
${0##*/} running
for over
5 minutes
>&2
58 if pid
=( $
(pidof
-o %PPID
-x ${0##*/}) ) && (( ${#pid[@]} > 1 )); then
61 echo error
: existing
${0##*/} running
>&2
69 if [[ $max_age ]]; then
70 full_backup_arg
="--full-if-older-than $(half-time $max_age)"
77 local dest
=root@li
::/root
/rdiff-backups
/${d##*/}/${interval}
79 c
="rdiff-backup $* --create-full-path $d $dest"
82 if [[ $max_age ]]; then
83 c
="rdiff-backup --force --remove-older-than $max_age $dest"
90 rbackup
/a
/bin
--exclude /a
/bin
/fai-basefiles
93 # this is populated after input_setup.sh is run on login
95 ssh root@li mkdir
-p /root
/duplicity-backups
/p
/$interval
96 source /p
/duplicity
/gpg_agent_env
97 duplicity_dest
=rsync
://root@li
//root
/duplicity-backups
/p
/$interval
100 if ((${#x[@]} > 1)); then
102 # archive-dir is sort of a persistent cache
103 duplicity
--use-agent \
104 --encrypt-sign-key E969C67B \
105 --include-globbing-filelist /p
/duplicity
/filelist \
106 --archive-dir /p
/duplicity
/archive \
108 $full_backup_arg /p
$duplicity_dest
109 if [[ $max_age ]]; then
110 duplicity
--use-agent \
111 remove-all-but-n-full
2 --force $duplicity_dest
115 # example restore command. We only need to make the first argument be a url for it to know it to do restore
116 # the archive-dir and tempdir args are not needed
117 # 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
122 # to restore duplicity. see man for additional options
123 # duplicity --use-agent restore ...
124 if [[ $accumulated_error ]]; then
125 eccho
"tail -n 50 of /tmp/small-backup.log:"
126 tail -n 50 /tmp
/small-backup.log