Last active
December 8, 2019 17:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" ] ; then | |
echo "[1/2] 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/2] Older than $timeago, starting backup now" | |
notify-send "Backup" "Starting backup $backupname" | |
veeamconfig job start --name $backupname --retriable --scheduled --highpriority | |
else | |
echo "[-/2] Backup made shorter than $timeago, skipping" | |
fi | |
else | |
echo "[-/2] Discharging battery, skipping" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment