Feature: Added multi-destination support + fixed some bugs

master
Toerd@archlinux 4 years ago
parent 3805e055fc
commit 004f0eec76

@ -18,37 +18,52 @@ tar_cmd="tar --exclude-vcs -czf"
part_backup_files="/home/phga/sync/docs/study/BA/proposal /home/phga/sync/docs/study/BA/BA_WIP.org"
full_backup_files="/home/phga/sync/docs/study/BA"
backup_path="https://nx.phga.de/remote.php/dav/files/toerd/external/no_sync/backups/study_backups/BA/"
nxt_user=toerd
# Add your own paths, users and password-files separated with a space
backup_paths=("https://nx.phga.de/remote.php/dav/files/toerd/external/no_sync/backups/study_backups/BA/" "https://nc.frfe.de/remote.php/dav/files/toerd/backups/BA/")
nxt_users=(toerd toerd)
nxt_passwds=(backup_ba_pw_phga.de.gpg backup_ba_pw_frfe.de.gpg)
# PASSWORD: see desc in header (./backup_ba_pw.gpg)
# get latest backup date (from filename, order in webdav seems to be asc - lucky for us)
last_full_backup=$(curl -s -u toerd:$(gpg -d $me/backup_ba_pw.gpg) -X PROPFIND "$backup_path" | rg -o -e "(\d{4}-\d{2}-\d{2})_BA_full" -r '$1' | tail -1)
last_part_backup=$(curl -s -u toerd:$(gpg -d $me/backup_ba_pw.gpg) -X PROPFIND "$backup_path" | rg -o -e "(\d{4}-\d{2}-\d{2})_BA_part" -r '$1' | tail -1)
datediff_full_backup=$((($(date +%s) - $(date -d $last_full_backup +%s)) / (3600 * 24)))
i=0
for bp in ${backup_paths[@]}; do
last_full_backup=$(curl -s -u ${nxt_users[$i]}:$(gpg -d $me/${nxt_passwds[$i]}) -X PROPFIND "$bp" | rg -o -e "(\d{4}-\d{2}-\d{2})_BA_full" -r '$1' | tail -1)
last_part_backup=$(curl -s -u ${nxt_users[$i]}:$(gpg -d $me/${nxt_passwds[$i]}) -X PROPFIND "$bp" | rg -o -e "(\d{4}-\d{2}-\d{2})_BA_part" -r '$1' | tail -1)
if [ ! -z $last_full_backup ]; then
datediff_full_backup=$((($(date +%s) - $(date -d $last_full_backup +%s)) / (3600 * 24)))
else
datediff_full_backup=1337
fi
# Info output
echo --------------------------------------
echo Last full backup was $datediff_full_backup days ago
echo Date last full backup: $last_full_backup
echo Date last part backup: $last_part_backup
echo --------------------------------------
# Info output
echo --------------------------------------
echo $bp | rg -o -e ".*\.de"
echo Last full backup was $datediff_full_backup days ago
echo Date last full backup: $last_full_backup
echo Date last part backup: $last_part_backup
echo --------------------------------------
# If 14 days have passed, create a new full backup
if [ -z $last_full_backup ] || [ $datediff_full_backup -gt 14 ]; then
$tar_cmd "$tmp_path$archive_name_full" $full_backup_files
curl -s -u $nxt_user:$(gpg -d $me/backup_ba_pw.gpg) -T "$tmp_path$archive_name_full" "$backup_path$archive_name_full"
else
echo "---- No full backup required yet! ----"
fi
# if there is no important backup from this day, create one
if [ -z $last_part_backup ] || [ $today != $last_part_backup ]; then
$tar_cmd "$tmp_path$archive_name_part" $part_backup_files
curl -s -u $nxt_user:$(gpg -d $me/backup_ba_pw.gpg) -T "$tmp_path$archive_name_part" "$backup_path$archive_name_part"
else
echo "---- No part backup required yet! ----"
fi
# If 14 days have passed, create a new full backup
if [ -z $last_full_backup ] || [ $datediff_full_backup -gt 14 ]; then
# if no tar for this backup exists create one
if [ ! -f "$tmp_path$archive_name_full" ]; then
$tar_cmd "$tmp_path$archive_name_full" $full_backup_files
fi
curl -s -u ${nxt_users[$i]}:$(gpg -d $me/${nxt_passwds[$i]}) -T "$tmp_path$archive_name_full" "$bp$archive_name_full"
else
echo "---- No full backup required yet! ----"
fi
# if there is no important backup from this day, create one
if [ -z $last_part_backup ] || [ $today != $last_part_backup ]; then
if [ ! -f "$tmp_path$archive_name_part" ]; then
$tar_cmd "$tmp_path$archive_name_part" $part_backup_files
fi
curl -s -u ${nxt_users[$i]}:$(gpg -d $me/${nxt_passwds[$i]}) -T "$tmp_path$archive_name_part" "$bp$archive_name_part"
else
echo "---- No part backup required yet! ----"
fi
((i++))
done
# remove temp path
rm -r $tmp_path
Loading…
Cancel
Save