Skip to content

Instantly share code, notes, and snippets.

@snevas
Last active April 29, 2025 17:21
Show Gist options
  • Save snevas/0c82936437aa1f784587c028bf0c54dc to your computer and use it in GitHub Desktop.
Save snevas/0c82936437aa1f784587c028bf0c54dc to your computer and use it in GitHub Desktop.
The fixed time shedule does not work great with inregularly used laptops, that's why I made this conditional script that I run from a cronjob every hour. When not at home, it cannot mount the CIFS location, so it will also not backup. To be able to use notifications: add local user to veeam group and run the script with the cron of that user.
#!/bin/bash
# Cron every hour
backupname=full
timeago='1 day ago'
echo "Starting backup checks at $(date)"
# Check if not on battery
if [ $(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep state | awk '{print $2}') != "discharging" ] || [ "$1" == "-1" ]; then
echo "[1/3] Not discharging, continuing"
datetime=$(veeamconfig session list | grep Success | tail -1 | awk '{print $7 "T" $8}')
dtSec=$(date --date "$datetime" +'%s')
taSec=$(date --date "$timeago" +'%s')
#echo "INFO: dtSec=$dtSec, taSec=$taSec" >&2
# Check if last successful is older then $timeago
if [ $dtSec -lt $taSec ] ; then
echo "[2/3] Older than $timeago, starting backup now"
notify-send "Backup" "Starting backup $backupname"
nrBack=$(veeamconfig backup info --id \{5111a152-2da5-4b20-8111-90d69a1cbd81\} |grep false| wc -l)
if [ $nrBack -eq 7 ] ; then
echo "[3/3] $nrBack backups, so doing Active Full"
rm -rf /.veeamsnapstorage/
veeamconfig job start --activeFull --name $backupname --retriable
else
echo "[3/3] $nrBack backups, so doing incremental"
veeamconfig job start --name $backupname --retriable
fi
else
echo "[-/3] Backup made shorter than $timeago, skipping"
fi
else
echo "[-/3] Discharging battery, skipping. Add "-1" as argument to ignore"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment