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") |
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") \ |
49eec3
|
16 |
$1:/Uni/$([ $2 != "p" ] && echo "borg" || 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 |
49eec3
|
49 |
elif [ "$1" = "cron" ]; then |
JG |
50 |
borg create \ |
|
51 |
--compression zstd,22 \ |
|
52 |
--exclude '*~' \ |
|
53 |
--exclude '*#*' \ |
|
54 |
\ |
|
55 |
$BACKUP_DIR::"$(date +%F+%R)" \ |
|
56 |
$FILES_DIR |
|
57 |
else |
|
58 |
borg create \ |
|
59 |
--verbose \ |
|
60 |
--stats \ |
|
61 |
--compression zstd,22 \ |
|
62 |
--exclude '*~' \ |
|
63 |
--exclude '*#*' \ |
|
64 |
\ |
|
65 |
$BACKUP_DIR::"$(date +%F+%R)" \ |
|
66 |
$FILES_DIR |
f7f566
|
67 |
fi |
JG |
68 |
|
49eec3
|
69 |
borg prune \ |
d0df60
|
70 |
--keep-hourly 12 \ |
JG |
71 |
--keep-daily 8 \ |
|
72 |
--keep-monthly 2 \ |
49eec3
|
73 |
$BACKUP_DIR |
64e605
|
74 |
|
49eec3
|
75 |
LAST="$(borg list $BACKUP_DIR | tail -n2 | cut -d' ' -f1)" |
JG |
76 |
if [ -z "$(borg diff $BACKUP_DIR::$(echo $LAST | cut -d' ' -f1) $(echo $LAST | cut -d' ' -f2))" ]; then |
|
77 |
borg delete $BACKUP_DIR::$(echo $LAST | cut -d' ' -f2) |
f7f566
|
78 |
else |
49eec3
|
79 |
echo "New backup $(echo $LAST | cut -d' ' -f2)" |
ae2fb4
|
80 |
sync_all |
f7f566
|
81 |
fi |