TiNa - Géneration de rapports de sauvegardes

Ce script Bash permet de générer automatiquement un rapport sur l’état des sauvegardes dans TiNa. Il collecte différentes informations relatives aux sauvegardes, à la configuration du catalogue ainsi qu’à l’état des cartouches utilisées par l’infrastructure de sauvegarde.

Le script produit plusieurs fichiers de rapport aux formats CSV et texte contenant les détails des sauvegardes exécutées, la configuration du serveur TiNa et l’inventaire des cartouches. Il extrait également les éventuelles erreurs liées aux lecteurs de bandes détectées dans les événements récents.

Une fois les rapports générés, le script envoie automatiquement un email contenant un résumé du système ainsi que les fichiers de rapport en pièces jointes aux adresses définies dans la configuration. Les fichiers temporaires sont ensuite supprimés.

Script Bash

Ce script est conçu pour être exécuté automatiquement via une tâche planifiée (cron), permettant ainsi l’envoi régulier de rapports de sauvegarde aux administrateurs système.

#!/bin/bash
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# Last version : V2 - 2026-02-26
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# README ═══════════════════════════════════════════════════════════════════════════════════════════
# This script allows editing a report of the backups from the Atempo Tina solution to one or more
# defined email addresses
# The credentials file has to be created manually before to execute the script.
# The following line shall be added to the crontab -------------------------------------------------
# 00 8 * * 1 /root/TiNa-scripts/TiNa-Backup-report.sh
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

#=======================================
# VARIABLES DEFINITION
#=======================================
# Tina Bin
PATH_TINA=/usr/Atempo/TimeNavigator/myCatalog/Bin/
# PATH files
PATH_BCKP_REPORT=/root/TiNa-scripts/reports/$(date +%Y-%m-%d)-Backups-Report.csv
PATH_CATA_REPORT=/root/TiNa-scripts/reports/$(date +%Y-%m-%d)-Catalog-Report.txt
PATH_CART_REPORT=/root/TiNa-scripts/reports/$(date +%Y-%m-%d)-Cartridges-Report.csv
PATH_BCKP_TMP_REP=/root/TiNa-scripts/reports/$(date +%Y-%m-%d)-Backups-Report_tmp.csv
PATH_CRED=$(cat /opt/tina_report/.credentials/tina_login)
# Mail param
MAIL_FROM="[email protected]"
MAIL_SUBJ="[TiNa] - BACKUPS List Report"
MAIL_TO="[email protected]"

#=======================================
# BACKUP REPORT CREATION - CSV
#=======================================
backup_creation_file(){

# Generate the report
"${PATH_TINA}"./tina_acct \
-identity "${PATH_CRED}" \
-output_format csv \
-file "${PATH_BCKP_REPORT}" \
-csv_separator "," \
-v_description \
-start_date $(echo `date -d "now -3650 days" +%Y%m%d`0000) \
-end_date $(echo `date +%Y%m%d%H%M`) \
-catalog my \
-volume_unit giga \
-v_report_date -v_dates -v_platform -v_jobid -v_jobtype -v_elapsed -v_volume -v_objects -v_cart -v_status -v_barcode -v_priority

# Editing the report
sed -i -E -e 's/(^Duplication|^Backup)(.*)/\2\1/g' -e "s/ of Job .*: //g" -e '/^Catalog Collect/d' -e '/\?\?\?\?\?\?/d' "${PATH_BCKP_REPORT}"
sed -i -e 's/^Backup //g' -e 's/^ //g' "${PATH_BCKP_REPORT}"
awk -F, '{ t = $19; $19 = $20; $20 = t; print; }' OFS=, "${PATH_BCKP_REPORT}" > "${PATH_BCKP_TMP_REP}" && mv "${PATH_BCKP_TMP_REP}" "${PATH_BCKP_REPORT}" 2>&1
sed -i -E -e '1s/.*/Host,Report Date,Submit Date,Execution Date,End Date,Platform,ID,Type,Mode,Elapsed Time,Processed volume,Unit,Number of Objects,Format,Cartridges,Number of Cartridges,Status,Alarm,Description,Priority/g' "${PATH_BCKP_REPORT}"

}

