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

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