Question

Query: Setting up Automatic Power-Off After Veeam Backup Completion


Userlevel 5

Hello Forum Members,

I'm currently using Veeam Backup and am keen on configuring an automatic power-off for the system once the backup process is completed. Could anyone kindly provide guidance on how to set up this feature, or direct me to the relevant documentation?

Your insights and assistance would be highly valuable.


14 comments

Userlevel 7
Badge +17

I assume this is a Backup Job within Veeam Backup & Replication? And, you want to power off a server/computer after the job is finished? What you could do is, within the Job > Storage section > Advanced button > Scripts tab, create a powershell script to power off the computer after the job runs.
 



See here from the User Guide. Make sure the script (PoSH, or whatever language you choose) is placed in a local folder on the Veeam Server, then browse to the folder and select the script. 

As with any Job change, I would test this first before using in production. Create a test job with a couple test VMs. Create the Script to power off 1 of the VMs (or all of them if that’s what you wanna do), then create the Job & adding the script. Run the Job and see if it behaves as you want it to.

Userlevel 5

i have done this already, it didnt power off the server!

 

Userlevel 7
Badge +17

Did you test your script alone to verify it works? If so, and again..if your script is on the Veeam server, yet still doesn’t work, I’d reach out to Veeam Support to get some assistance.

Userlevel 5

Thank you for your response.

I believe I have identified the issue; it is related to User Account Control (UAC). When I execute the .bat or .ps1 script, it fails with an "access denied" error unless I run the command prompt with administrative rights. I suspect this is associated with the UAC.

Please let me know if you have any further insights or if there's anything specific we should address regarding the UAC.

Userlevel 7
Badge +17

You can try disabling UAC on the system...if your org policy allows you to. Or to test, at least disable it for 1 job run to see your script successfully executes.

Another thing to be aware of, the script executes as the account used for the Veeam Backup Service on the VBR server. You can try a domain account to use for the Veeam Backup Service account. Place the domain account in the local Administrators group on the VBR server, as well as grant it Log On As a Service and db_owner rights to the configuration DB. Then, on the server in the job you want to execute the script against, add the domain account to the local Admin group there then re-attempt your Job and script.

Userlevel 7
Badge +7

Another option you can try, would be to query the status of the jobs and if there are no jobs running, shutdown the server. 

You could use PowerShell to query the job status

https://helpcenter.veeam.com/docs/backup/powershell/get-vbrsession.html?ver=120

The downside is that you would need to run the check at given intervals, so possibly as a Scheduled task with a user account that has the bare minimum of permissions to be able to shutdown the server and nothing more. 

 

Userlevel 7
Badge +20

As an aside from the conversation, why do you want the Veeam server powered down? That will just make your RTO longer for performing restorations?

Userlevel 7
Badge +22

Hi, if this is for security reasons, then keep in mind if your repository is not on the VBR server (i.e. an all in one) and you leave your repository server running then there is little gained from a security standpoint by just turning off the VBR server.

Userlevel 5

As an aside from the conversation, why do you want the Veeam server powered down? That will just make your RTO longer for performing restorations?

 @MicoolPaul I do have my reasons for powering off this server. We have four Veeam servers, each one efficiently performing its job. There's no need to have two servers running continuously and consuming electricity. I'm referring to physical servers.

Userlevel 5

Another option you can try, would be to query the status of the jobs and if there are no jobs running, shutdown the server. 

You could use PowerShell to query the job status

https://helpcenter.veeam.com/docs/backup/powershell/get-vbrsession.html?ver=120

The downside is that you would need to run the check at given intervals, so possibly as a Scheduled task with a user account that has the bare minimum of permissions to be able to shutdown the server and nothing more. 

 

I'm looking for a batch file that shuts down the server only after it has completed tasks like converting backups or checking the backup health. The current script shuts down the server even when these tasks are still in progress. I want the script to initiate the shutdown only when all the jobs, health scans, and other tasks are done. Unfortunately, the existing script is not functioning correctly. Do you happen to have a working script that achieves this?

Userlevel 7
Badge +17

Hi @VEEAM_Legend , I interpreted incorrectly what you’re goal was here. You aren’t wanting to power down a VM server within a Backup Job after a Backup Job run, but rather power down the VBR server? There is no way to do this within Veeam. There is only 1 way I know of to accomplish this. You can do so in Windows, but it would be a bit of a guessing game → to configure this, you simply need to create a Windows Task in Task Scheduler to run your powerdown PoSH or BAT script after all your jobs run. This is where the ‘guessing game’ comes. You need to set a time for the script Task to run when your jobs are finished. The only way to know when they’re finished running is look at the Job history of the last running job and see how long it takes to run...or at least the longest time it takes to run. Then configure the Task to run a set time (an additional hr?) after the longest Job run time just to be safe. 

Obviously, this isn’t ideal because a job could take longer for any of a number of reasons → problem with the backup method causing it to revert to Network mode and thus taking longer; healthcheck and other maintenance tasks which generally run after a job and take an unknown variable amount of time to complete, etc.

Userlevel 5

Hi @VEEAM_Legend , I interpreted incorrectly what you’re goal was here. You aren’t wanting to power down a VM server within a Backup Job after a Backup Job run, but rather power down the VBR server? There is no way to do this within Veeam. There is only 1 way I know of to accomplish this. You can do so in Windows, but it would be a bit of a guessing game → to configure this, you simply need to create a Windows Task in Task Scheduler to run your powerdown PoSH or BAT script after all your jobs run. This is where the ‘guessing game’ comes. You need to set a time for the script Task to run when your jobs are finished. The only way to know when they’re finished running is look at the Job history of the last running job and see how long it takes to run...or at least the longest time it takes to run. Then configure the Task to run a set time (an additional hr?) after the longest Job run time just to be safe. 

Obviously, this isn’t ideal because a job could take longer for any of a number of reasons → problem with the backup method causing it to revert to Network mode and thus taking longer; healthcheck and other maintenance tasks which generally run after a job and take an unknown variable amount of time to complete, etc.

Thank you for your answer.
this what i’ve been doing for the last 4 years.
every minute that the backup server is up, is kinda of risky which i am trying to avoid.
i’ll test the powershell scripts.

Userlevel 7
Badge +17

Sure..no problem. I’m not sure it’s something Veeam would consider adding, but it wouldn’t hurt to go over to the forums and add a feature request post for what you’re wanting.

Userlevel 7
Badge +17

Hi @VEEAM_Legend -

I’m just following up on your post here...did you ever get your power off task settled? Did one of the provided comments help? If so, or if resolved it on your own, we ask you mark one of the comments as ‘Best Answer’ so those with a similar need who come across your post may benefit.

Thank you.

Comment