Salta al contenuto principale

Use "Pre" / "Post" backup commands to send messages to users ?

Thread solved

Hello,

can you help to create working messages to users before and after backup ?

I currently tried to reference 2 powershell scripts to users but nothing happen, I certainly do something wrong.

I would also like the first "Pre" message to have a 2 min timer...

First Pre message script:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon

$objNotifyIcon.Icon = [System.Drawing.SystemIcons]::Information
$objNotifyIcon.BalloonTipIcon = "Info" 
$objNotifyIcon.BalloonTipText = "Weekly files backup status" 
$objNotifyIcon.BalloonTipTitle = "Backup will start in 2 minutes, please plug your backup drive !"
$objNotifyIcon.Visible = $True

$objNotifyIcon.ShowBalloonTip(10000)
Start-Sleep 500

2nd Post message script:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon

$objNotifyIcon.Icon = [System.Drawing.SystemIcons]::Information
$objNotifyIcon.BalloonTipIcon = "Info" 
$objNotifyIcon.BalloonTipText = "Weekly files backup status" 
$objNotifyIcon.BalloonTipTitle = "Backup completed, you can unplug your backup drive."
$objNotifyIcon.Visible = $True

$objNotifyIcon.ShowBalloonTip(10000)
Start-Sleep 500

Thank you for your tips

1 Users found this helpful

Hello Romain!

For future reference here are some tips to debugging scripts: https://kb.acronis.com/content/46690

I setup a quick test for your script. Here's some info:

  • The scripts need to be stored where the agent that performs the backup can access it. It will be run by the user the agent is running under, so this user needs to be able to read and execute the script path you set in the plan
  • Unless you have set the powershell execution policy system wide you won't be able to run a powershell script. Check the end of the bost for a batch file that wraps a script with executionpolicy set
  • I've also experienced that setting a powershell file to execute while not having execution policy set makes the whole function broken. It took me various combination of recreating the plan, revoking, restarting the agent computer before pre/post commands started to work again with simple batch files.
  • Running the scripts you provided by hand from my machine works as expected. Though I had to remove the sleep from the post script to allow the wrapping batch to exit.
  • Printing some debug info into file within your script confirms it is running when executed by Acronis, however there is no notification as you observed.
  • On my machine the managed machine service is running under Local Machine. which is confirmed if I print out this to file (NT AUTHORITY\SYSTEM): [System.Security.Principal.WindowsIdentity]::GetCurrent().Name

My guess is it's not displaying because the script is running as another user. Googled around, but it appears to be more involved to get a toast notification to display when running as System. I leave that exercise to you.

Wrapping batch code:

@REM Call a powershell script with execution policy set
@echo off
set BatchDir=%~dp0
set ScriptPath=%~dp0%1
echo executed> pre-bat-executed.txt
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%ScriptPath%pre-backup.ps1'"

 -- Peter

Thanks a lots for your help ! 

I'll dig into Toast notification when I'll find some time, and I disable pre/post notifications for now, 
as it break my all backup :)

 

thanks for the time and investigation !

 

I'll update here if I suceed with Toast content - UWP applications | Microsoft Docs