Druva inSync Last Backup Extension Attribute

arzate
New Contributor

Hi all wanted to share this in hopes it's useful for anyone. I wanted a way to be able to collect the last backup done by Druva inSync just to avoid having to go to two different interfaces to find out. It could be improved a bit more, but it does what I need it to do at this moment. I also wanted to avoid having to install anything extra. 


#!/bin/bash

#Created: 5-05-2023
#Description: Runs through all druva insync logs for that last finished backup cycle and returns the date and time

# Get the current GUI user's username
gui_user=$(stat -f '%Su' /dev/console)
# Loop through the log files in reverse chronological order until the "Finished backup cycle" line is found
backup_finished=""
IFS=''
log_files=$(ls -t "/Users/$gui_user/Library/Application Support/inSync/logs/inSyncClient"*."log")
while IFS= read -r log_file; do
    if tail -n 50 "$log_file" | grep -q "Finished backup cycle."; then
        echo $log_file
        backup_finished=$(tail -n 50 "$log_file" | grep "Finished backup cycle" | cut -d'[' -f2 | cut -d']' -f1 | sed 's/,.*//')
        break
    fi
done <<< "$log_files"
 
# If the phrase is found, set the attribute value to the date and time
if [ -n "$backup_finished" ]; then
    echo "<result>$backup_finished</result>"
else
    echo "<result>0000-00-00 00:00:00</result>"
fi
0 REPLIES 0