#=======================================
# BACKUP REPORT CREATION - TXT
#=======================================
catalog_creation_file(){

# Extract information of server configuration and scheduled backups
"${PATH_TINA}"./tina_config -identity "${PATH_CRED}" -catalog my > "${PATH_CATA_REPORT}" 2>&1

}

#=======================================
# BACKUP REPORT CREATION - CSV
#=======================================
cartridge_creation_file(){

# Options
COMMON_OPTS=(-all -status -v_name -v_barcode -v_volume -v_unit -v_creation_date -v_backup_date -v_status -v_location -v_pool_label)

# Pools
POOLS=(P_1M- P_1Y- P_2M- P_2Y- P_3M- P_3Y- P_4M- P_6M- P_7D- P_2W-)

# Writting
for i in "${!POOLS[@]}"; do
if [ "$i" -eq 0 ]; then
"${PATH_TINA}"./tina_cart_control -identity "${PATH_CRED}" -output_format csv -csv_separator "," -pool "${POOLS[i]}" "${COMMON_OPTS[@]}" > "${PATH_CART_REPORT}" 2>&1
else
"${PATH_TINA}"./tina_cart_control -identity "${PATH_CRED}" -output_format csv -csv_separator "," -pool "${POOLS[i]}" "${COMMON_OPTS[@]}" >> "${PATH_CART_REPORT}" 2>&1
fi
done

}

#=======================================
# ROBOT DRIVES INFORMATIONS
#=======================================
drives_infos(){
DRIVES_INFOS=$(/usr/Atempo/TimeNavigator/codac/Bin/tina_event -f_date $(date -d "8 days ago" +"%Y%m%d%H%M") $(date +"%Y%m%d%H%M") | grep "Disabling the drive")
}

#=======================================
# SEND MAIL
#=======================================
send_report(){

# BODY
MAIL_BODY=$(cat <<EOF
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ Monthly Backup Report Of $HOSTNAME
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ Date: $(date +%Y-%m-%d)
┃ Uptime: $(uptime | awk -F'up ' '{print $2}' | awk -F',' '{print $1}')
┃ System: $(cat /etc/redhat-release)
┃ Kernel: $(uname -r)
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ Attached files:
┃ - $(date +%Y-%m-%d)-Backups-Report.csv
┃ - $(date +%Y-%m-%d)-Catalog-Report.txt
┃ - $(date +%Y-%m-%d)-Cartridges-Report.csv
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ Drives errors logs (7 days):
┃ ${DRIVES_INFOS}
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
)

# Send mail if file not empty
if [[ -s "${PATH_BCKP_REPORT}" ]]; then
echo "$MAIL_BODY" | mail -s "${MAIL_SUBJ}" -r "${MAIL_FROM}" \
-a "${PATH_BCKP_REPORT}" \
-a "${PATH_CART_REPORT}" \
-a "${PATH_CATA_REPORT}" \
"${MAIL_TO}"
fi

}

#=======================================
# FILE DELETION
#=======================================

file_deletion() {
# Liste des fichiers à supprimer
FILES=(
"$PATH_BCKP_TMP_REP"
"$PATH_BCKP_REPORT"
"$PATH_CATA_REPORT"
"$PATH_CART_REPORT"
)

# Suppression si le fichier existe
for f in "${FILES[@]}"; do
[ -f "$f" ] && rm -f "$f"
done
}


#========================================
# Main Program
#========================================

backup_creation_file
catalog_creation_file
cartridge_creation_file
drives_infos
send_report
file_deletion
exit 0

Documentation

Man TiNa
Man bash

🡅 Partager