From afe40b2bf69d3b1dd5b2368968008e8e321727a7 Mon Sep 17 00:00:00 2001 From: Joel Grunbaum <joelgrun@gmail.com> Date: Mon, 21 Sep 2020 12:32:39 +0000 Subject: [PATCH] Added btrfs-progs to base packages to compliment filesystem --- backup.sh | 96 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 74 insertions(+), 22 deletions(-) diff --git a/backup.sh b/backup.sh index 21f8aea..13d1dc8 100755 --- a/backup.sh +++ b/backup.sh @@ -1,29 +1,81 @@ #!/bin/sh +BACKUP_DIR="/backup/work/" +FILES_DIR="/home/joel/OneDrive/" +RCLONE_BACKUP=("OneDrive_Personal" "GoogleDrive" "Mega" "unimelb" "sout" "pCloud" "gdrive_unimelb") +RCLONE_FILES=("sout" "Mega" "unimelb" "gdrive_unimelb") + +function sync() { + case $1 in + "sout") + rclone sync $([ $2 != "p" ] && echo "$BACKUP_DIR" || echo "$FILES_DIR") \ + $1:/data/Cloud/$([ $2 != "p" ] && echo "backup" || echo "files") $(! [ -z $3 ] && echo "-P") + ;; + *) + rclone sync $([ $2 != "p" ] && echo "$BACKUP_DIR" || echo "$FILES_DIR") \ + $1:/Uni/$([ $2 != "p" ] && echo "borg" || echo "files") $(! [ -z $3 ] && echo "-P") + ;; + esac +} + +function sync_all() { + if [ -z $1 ]; then + for i in ${RCLONE_BACKUP[*]}; do + #echo -e '\033[0;31m'$i backup'\033[0m' + sync $i n & + done + for i in ${RCLONE_FILES[*]}; do + #echo -e '\033[0;31m'$i files'\033[0m' + sync $i p & + done + else + for i in ${RCLONE_BACKUP[*]}; do + echo -e '\033[0;31m'$i backup'\033[0m' + sync $i n p + done + for i in ${RCLONE_FILES[*]}; do + echo -e '\033[0;31m'$i files'\033[0m' + sync $i p p + done + fi +} + cd /home/joel/OneDrive -LAST="$(duplicacy list | tail -n1 | cut -d' ' -f4)" -CURR="$(duplicacy backup | grep "revision [0-9] completed" | sed 's/[^0-9]//g')" -#LAST=2 -#CURR=4 -DIFF="$(duplicacy diff -r $CURR -r $LAST | grep '-')" - -#echo "curr - $CURR" -#echo "last - $LAST" -#echo "diff - $DIFF" - -if [ -z "$DIFF" ]; then - duplicacy prune -r $CURR -exclusive +if [ "$1" = "sync" ]; then + echo -e '\033[0;32m'Syncing'\033[0m' + sync_all p + exit +elif [ "$1" = "cron" ]; then + borg create \ + --compression zstd,22 \ + --exclude '*~' \ + --exclude '*#*' \ + \ + $BACKUP_DIR::"$(date +%F+%R)" \ + $FILES_DIR else - echo "No diff to backup" + borg create \ + --verbose \ + --stats \ + --compression zstd,22 \ + --exclude '*~' \ + --exclude '*#*' \ + \ + $BACKUP_DIR::"$(date +%F+%R)" \ + $FILES_DIR fi -duplicacy prune -keep 1:7 -keep 7:30 -exclusive -BACKUP_DIR="/backup/work/" -rclone sync $BACKUP_DIR "OneDrive_Personal":/Uni & -rclone sync $BACKUP_DIR "NextCloud":/Uni & -rclone sync $BACKUP_DIR "GoogleDrive":/Uni & -rclone sync $BACKUP_DIR "Mega":/Uni & -rclone sync $BACKUP_DIR "unimelb":/ & -rclone sync $BACKUP_DIR "sout":/data/Cloud & -#rclone sync $BACKUP_DIR "Oracle":/Uni +borg prune \ + --keep-hourly 24 \ + --keep-daily 7 \ + --keep-monthly 4 \ + $BACKUP_DIR + +LAST="$(borg list $BACKUP_DIR | tail -n2 | cut -d' ' -f1)" +if [ -z "$(borg diff $BACKUP_DIR::$(echo $LAST | cut -d' ' -f1) $(echo $LAST | cut -d' ' -f2))" ]; then + borg delete $BACKUP_DIR::$(echo $LAST | cut -d' ' -f2) +else + echo "New backup $(echo $LAST | cut -d' ' -f2)" + sync_all +fi -- Gitblit v1.9.3