-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbackup.sh
executable file
·53 lines (40 loc) · 1.31 KB
/
backup.sh
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
# !/bin/bash
echo "$PWD"
if [ -f .env ]
then
echo ".env exists"
export $(cat .env | sed 's/#.*//g' | xargs)
fi
destination=${BACKUP_DESTINATION}
destinationMount=${BACKUP_DESTINATION_MOUNT}
repository="homeserver"
source=$( pwd; )
sourceMount=${BACKUP_SOURCE_MOUNT}
encryption="none"
compression="lz4"
rootuser="yes"
pruning="--keep-within=1d --keep-daily=7 --keep-weekly=4 --keep-monthly=6"
webhook=${WEBHOOK}
repopath="$destination"/"$repository"
if grep $destinationMount /proc/mounts && grep $sourceMount /proc/mounts
then
if [ $(id -u) -ne 0 ] && [ "$rootuser" == "yes" ]; then
echo "Backup has to be run as root user."
exit 1
fi
if [ ! -d $repopath ]; then
borg init --encryption=$encryption $repopath
echo "Borg-repository created at $repopath"
fi
SECONDS=0
$source/script.sh SAVE_BACKUP stop
echo "Start of backup $(date)."
borg create --compression $compression --exclude-caches --one-file-system -v --stats --progress $repopath::'{hostname}-{now:%Y-%m-%d-%H%M%S}' $source
echo "End of backup $(date). Duration: $SECONDS seconds"
$source/script.sh SAVE_BACKUP start
borg prune -v --list $repopath --glob-archives '{hostname}-*' $pruning
borg compact $repopath
curl $webhook
else
echo "!!! DIRECTORIES NOT MOUNTED !!! $(date)"
fi