Feature Request: Don't backup if no session opened (windows)

Hi,

The option to NOT backup when NO session is running would be interresting on Windows

Thanks

So I understand, you scenario is:

  • Installed Duplicati as a service on Windows
  • No user is logged in to the server

What should happen with scheduled backups?

  • Postpone?
  • Cancel?

Can you explain in a few words what the benefit would be to you if this was implemented?

You could use –run-script-before run run a script like this:

@echo off
if not %DUPLICATI__OPERATIONNAME%==BACKUP goto :eof
for /f "skip=1 tokens=1" %%a in ('query user') do (set usersession=TRUE)
if "%usersession%"=="TRUE" exit 1

This will query the current user sessions and exit with exit code 1 if there are 1 or more users logged on.
Exit code 1 will prevent running the backup without any errors, see Example Scripts.

1 Like

Sorry for my english

Yes it’s the scenario.

I think the scheduled backup should be postponed in the same way as when the computer is off.

Benefit : In my configuration :

  • the destination folder is calculated by the script-before/after to be like \server\share\computername\activeuser

  • the source folder is c:\users\activeuser.…

Activeuser is the result of this command :
for /F “tokens=1,2” %%i in (‘qwinsta /server:%COMPUTERNAME% ^| findstr “console”’) do set activeuser=%%j

If no user is logged, ActiveUser returns a number (1 or 2) that corresponds to the system account and the backup returns errors because c:\users\1 doesn’t exist.

Currently, to stop the backup, i set set OPERATIONNAME to “” and exit

@kees-z
Thank you, this is what i do (if there is no user logged on), but i think that this could be an interresting option to be added to Duplicati.

I wouldn’t recommend to dynamically change the source path between multiple user profile folders using a --run-before script.
When a backup starts using another source path than the prior backup, all files from the prior backup will be considered deleted. All files will be re-added as new fles after the first user logs in and all other files from the second user will again be considered deleted.

Instead, create separate backup jobs, one for each user. With a simple script, you can check if the user is actually logged on, if you like to do so.

I understand. In my case it’s not a problem because 1 computer = 1 user