We send reports of Veeam agent Linux to mail or in Telegram

Greetings, Habr!



More recently, the company I work for started offering Veeam as the primary backup tool. And all would be fine, but the following was found out during the familiarization process:





Based on this, it turns out that if the organization uses only Linux, then you will not see any reports. Or we buy and install Windows, and already in it we install and configure everything that is required, and from there we get full information about the results of the Veeam agent (Linux). Or we go to each car and see how the next "working day" of the agent went there.



And then came the day when a small organization was found that uses only Linux and which really needs to be backed up and preferably for free. But daily to monitor how the agent worked there, I want to centrally, rather than massive raids on servers.



To solve this issue, I had to go to the FAQ on the Veeam website and read what we can get using the console and the available veeam agent commands. From the read, a small Bash script was born that looks at the result of the last task, and for one free space in a network folder designed to store backups.

Actually, I want to share this script. I warn you right away, I'm not good at scripting, so criticism and suggestions are welcome.



check_veeam_backup.sh
#!/bin/bash # PARAMETRS HOST=`hostname` REPORT_NAME_FORMAT="%d-%m-%Y" CURRENT_DATE_FORMAT="%d.%m.%Y" CURRENT_TIME_FORMAT="%H:%M:%S" REPORT_FILE=report_$(date +$REPORT_NAME_FORMAT).log #TOKEN="000000000:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" #RECIP_ID="00000000" REPOSITORY=" " MOUNT_POINT=" " # MOUNT_USER=" " # MOUNT_PASSWORD=" " # Get Veeam job list JOB_LIST=($(awk 'NR>1 {print$1}' <<< "$(veeamconfig job list)")) JOB_RESULT_PATH="/var/log/veeam/Backup/" echo -e "\nStart check on $(date +$CURRENT_DATE_FORMAT) at $(date +$CURRENT_TIME_FORMAT)\n" >> $REPORT_FILE # Check result Veeam backup job for JOB in $JOB_LIST do echo ------------------------------------------------------ >> $REPORT_FILE echo Check Schedule job name: $JOB from Host: $HOST >> $REPORT_FILE echo -e "------------------------------------------------------\n" >> $REPORT_FILE echo -e "$(veeamconfig schedule show --jobName $JOB)\n" >> $REPORT_FILE echo ------------------------------------------------------ >> $REPORT_FILE echo Check latest session Job name: $JOB from Host: $HOST >> $REPORT_FILE echo -e "------------------------------------------------------\n" >> $REPORT_FILE LAST_JOB_RESULT=$(ls -t $JOB_RESULT_PATH/$JOB | head -n1 | cut -c 25-) veeamconfig session info --id $LAST_JOB_RESULT >> $REPORT_FILE done echo ------------------------------------------------------ >> $REPORT_FILE echo Stop check on $(date +$CURRENT_DATE_FORMAT) at $(date +$CURRENT_TIME_FORMAT) >> $REPORT_FILE echo "\n" >> $REPORT_FILE # if the repository owner is not root # mount -t cifs -o user=$MOUNT_USER,password=$MOUNT_PASSWORD $REPOSITORY $MOUNT_POINT mount -t cifs $REPOSITORY $MOUNT_POINT echo ------------------------------------------------------ >> $REPORT_FILE echo -e "Check files in backup repository:\n" >> $REPORT_FILE ls -h $MOUNT_POINT >> $REPORT_FILE echo ------------------------------------------------------ >> $REPORT_FILE echo -e "Check free space on backup repository:\n" >> $REPORT_FILE echo -e "$(df -h $MOUNT_POINT)\n" >> $REPORT_FILE echo -e "------------------------------------------------------\n\n\n" >> $REPORT_FILE sleep 30 umount $MOUNT_POINT SEND_RESULT="$(echo -e "$(cat ${REPORT_FILE})")" # Send result to telegram # Uncomment the next line to send results to telegram # curl --silent --data "html&text=$SEND_RESULT" https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=$RECIP_ID&parse_mode= # Send result to email # Uncomment the next line to send the results by email and replace <your_mail@yuor_domain> # mail -s "Report $HOST - $(date +$CURRENT_DATE_FORMAT)" your_mail@yuor_domen < $REPORT_FILE # if you want delete report file, uncomment next line # rm -rf $REPORT_FILE #Delete log file
      
      







As a result of the script, a report will be prepared as follows:



 Start check on 10.09.2019 at 14:13:30 ------------------------------------------------------ Check Schedule job name: HP from Host: hp ------------------------------------------------------ Every day At: 23:00 Run automatically: enabled ------------------------------------------------------ Check latest session Job name: HP from Host: hp ------------------------------------------------------ Backup session ID: {555ebf40-2fb9-47cc-baf0-7192c0ae896e} Job name: HP Job ID: {435117d7-ace8-4009-9c51-b00e8174c252} State: Success Start time: 2019-09-06 22:43:19 End time: 2019-09-07 00:02:14 ------------------------------------------------------ Stop check on 10.09.2019 at 14:13:30 ------------------------------------------------------ Check files in backup repository: media media ------------------------------------------------------ Check free space on backup repository:      % C  //share/backup 1,8T 96G 1,7T 6% /media/backup_repository ------------------------------------------------------
      
      





Depending on the chosen method, the report will be sent either by mail or in Telegram (my case):







It remains to add the task to crontab, for example, every day at 9 am



0 9 * * * /scripts/check_veeam_backup.sh> / dev / null # Daily check at 9am



Now the script runs every morning and by the time the work day begins, all the information about the work of agents and available space on the backup server is at hand.



Not everything is smooth in the script, especially with a username and password for mounting a network folder, access to which only a special user has access to. But if you allow this user only read, then there is a clear plus. Your backups will never be rubbed by this user, even by accident.



All Articles