mirror of https://github.com/Chizi123/Scripts.git

Joel Grunbaum
2020-06-17 305b169e0390b1d86fd673e27a1d21f463b2cc72
commit | author | age
64e605 1 #!/bin/sh
JG 2
ae2fb4 3 BACKUP_DIR="/backup/work/"
JG 4 FILES_DIR="/home/joel/OneDrive/"
305b16 5 RCLONE_BACKUP=("OneDrive_Personal" "GoogleDrive" "Mega" "unimelb" "sout" "pCloud" "gdrive_unimelb")
JG 6 RCLONE_FILES=("sout" "Mega" "unimelb" "gdrive_unimelb")
ae2fb4 7
JG 8 function sync() {
65356c 9     case $1 in
JG 10         "sout")
305b16 11             rclone sync $([ $2 != "p" ] && echo "$BACKUP_DIR" || echo "$FILES_DIR") \
JG 12                    $1:/data/Cloud/$([ $2 != "p" ] && echo "backup" || echo "files") $(! [ -z $3 ] && echo "-P")
65356c 13             ;;
JG 14         *)
305b16 15             rclone sync $([ $2 != "p" ] && echo "$BACKUP_DIR" || echo "$FILES_DIR") \
JG 16                    $1:/Uni/$([ $2 != "p" ] && echo "duplicacy" || echo "files")  $(! [ -z $3 ] && echo "-P")
65356c 17             ;;
JG 18     esac
ae2fb4 19 }
JG 20
21 function sync_all() {
22     if [ -z $1 ]; then
23         for i in ${RCLONE_BACKUP[*]}; do
305b16 24             #echo -e '\033[0;31m'$i backup'\033[0m'
JG 25             sync $i n &
ae2fb4 26         done
JG 27         for i in ${RCLONE_FILES[*]}; do
305b16 28             #echo -e '\033[0;31m'$i files'\033[0m'
ae2fb4 29             sync $i p &
JG 30         done
31     else
32         for i in ${RCLONE_BACKUP[*]}; do
33             echo -e '\033[0;31m'$i backup'\033[0m'
34             sync $i n p
35         done
36         for i in ${RCLONE_FILES[*]}; do
65356c 37             echo -e '\033[0;31m'$i files'\033[0m'
ae2fb4 38             sync $i p p
JG 39         done
40     fi
41 }
42
64e605 43 cd /home/joel/OneDrive
JG 44
9af599 45 if [ "$1" = "sync" ]; then
ae2fb4 46     echo -e '\033[0;32m'Syncing'\033[0m'
JG 47     sync_all p
f7f566 48     exit
JG 49 fi
50
64e605 51 LAST="$(duplicacy list | tail -n1 | cut -d' '  -f4)"
f7f566 52 CURR="$(duplicacy backup | tail -n1 | sed 's/[^0-9]//g')"
64e605 53 #LAST=2
JG 54 #CURR=4
55 DIFF="$(duplicacy diff -r $CURR -r $LAST | grep '-')"
56
57 #echo "curr - $CURR"
58 #echo "last - $LAST"
59 #echo "diff - $DIFF"
60
5417a6 61 duplicacy prune -keep 7:30 -keep 1:7 -exclusive > /dev/null 2>&1
64e605 62
f7f566 63 if [ -z "$DIFF" ]; then
JG 64     duplicacy prune -r $CURR -exclusive > /dev/null 2>&1
65 else
66     echo "New backup $CURR"
ae2fb4 67     sync_all
f7f566 68 fi