Op 21 september 2023
#! /bin/bash ############ # database-dump.sh # Syntax : # database-dump.sh # Purpose : Dump the datacenter database to a backup file. # # # # # nu=$(date +%Y%m%d-%H%M%S) dumpDir=/backup/logical dumpFile=${dumpDir}/mariadb-dump-${nu}.sql logDir=/var/log/database-dump logFile=${logDir}/dump-$nu.log mkdir $logDir 2>/dev/null echo "Dump started $(date)" >$logFile mkdir -p ${dumpDir} cd ${dumpDir} 2>/dev/null if [[ $? -ne 0 ]] ;then echo "Error: $(basename $0) : Could not access $DumpDir" >>$logFile exit 2 fi mariadb-dump \ -ubackup_logical \ -p'DeltionBackup123!' \ --databases datacenter > ${dumpFile} 2>>$logFile if [[ $? -ne 0 ]] ; then echo "Error: $(basename $0) : Dump failed">>$logFile exit 2 fi tar -czvf ${dumpFile}.tgz ${dumpFile} >>$logFile 2>&1 rm ${dumpFile} echo "Dump finished $(date)" >>$logFile # eos