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

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