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

**URL:** <https://forum.duplicati.com/t/feature-request-dont-backup-if-no-session-opened-windows/18011>\
**Category:** Features\
**Created:** [May 31, 2024, 5:37am UTC](https://forum.duplicati.com/t/feature-request-dont-backup-if-no-session-opened-windows/18011 "2024-05-31T05:37:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://forum.duplicati.com/u/phil)\
**Post date:** [May 31, 2024, 5:37am UTC](https://forum.duplicati.com/t/feature-request-dont-backup-if-no-session-opened-windows/18011/1 "2024-05-31T05:37:09Z")

</div>

Hi,

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

Thanks

---

<div class="post-metadata">

**Author:** ![kenkendk](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kenkendk/32/5305_2.png) [@kenkendk](https://forum.duplicati.com/u/kenkendk)\
**Post date:** [May 31, 2024, 3:11pm UTC](https://forum.duplicati.com/t/feature-request-dont-backup-if-no-session-opened-windows/18011/2 "2024-05-31T15:11:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kees-z](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kees-z/32/29_2.png) [@kees-z](https://forum.duplicati.com/u/kees-z)\
**Post date:** [June 1, 2024, 3:28pm UTC](https://forum.duplicati.com/t/feature-request-dont-backup-if-no-session-opened-windows/18011/3 "2024-06-01T15:28:58Z")

</div>

You could use [–run-script-before](https://docs.duplicati.com/en/latest/06-advanced-options/#run-script-before) run run a script like this:

```plaintext
@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](https://docs.duplicati.com/en/latest/appendix-g-example-scripts/).

---

<div class="post-metadata">

**Author:** ![phil](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://forum.duplicati.com/u/phil)\
**Post date:** [June 3, 2024, 5:50am UTC](https://forum.duplicati.com/t/feature-request-dont-backup-if-no-session-opened-windows/18011/4 "2024-06-03T05:50:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![phil](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://forum.duplicati.com/u/phil)\
**Post date:** [June 3, 2024, 5:55am UTC](https://forum.duplicati.com/t/feature-request-dont-backup-if-no-session-opened-windows/18011/5 "2024-06-03T05:55:37Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![kees-z](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kees-z/32/29_2.png) [@kees-z](https://forum.duplicati.com/u/kees-z)\
**Post date:** [June 10, 2024, 11:48am UTC](https://forum.duplicati.com/t/feature-request-dont-backup-if-no-session-opened-windows/18011/6 "2024-06-10T11:48:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![phil](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://forum.duplicati.com/u/phil)\
**Post date:** [June 11, 2024, 5:19am UTC](https://forum.duplicati.com/t/feature-request-dont-backup-if-no-session-opened-windows/18011/7 "2024-06-11T05:19:31Z")

</div>

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