Update mssql-backup.sh

This commit is contained in:
Mattia Tadini 2024-11-07 16:51:13 +00:00
parent b66d01ebc1
commit a16089beaf

View File

@ -2,7 +2,7 @@
# Script per il backup di database MS SQL Server
# Autore: Lorenzo Paciotti & Mattia Tadini
# Nome del file: mssql-backup.sh
# Revisione: 1.00
# Revisione: 1.10
# Configuration
BACKUP_DIR="/zucchetti/backupdb/bkfiles"
@ -14,8 +14,8 @@ RETENTION=1 # Retention per i backup locali
REMOTE_RETENTION=2 # Retention per i backup remoti
DATE=$(LC_TIME=C date +%Y%m%d%H%M%S) # Forza il formato della data
SERVER_NAME="DBSQL01" # Identificativo del server fisico
LOG_FILE="/zucchetti/backupdb/backup_log.txt"
ERROR_LOG_FILE="/zucchetti/backupdb/backup_err.txt"
LOG_FILE="/zucchetti/backupdb/backup_log_$DATE.txt"
ERROR_LOG_FILE="/zucchetti/backupdb/backup_err_$DATE.txt"
FTP_SERVER="terni.poloinformatico.it"
FTP_USER="backupmssqldb"
FTP_PASSWORD="!Li'D/i%2&*QkvK!"
@ -37,10 +37,14 @@ REMOTE_DB_DIR="$REMOTE_DIR/$DB_NAME"
# Create local backup directory if it doesn't exist
mkdir -p "$LOCAL_DB_DIR"
chown mssql:mssql "$LOCAL_DB_DIR"
# Create remote directory on FTP server if it doesn't exist
ftp -inv $FTP_SERVER <<EOF >> $LOG_FILE 2>> $ERROR_LOG_FILE
user $FTP_USER $FTP_PASSWORD
mkdir "$REMOTE_DB_DIR"
cd $REMOTE_DB_DIR
if [ $? -ne 0 ]; then
mkdir "$REMOTE_DB_DIR"
fi
bye
EOF
@ -150,10 +154,8 @@ done
# Determine email status
if [ $LOCAL_STATUS -eq 0 ] && [ $FTP_STATUS -eq 0 ]; then
EMAIL_STATUS="SUCCESS"
elif [ $LOCAL_STATUS -eq 1 ] || [ $FTP_STATUS -eq 1 ]; then
EMAIL_STATUS="FAILED"
else
EMAIL_STATUS="WARNING"
EMAIL_STATUS="FAILED"
fi
# Send the email with the log
@ -162,4 +164,12 @@ send_email
# Remove the log file after sending the email
rm -f $LOG_FILE
echo "Backup process complete, local status: $LOCAL_STATUS, FTP status: $FTP_STATUS, and email sent."
# Send the email with the log
send_email
# Remove the log file after sending the email
rm -f $LOG_FILE
echo "Backup process complete, local status: $LOCAL_STATUS, FTP status: $FTP_STATUS, and email sent."