Compare commits

...

3 Commits

Author SHA1 Message Date
Asif Bacchus
5af5a064a9 replaced redis err check w/ verification of success string piped to log 2018-10-25 09:42:22 -06:00
Asif Bacchus
9bd6c9d431 Removed err check for sqldump, replaced w/ dumpfile > 0 existance check 2018-10-25 09:12:01 -06:00
Asif Bacchus
93a0cce519 added checkExist for file > 0 bytes 2018-10-25 09:06:35 -06:00

View File

@ -144,6 +144,15 @@ function checkExist {
# not found
return 1
fi
elif [ "$1" = "fs" ]; then
# find file > 0 bytes
if [ -s "$2" ]; then
# found
return 0
else
# not found
return 1
fi
elif [ "$1" = "fd" ]; then
# find directory
if [ -d "$2" ]; then
@ -556,27 +565,29 @@ fi
### Dump SQL
echo -e "${op}${stamp} Dumping mailcow SQL database...${normal}" >> "$logFile"
docker-compose exec mysql-mailcow mysqldump --default-character-set=utf8mb4 -u${DBUSER} -p${DBPASS} ${DBNAME} > "$sqlDumpDir/$sqlDumpFile" 2>> "$logFile"
checkResult=$(docker-compose exec -T mysql-mailcow echo $?)
# verify sql dump was successful
if [ "$checkResult" = 0 ]; then
echo -e "${ok}${stamp} -- [SUCCESS] SQL successfully dumped --${normal}" \
>> "$logFile"
else
exitError+=("${stamp}_201")
fi
## error checking sqldump within the container in a cron-friendly manner is a
## nightmare, so let's just see if a non-empty file with the expected name was
## created
checkExist fs "$sqlDumpDir/$sqlDumpFile"
checkResult="$?"
if [ "$checkResult" = "0" ]; then
echo -e "${ok}${stamp} -- [SUCCESS] SQL successfully dumped --" \
"${normal}" >> "$logFile"
else
exitError+=("${stamp}_201")
fi
### Save redis state
echo -e "${op}${stamp} Saving redis state information...${normal}" >> "$logFile"
docker-compose exec redis-mailcow redis-cli save >> "$logFile" 2>&1
checkResult=$(docker-compose exec -T redis-mailcow echo "$?")
# Verify save was successful
if [ "$checkResult" = 0 ]; then
## redis outputs a simple 'OK' if the export succeeded, so check the log file
## for a line just written that says that specifically
if [ $(tail -1 "$logFile") = "OK" ];
echo -e "${ok}${stamp} -- [SUCCESS] redis state saved --${normal}" \
>> "$logFile"
else
exitError+=("${stamp}_202")
fi
else
exitError+=("${stamp}_202")
fi
### Call borgbackup to copy actual files