ShellCheck Lint on external-backup.sh
This commit is contained in:
parent
ba5885dd36
commit
8cfce475e9
1 changed files with 22 additions and 24 deletions
|
@ -35,7 +35,7 @@ finishUp () {
|
||||||
# Clean up tempfiles
|
# Clean up tempfiles
|
||||||
rm "$LOGFILE"
|
rm "$LOGFILE"
|
||||||
# Just to be sure
|
# Just to be sure
|
||||||
sync -f $DATA_PATH
|
sync -f "$DATA_PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
healthchecksStart () {
|
healthchecksStart () {
|
||||||
|
@ -86,8 +86,8 @@ notify () {
|
||||||
checkFreeSpace () {
|
checkFreeSpace () {
|
||||||
# Pruefe auf freien Plattenplatz
|
# Pruefe auf freien Plattenplatz
|
||||||
GETPERCENTAGE='s/.* \([0-9]\{1,3\}\)%.*/\1/'
|
GETPERCENTAGE='s/.* \([0-9]\{1,3\}\)%.*/\1/'
|
||||||
KBISFREE=$(df /$DATA_PATH | tail -n1 | sed -e "$GETPERCENTAGE")
|
KBISFREE=$(df /"$DATA_PATH" | tail -n1 | sed -e "$GETPERCENTAGE")
|
||||||
INODEISFREE=$(df -i /$DATA_PATH | tail -n1 | sed -e "$GETPERCENTAGE")
|
INODEISFREE=$(df -i /"$DATA_PATH" | tail -n1 | sed -e "$GETPERCENTAGE")
|
||||||
|
|
||||||
if [ "$KBISFREE" -ge $HDMINFREE ] || [ "$INODEISFREE" -ge $HDMINFREE ] ; then
|
if [ "$KBISFREE" -ge $HDMINFREE ] || [ "$INODEISFREE" -ge $HDMINFREE ] ; then
|
||||||
echo "Fatal: Not enough space left for rotating backups!"
|
echo "Fatal: Not enough space left for rotating backups!"
|
||||||
|
@ -111,7 +111,7 @@ EOF
|
||||||
|
|
||||||
source $CONFFILE
|
source $CONFFILE
|
||||||
|
|
||||||
if [ -z $GOTIFYURL ] || [ -z $HCURL ] ; then
|
if [ -z "$GOTIFYURL" ] || [ -z "$HCURL" ] ; then
|
||||||
echo "Fatal: GOTIFYURL and HCURL must be set in $CONFFILE. Please edit the file and set correct values, then try again."
|
echo "Fatal: GOTIFYURL and HCURL must be set in $CONFFILE. Please edit the file and set correct values, then try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -126,7 +126,7 @@ EOF
|
||||||
# Unter welchem Pfad wird gesichert?
|
# Unter welchem Pfad wird gesichert?
|
||||||
DATA_PATH="/mnt/${HDDNAME}"
|
DATA_PATH="/mnt/${HDDNAME}"
|
||||||
|
|
||||||
if ! [ -d $DATA_PATH ] ; then
|
if ! [ -d "$DATA_PATH" ] ; then
|
||||||
echo "Fatal: Data path does not exist: $DATA_PATH"
|
echo "Fatal: Data path does not exist: $DATA_PATH"
|
||||||
healthchecksFinish fail
|
healthchecksFinish fail
|
||||||
notify custom "DATA_PATH_NON_EXISTENT" "FATAL" "Data path does not exist: $DATA_PATH"
|
notify custom "DATA_PATH_NON_EXISTENT" "FATAL" "Data path does not exist: $DATA_PATH"
|
||||||
|
@ -136,8 +136,8 @@ EOF
|
||||||
checkFreeSpace
|
checkFreeSpace
|
||||||
|
|
||||||
# Ggf. Verzeichnis anlegen
|
# Ggf. Verzeichnis anlegen
|
||||||
if ! [ -d $DATA_PATH/"$SERVER"/daily.0 ] ; then
|
if ! [ -d "$DATA_PATH"/"$SERVER"/daily.0 ] ; then
|
||||||
mkdir -p $DATA_PATH/"$SERVER"/daily.0
|
mkdir -p "$DATA_PATH"/"$SERVER"/daily.0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,25 +145,25 @@ rotate () {
|
||||||
echo "Rotating snapshots of $SERVER..."
|
echo "Rotating snapshots of $SERVER..."
|
||||||
|
|
||||||
# Das hoechste Snapshot abloeschen
|
# Das hoechste Snapshot abloeschen
|
||||||
if [ -d $DATA_PATH/"$SERVER"/daily.12 ] ; then
|
if [ -d "$DATA_PATH"/"$SERVER"/daily.12 ] ; then
|
||||||
rm -rf $DATA_PATH/"$SERVER"/daily.12
|
rm -rf "$DATA_PATH"/"$SERVER"/daily.12
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Alle anderen Snapshots eine Nummer nach oben verschieben
|
# Alle anderen Snapshots eine Nummer nach oben verschieben
|
||||||
for OLD in 12 11 10 9 8 7 6 5 4 3 2 1 ; do
|
for OLD in 12 11 10 9 8 7 6 5 4 3 2 1 ; do
|
||||||
if [ -d $DATA_PATH/"$SERVER"/daily.$OLD ] ; then
|
if [ -d "$DATA_PATH"/"$SERVER"/daily.$OLD ] ; then
|
||||||
NEW=$(( OLD + 1 ))
|
NEW=$(( OLD + 1 ))
|
||||||
# Datum sichern
|
# Datum sichern
|
||||||
touch $DATA_PATH/.timestamp -r $DATA_PATH/"$SERVER"/daily.$OLD
|
touch "$DATA_PATH"/.timestamp -r "$DATA_PATH"/"$SERVER"/daily.$OLD
|
||||||
mv $DATA_PATH/"$SERVER"/daily.$OLD $DATA_PATH/"$SERVER"/daily."$NEW"
|
mv "$DATA_PATH"/"$SERVER"/daily.$OLD "$DATA_PATH"/"$SERVER"/daily."$NEW"
|
||||||
# Datum zurueckspielen
|
# Datum zurueckspielen
|
||||||
touch $DATA_PATH/"$SERVER"/daily."$NEW" -r $DATA_PATH/.timestamp
|
touch "$DATA_PATH"/"$SERVER"/daily."$NEW" -r "$DATA_PATH"/.timestamp
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Snapshot von Level-0 per hardlink-Kopie nach Level-1 kopieren
|
# Snapshot von Level-0 per hardlink-Kopie nach Level-1 kopieren
|
||||||
if [ -d $DATA_PATH/"$SERVER"/daily.0 ] ; then
|
if [ -d "$DATA_PATH"/"$SERVER"/daily.0 ] ; then
|
||||||
cp -al $DATA_PATH/"$SERVER"/daily.0 $DATA_PATH/"$SERVER"/daily.1
|
cp -al "$DATA_PATH"/"$SERVER"/daily.0 "$DATA_PATH"/"$SERVER"/daily.1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
STATUSCODE=$?
|
STATUSCODE=$?
|
||||||
|
@ -183,7 +183,6 @@ backupNC () {
|
||||||
NCOCC="sudo -u www-data php $NCDIR/occ"
|
NCOCC="sudo -u www-data php $NCDIR/occ"
|
||||||
NCDATADIR="$($NCOCC config:system:get datadirectory)"
|
NCDATADIR="$($NCOCC config:system:get datadirectory)"
|
||||||
NCDUMPSDIR="$NCDATADIR/sqldumps"
|
NCDUMPSDIR="$NCDATADIR/sqldumps"
|
||||||
NCBKPPATH="$DATA_PATH/"$SERVER"/daily.0$NCDATADIR"
|
|
||||||
DBPASSWORD="$($NCOCC config:system:get dbpassword)"
|
DBPASSWORD="$($NCOCC config:system:get dbpassword)"
|
||||||
DBNAME="$($NCOCC config:system:get dbname)"
|
DBNAME="$($NCOCC config:system:get dbname)"
|
||||||
DBHOST="$($NCOCC config:system:get dbhost)"
|
DBHOST="$($NCOCC config:system:get dbhost)"
|
||||||
|
@ -196,19 +195,18 @@ backupNC () {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p $NCDUMPSDIR
|
mkdir -p "$NCDUMPSDIR"
|
||||||
find $NCDUMPSDIR/nextcloud-sqlbkp_* -maxdepth 0 -mmin +$(($DELETEDAYS*60*24)) -exec rm -rvf {} \; > 2&>1
|
find "$NCDUMPSDIR"/nextcloud-sqlbkp_* -maxdepth 0 -mmin +$(($DELETEDAYS*60*24)) -exec rm -rvf {} \; > 2&>1
|
||||||
|
|
||||||
echo "Starting nextcloud backup..."
|
echo "Starting nextcloud backup..."
|
||||||
$NCOCC maintenance:mode --on
|
$NCOCC maintenance:mode --on
|
||||||
|
|
||||||
echo "Backup Nextcloud DB"
|
echo "Backup Nextcloud DB"
|
||||||
PGPASSWORD=$DBPASSWORD pg_dump $DBNAME -h $DBHOST -U $DBUSER -f "$NCDUMPSDIR/nextcloud-sqlbkp_`date +"%Y-%m-%d-%H-%M-%S"`.bak"
|
PGPASSWORD=$DBPASSWORD pg_dump "$DBNAME" -h "$DBHOST" -U "$DBUSER" -f "$NCDUMPSDIR/nextcloud-sqlbkp_$(date +"%Y-%m-%d-%H-%M-%S").bak"
|
||||||
|
|
||||||
|
|
||||||
echo "Backup $NCDATADIR"
|
echo "Backup $NCDATADIR"
|
||||||
mkdir -p $NCBKPPATH
|
rsync -aAXHh --stats --numeric-ids --noatime --delete --delete-excluded "$NCDATADIR"/ "$DATA_PATH"/"$SERVER"/daily.0"$NCDATADIR"
|
||||||
rsync -aAXHh --stats --numeric-ids --noatime --delete --delete-excluded $NCDATADIR/ $NCBKPPATH
|
|
||||||
|
|
||||||
STATUSCODE=$?
|
STATUSCODE=$?
|
||||||
|
|
||||||
|
@ -236,7 +234,7 @@ backup () {
|
||||||
rsync -aAXHh --stats --numeric-ids --noatime --delete --delete-excluded \
|
rsync -aAXHh --stats --numeric-ids --noatime --delete --delete-excluded \
|
||||||
--include={"/mnt/storage","/mnt/storage/media**","/mnt/storage/backup**"} \
|
--include={"/mnt/storage","/mnt/storage/media**","/mnt/storage/backup**"} \
|
||||||
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/.snapshots"} \
|
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/.snapshots"} \
|
||||||
$SRC_PATH $DATA_PATH/"$SERVER"/daily.0
|
$SRC_PATH "$DATA_PATH"/"$SERVER"/daily.0
|
||||||
|
|
||||||
STATUSCODE=$?
|
STATUSCODE=$?
|
||||||
|
|
||||||
|
@ -253,7 +251,7 @@ backup () {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Verzeichnis anfassen, um Backup-Datum zu speichern
|
# Verzeichnis anfassen, um Backup-Datum zu speichern
|
||||||
touch $DATA_PATH/"$SERVER"/daily.0
|
touch "$DATA_PATH"/"$SERVER"/daily.0
|
||||||
|
|
||||||
echo "Finished rsync backup from $SERVER..."
|
echo "Finished rsync backup from $SERVER..."
|
||||||
}
|
}
|
||||||
|
@ -262,7 +260,7 @@ backup () {
|
||||||
exec > >(tee -i "${LOGFILE}")
|
exec > >(tee -i "${LOGFILE}")
|
||||||
exec 2>&1
|
exec 2>&1
|
||||||
|
|
||||||
basicChecks ${1}
|
basicChecks "${1}"
|
||||||
healthchecksStart
|
healthchecksStart
|
||||||
notify start
|
notify start
|
||||||
setLED
|
setLED
|
||||||
|
|
Loading…
Reference in a new issue