add email export and cleanup

This commit is contained in:
Asif Bacchus 2019-07-25 00:26:42 -06:00
parent f268a2b6b5
commit 6944db98d4
2 changed files with 53 additions and 33 deletions

View File

@ -1,3 +1,19 @@
{ {
"bookmarks": [] "bookmarks": [
{
"fsPath": "$ROOTPATH$/pilerbackup.sh",
"bookmarks": [
-1,
332,
65,
-1,
-1,
-1,
-1,
-1,
-1,
576
]
}
]
} }

View File

@ -63,6 +63,18 @@ cleanup () {
"$(stamp)" >> "$logFile" "$(stamp)" >> "$logFile"
fi fi
fi fi
# remove EML temporary directory
if ! rm -f "$exportDir" 2>>"$logFile"; then
printf "${warn}[%s] -- [WARNING] Could not remove EML export tmp dir:" \
"$(stamp)" >> "$logFile"
printf "\n%s\n" "$exportDir" >> "$logFile"
printf "please remove this directory manually! --${norm}\n" \
>> "$logFile"
warnCount=$((warnCount+1))
else
printf "${cyan}[%s] -- [INFO] EML temp directory removed --${norm}\n" \
"$(stamp)" >> "$logFile"
fi
} }
# call cleanup and then exit with error report # call cleanup and then exit with error report
@ -311,43 +323,34 @@ printf "${cyan}[%s] -- [INFO] ${yellow}%s${cyan} imported --${norm}\n" \
"$(stamp)" "$configDetails" >> "$logFile" "$(stamp)" "$configDetails" >> "$logFile"
## create tmp directory ## create tmp directory and change to it for export operations
printf "${cyan}[%s] -- [INFO] Dumping SQL databases --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Exporting EML files from piler --${norm}\n" \
"$(stamp)" >> "$logFile" "$(stamp)" >> "$logFile"
# create temporary directory to dump files before borg backup # create temporary directory to dump files before borg backup
if ! sqlDumpDir=$( mktemp -d 2>>"$logFile" ); then if ! exportDir=$( mktemp -d 2>>"$logFile" ); then
exitError 111 "Could not create temporary directory to dump SQL files" exitError 111 "Could not create temporary directory for exported EML files"
fi fi
# set cleanup flag if ! cd "$exportDir"; then
sqlCopied=1 exitError 112 "Unable to change to temporary export directory"
printf "${cyan}[%s] -- [INFO] SQL dump files will be temporarily stored in:" \ fi
printf "${cyan}[%s] -- [INFO] EML files will be temporarily stored in:" \
"$(stamp)" >> "$logFile" "$(stamp)" >> "$logFile"
printf "\n${yellow}%s/${cyan} --${norm}\n" "$sqlDumpDir" >> "$logFile" printf "\n${yellow}%s/${cyan} --${norm}\n" "$exportDir" >> "$logFile"
# create unique names for database dump files
sqlDump_ccnet="backup-$(date +%Y%m%d_%H%M%S)_${ccnetDB_name}.sql"
sqlDump_seafile="backup-$(date +%Y%m%d_%H%M%S)_${seafileDB_name}.sql"
sqlDump_seahub="backup-$(date +%Y%m%d_%H%M%S)_${seahubDB_name}.sql"
## dump databases ## export EML from piler
# dump CCNET-DB if [ "$exportAll" -eq 1 ]; then
if ! mysqldump -h"${sqlServer}" -u"${sqlUser}" -p"${sqlPass}" \ if ! pilerexport -A 2>>"$logFile"; then
--opt "${ccnetDB_name}" > "${sqlDumpDir}/${sqlDump_ccnet}" \ exitError 115 "There was a problem while exporting EML from piler"
2>> "$logFile"; then fi
exitError 115 "Could not dump ${ccnetDB_name} database" printf "${ok}[%s] -- [SUCCESS] Exported EML files from piler --${norm}\n" \
"$(stamp)" >> "$logFile"
else
if ! pilerexport -a $exportStart -b $exportEnd 2>>"$logFile"; then
exitError 115 "There was a problem while exporting EML from piler"
fi
printf "${ok}[%s] -- [SUCCESS] Exported EML files from piler --${norm}\n" \
"$(stamp)" >> "$logFile"
fi fi
# dump SEAFILE-DB
if ! mysqldump -h"${sqlServer}" -u"${sqlUser}" -p"${sqlPass}" \
--opt "${seafileDB_name}" > "${sqlDumpDir}/${sqlDump_seafile}" \
2>> "$logFile"; then
exitError 116 "Could not dump ${seafileDB_name} database"
fi
# dump CCNET-DB
if ! mysqldump -h"${sqlServer}" -u"${sqlUser}" -p"${sqlPass}" \
--opt "${seahubDB_name}" > "${sqlDumpDir}/${sqlDump_seahub}" 2>> "$logFile"; then
exitError 117 "Could not dump ${seahubDB_name} database"
fi
printf "${ok}[%s] -- [SUCCESS] SQL databases dumped successfully --${norm}\n" \
"$(stamp)" >> "$logFile"
### pre-backup tasks completed -- move to borg tasks ### pre-backup tasks completed -- move to borg tasks
@ -577,7 +580,8 @@ exit 0
# 3: borg not installed # 3: borg not installed
# 99: TERM signal trapped # 99: TERM signal trapped
# 111: could not create tmp dir for EML dump from piler-export # 111: could not create tmp dir for EML dump from piler-export
# 112: problem during piler-export operation # 112: could not change to tmp dir to start export operation
# 115: problem during piler-export operation
# 130: null configuration variable in details file # 130: null configuration variable in details file
# 131: invalid configuration variable in details file # 131: invalid configuration variable in details file
# 138: borg exited with a critical error # 138: borg exited with a critical error