commit | author | age
|
64e605
|
1 |
#!/bin/sh |
JG |
2 |
|
ae2fb4
|
3 |
BACKUP_DIR="/backup/work/" |
JG |
4 |
FILES_DIR="/home/joel/OneDrive/" |
d0df60
|
5 |
RCLONE_BACKUP=("GoogleDrive" "Mega" "unimelb" "pCloud" "gdrive_unimelb" "NC_home" "NextCloud") |
JG |
6 |
RCLONE_FILES=("Mega" "unimelb" "gdrive_unimelb" "NC_home") |
af5c53
|
7 |
EXCLUDES="--exclude '*~' --exclude '*#*' --exclude '.DS_Store' --exclude '*.7z' " |
ae2fb4
|
8 |
|
JG |
9 |
function sync() { |
65356c
|
10 |
case $1 in |
JG |
11 |
"sout") |
305b16
|
12 |
rclone sync $([ $2 != "p" ] && echo "$BACKUP_DIR" || echo "$FILES_DIR") \ |
JG |
13 |
$1:/data/Cloud/$([ $2 != "p" ] && echo "backup" || echo "files") $(! [ -z $3 ] && echo "-P") |
65356c
|
14 |
;; |
JG |
15 |
*) |
305b16
|
16 |
rclone sync $([ $2 != "p" ] && echo "$BACKUP_DIR" || echo "$FILES_DIR") \ |
49eec3
|
17 |
$1:/Uni/$([ $2 != "p" ] && echo "borg" || echo "files") $(! [ -z $3 ] && echo "-P") |
65356c
|
18 |
;; |
JG |
19 |
esac |
ae2fb4
|
20 |
} |
JG |
21 |
|
|
22 |
function sync_all() { |
|
23 |
if [ -z $1 ]; then |
|
24 |
for i in ${RCLONE_BACKUP[*]}; do |
305b16
|
25 |
#echo -e '\033[0;31m'$i backup'\033[0m' |
JG |
26 |
sync $i n & |
ae2fb4
|
27 |
done |
JG |
28 |
for i in ${RCLONE_FILES[*]}; do |
305b16
|
29 |
#echo -e '\033[0;31m'$i files'\033[0m' |
ae2fb4
|
30 |
sync $i p & |
JG |
31 |
done |
|
32 |
else |
|
33 |
for i in ${RCLONE_BACKUP[*]}; do |
|
34 |
echo -e '\033[0;31m'$i backup'\033[0m' |
|
35 |
sync $i n p |
|
36 |
done |
|
37 |
for i in ${RCLONE_FILES[*]}; do |
65356c
|
38 |
echo -e '\033[0;31m'$i files'\033[0m' |
ae2fb4
|
39 |
sync $i p p |
JG |
40 |
done |
|
41 |
fi |
|
42 |
} |
|
43 |
|
64e605
|
44 |
cd /home/joel/OneDrive |
JG |
45 |
|
9af599
|
46 |
if [ "$1" = "sync" ]; then |
ae2fb4
|
47 |
echo -e '\033[0;32m'Syncing'\033[0m' |
JG |
48 |
sync_all p |
f7f566
|
49 |
exit |
49eec3
|
50 |
elif [ "$1" = "cron" ]; then |
af5c53
|
51 |
borg create \ |
49eec3
|
52 |
--compression zstd,22 \ |
af5c53
|
53 |
$EXCLUDES \ |
49eec3
|
54 |
\ |
JG |
55 |
$BACKUP_DIR::"$(date +%F+%R)" \ |
|
56 |
$FILES_DIR |
|
57 |
else |
af5c53
|
58 |
borg create \ |
49eec3
|
59 |
--verbose \ |
JG |
60 |
--stats \ |
|
61 |
--compression zstd,22 \ |
af5c53
|
62 |
$EXCLUDES \ |
49eec3
|
63 |
\ |
JG |
64 |
$BACKUP_DIR::"$(date +%F+%R)" \ |
|
65 |
$FILES_DIR |
f7f566
|
66 |
fi |
JG |
67 |
|
49eec3
|
68 |
borg prune \ |
d0df60
|
69 |
--keep-hourly 12 \ |
JG |
70 |
--keep-daily 8 \ |
|
71 |
--keep-monthly 2 \ |
49eec3
|
72 |
$BACKUP_DIR |
64e605
|
73 |
|
49eec3
|
74 |
LAST="$(borg list $BACKUP_DIR | tail -n2 | cut -d' ' -f1)" |
JG |
75 |
if [ -z "$(borg diff $BACKUP_DIR::$(echo $LAST | cut -d' ' -f1) $(echo $LAST | cut -d' ' -f2))" ]; then |
|
76 |
borg delete $BACKUP_DIR::$(echo $LAST | cut -d' ' -f2) |
f7f566
|
77 |
else |
49eec3
|
78 |
echo "New backup $(echo $LAST | cut -d' ' -f2)" |
ae2fb4
|
79 |
sync_all |
f7f566
|
80 |
fi |