-
Notifications
You must be signed in to change notification settings - Fork 5
/
jitsi_backup_push.sh
108 lines (94 loc) · 2.96 KB
/
jitsi_backup_push.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash -l
#===============================================================================
#
# FILE: jitsi_backup_push.sh
#
# USAGE: ./jitsi_backup_push.sh
#
# DESCRIPTION: simple backups transfer script
#
# OPTIONS: DSTIP= APP= BACKUPUSER= BACKUPFOLDER=
# AUTHOR: Andre Stemmann
# ORGANIZATION: AirITSystems GmbH
# CREATED: 30.04.2020 10:41
# REVISION: v0.2
#===============================================================================
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
set -o nounset # Treat unset variables as an error
# ===============================================================================
# BASE VARIABLES
# ===============================================================================
# script vars
TODAY=$(date +%Y%m%d)
start=$(date +%s)
HOST=$(hostname -f)
PROGGI=$(basename "$0")
READLINK=$(readlink -f "$0")
BASEDIR=$(dirname "$READLINK")
LOGPATH="${BASEDIR}/jitsi_backup_push_logs"
LOGFILE="${LOGPATH}/${PROGGI}-${TODAY}.log"
ERRORLOG="${LOGPATH}/${PROGGI}-${TODAY}_ERROR.log"
. /etc/os-release
# user vars
DSTIP="192.168.x.x"
APP="jitsi-meet"
BACKUPUSER="myfancybackupuser_to_access_the_remote_host"
BACKUPFOLDER="/var/backups"
BACKUPNAME="${HOST}_${ID}_${VERSION_ID}_${APP}_${TODAY}"
BACKDST="${DSTIP}:${BACKUPFOLDER}/${BACKUPUSER}"
# ===============================================================================
# BASE FUNCTIONS
# ===============================================================================
function log () {
echo "$PROGGI ; $(date '+%Y%m%d %H:%M:%S') ; $@" | tee -a "${LOGFILE}"
}
function errorlog () {
echo "${PROGGI}_ERRORLOG ; $(date '+%Y%m%d %H:%M:%S') ; $@" | tee -a "${ERRORLOG}"
}
function usercheck () {
if [[ $UID -ne 0 ]]; then
errorlog "...Become user ${BACKUPUSER} and try again"
exit 1
fi
}
function folder () {
if [ ! -d "$1" ]; then
mkdir -p "$1"
log "...Create Logfile structure for $PROGGI $1"
else
log "...Folder $1 already exists"
fi
}
function sync () {
if $(hash rsync); then
rsync -av --stats --progress "${BACKUPFOLDER}/${BACKUPNAME}.tar.gz" "${BACKUPUSER}"'@'"${BACKDST}"
else
errorlog "...Rsync not found, aborting"
fi
}
function tidyup () {
find "${BACKUPFOLDER}" -type f -mtime +7 | xargs rm -f
find "${LOGPATH}/" -type f -mtime +7 | xargs rm -f
}
# ===============================================================================
# MAIN RUN
# ===============================================================================
cd "$BASEDIR" || errorlog "...failed to cd into $BASEDIR"
echo "Backup CONFIG"
echo "#########################"
echo "logfile location : $LOGPATH"
echo "backup destination : $BACKDST"
echo "Backupfile : ${BACKUPFOLDER}/$BACKUPNAME"
echo "hostname : $HOST"
echo "date : $TODAY"
sleep 5
# folder structure
folder "${LOGPATH}"
# script run
usercheck
sync
tidyup
end=$(date +%s)
runtime=$((end-start))
log "...Runtime $runtime Seconds"
exit 0