Triggering Veeam Backups on Linux with SystemD
Veeam Backup is, in my opinion, one of the best free backup solutions available. The Linux version particularly shines with its ability to create snapshot backups of Ext4 partitions.
Unfortunately, the Linux version has a major drawback compared to its Windows counterpart: backup scheduling is extremely limited. You can only specify the day and hour for when backups should run. If the computer is asleep or powered off at that time, the backup won’t execute and, more importantly, won’t be rescheduled.
To work around this limitation, I had to get creative and combine SystemD timers, SystemD services, and some scripting.
Veeam CLI
You can also control Veeam jobs from outside the Terminal UI using the veeamconfig tool.
For example, you can start a backup with the following command:
veeamconfig job run --name "<JOBNAME>"
The catch is that this command is non-blocking and returns immediately. To check if the backup has completed and its status, you need to run:
veeamconfig job status --name "<JOBNAME>"
Since this command is also non-blocking, the only solution is polling. We need to repeatedly check if the job is still running until it either completes successfully or fails.
Here’s the key part of the polling script that handles the job monitoring:
# Extract session ID from job start output
SESSION_ID=$(echo "$OUTPUT" | grep -oP 'Session ID: \[\{\K[^}]+')
# Poll session status until completion
while true; do
STATUS=$(/usr/bin/veeamconfig session info --id "$SESSION_ID" | grep "State:")
STATE=$(echo "$STATUS" | grep -oP 'State:\s+\K\w+')
if [ "$STATE" = "Success" ] || [ "$STATE" = "Warning" ]; then
echo "Job completed with state: $STATE"
exit 0
elif [ "$STATE" = "Failed" ]; then
echo "Job failed!"
exit 1
fi
echo "Job still running... State: $STATE"
sleep $POLL_INTERVAL
done
The script also includes signal handling to gracefully stop backups if needed.
SystemD
The SystemD side was much more straightforward. SystemD timers allow me to wake the computer from sleep mode to start the backup. For this, you only need to set the option WakeSystem=true in the [Timer] block.
The service unit was just as little of a problem with the script. I only had to prevent the computer from going back to sleep while the backup is running. For this, I used systemd-inhibit.
SystemD Service
The service unit runs our script while preventing the system from sleeping during backups:
[Unit]
Description=Veeam Backup Job %i
After=network.target
[Service]
Type=simple
ExecStart=systemd-inhibit --what "sleep:idle:shutdown" --why "Veeam Backup %i" --who "Veeam Job" --mode "block-weak" /usr/local/bin/veeam-run-polling %i
Restart=no
SystemD Timer
This timer wakes your system and runs the backup every other day at 10:30 AM:
[Unit]
Description=Veeam Backup Timer for Job %i
[Timer]
OnCalendar=*-*-1/2 10:30:00
Persistent=true
WakeSystem=true
DeferReactivation=true
Unit=veeam-run@%i.service
[Install]
WantedBy=timers.target
All unit files and the script can be found at https://git.screebo.net/cperrin/veeam-systemd-timers.


