# Improvements for --run-script-before/after options

**URL:** https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519
**Category:** Features
**Created:** [September 8, 2017, 6:44pm UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519 "2017-09-08T18:44:57Z")
**Posts on this page:** 12
**Page:** 1

<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: [September 8, 2017, 6:44pm UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/1 "2017-09-08T18:44:57Z")

</div>

from the runscript helptext of `--run-script-before-required`:

> If the script returns a non-zero error code or times out, the operation will be aborted.

The ParsedResult will always be Failed if the script returns an errorlevel other than 0. There is no way to just skip the backup when a specific condition has met.

This can be improved by allowing multiple error levels:

```plaintext
Errorlevel 0: Everything is OK, start backup task
Errorlevel 1: Everything is OK, but don't run the backup
Errorlevel 2: There is something wrong, raise ParsedResult to Warning, add script output to Warning section in Result file. Run the backup.
Errorlevel 3: There is something wrong, raise ParsedResult to Warning, add script output to Warning section in Result file. Don't run the backup.
Errorlevel 4: There is something wrong, raise ParsedResult to Failed, add script output to Error section in Result file. Run the backup.
Errorlevel 5: There is something wrong, raise ParsedResult to Failed, add script output to Error section in Result file. Don't run the backup.

```

This makes `--run-script-before-required` unnecessary, because this way `--run-script-before` combines both options, but it could be kept for compatibility reasons.

Duplicati could parse the errorlevels the same way for `--run-script-after` (0,1=OK, 2,3=Warning, 4,5=Failed) to raise the ParsedResult value to Warning or Failed after a backup job has run.

---

<div class="post-metadata">

### Author: ![DennisDD](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/d/c37758/32.png) [@DennisDD](https://forum.duplicati.com/u/DennisDD)
#### Post date: [October 4, 2017, 3:44pm UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/2 "2017-10-04T15:44:11Z")

</div>

+1 for more distinctions in exit codes. I use run-script-before in this context: [Backup only when host is reachable; retry backup that was missed due to connection issues](https://forum.duplicati.com/t/backup-only-when-host-is-reachable-retry-backup-that-was-missed-due-to-connection-issues/721/5)

I wish ErrorLevel 1 would be available to use …

---

<div class="post-metadata">

### Author: ![thommyX](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@thommyX](https://forum.duplicati.com/u/thommyX)
#### Post date: [January 25, 2018, 9:45am UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/3 "2018-01-25T09:45:57Z")

</div>

This is an execellent suggestion!

An extention could be to give all parameters to the script! So it would be possible to make a general script that checks e.g. the target and one script can do that for all file jobs, another for webdav jobs. So no need to make an extra script for each job.

If we have a job

```
"C:\Program Files\Duplicati 2\Duplicati.CommandLine.exe"
backup
"file://blabla" 
"\\source1" 
"\\source2" 
"\\pathtodatabse\Duplicati-server.sqlite" 
--backup-name="name" 
--dbpath="name.sqlite" 
--encryption-module="aes" 
--compression-module="zip" 
--dblock-size="10MB" 
--passphrase="xxxxxxxxxxxxxxxx" 
--allow-missing-source="true" 
--disable-module="console-password-input" 
--run-script-before-required="myscript.cmd"

```

It should call

```
myscript.cmd 
backup
"file://blabla" 
"\\source1" 
"\\source2" 
"\\pathtodatabse\Duplicati-server.sqlite" 
--backup-name="name" 
--dbpath="name.sqlite" 
--encryption-module="aes" 
--compression-module="zip" 
--dblock-size="10MB" 
--passphrase="xxxxxxxxxxxxxxxx" 
--allow-missing-source="true" 
--disable-module="console-password-input" 
--run-script-before-required="myscript.cmd"

```

Then myscript can check //file:blabla or it can decide (eg. on the jobname or if the target starts with file:) what to check and also write a meaningful logfile.

---

<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: [January 25, 2018, 10:48am UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/4 "2018-01-25T10:48:26Z")

</div>

Almost all of this information is available in environment variables that you can check in your script.  
More info here:

> [@Duplicati Environment Variables](https://forum.duplicati.com/t/duplicati-environment-variables/1645):
>
> I am told that Duplicati has environment variables that can be used in scripts. They are usually DUPLICATI\_. Can someone point me in the direction of the Duplicati environment variables for Linux, in the documentation?

---

<div class="post-metadata">

### Author: ![Stephen](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Stephen](https://forum.duplicati.com/u/Stephen)
#### Post date: [February 13, 2018, 6:46am UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/5 "2018-02-13T06:46:12Z")

</div>

I really like the idea of the errorlevel handling when returning to duplicati from the run before script. +1

---

<div class="post-metadata">

### Author: ![boran\_blok](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@boran\_blok](https://forum.duplicati.com/u/boran_blok)
#### Post date: [August 9, 2018, 7:10am UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/6 "2018-08-09T07:10:50Z")

</div>

Another vote for this feature.

I use a script to decline backups outside daytime hours so I can use night for maintenance.  
And it is kind of annoying to have all these marked as failed.

They arent failed, it is supposed to not backup at that moment.

---

<div class="post-metadata">

### Author: ![JonMikelV](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@JonMikelV](https://forum.duplicati.com/u/JonMikelV)
#### Post date: [August 14, 2018, 3:01am UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/7 "2018-08-14T03:01:16Z")

</div>

Thanks for bumping this back up.

@kenkendk, unless there is a particular reason we would NOT want to handle script return codes as @kees-z proposed in the original post I think I’ll try to create a GitHub issue requesting it…

---

<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: [August 14, 2018, 6:38am UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/8 "2018-08-14T06:38:55Z")

</div>

Yes, sounds as a simple and great improvement.  
I will add it asap.

---

<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: [August 14, 2018, 9:10am UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/9 "2018-08-14T09:10:29Z")

</div>

Done: [Added support for multiple exit codes, and added a unittest to verify… · duplicati/duplicati@494fccd · GitHub](https://github.com/duplicati/duplicati/commit/494fccd9316da42c0e65ad8527902ced4f7733af)

---

<div class="post-metadata">

### Author: ![JonMikelV](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@JonMikelV](https://forum.duplicati.com/u/JonMikelV)
#### Post date: [August 14, 2018, 5:14pm UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/10 "2018-08-14T17:14:14Z")

</div>

Thank you!

You did in 3 hours what I probably would have taken 3 weeks to approximate - if there was a way to “like” a post more than once, I’d be sure to do it!

---

<div class="post-metadata">

### Author: ![JonMikelV](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@JonMikelV](https://forum.duplicati.com/u/JonMikelV)
#### Post date: [November 28, 2018, 9:16pm UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/11 "2018-11-28T21:16:26Z")

</div>

So can this be “Solved” and taken out of Planned mode based on this release?

> [@Release: 2.0.3.10 (canary) 2018-08-30](https://forum.duplicati.com/t/release-2-0-3-10-canary-2018-08-30/4497):
>
> [2.0.3.10-2.0.3.10\_canary\_2018-08-30](https://github.com/duplicati/duplicati/releases/tag/v2.0.3.10-2.0.3.10_canary_2018-08-30) Updated the help text for no certificates found, thanks @jonmikeiv Fixed logging details, thanks @mnaimanFixed error messages on repair, thanks @mnaimanRefactored the FTP backend, thanks @verhoekRewrote the lock on database queries to be simpler and less CPU intensive Removed some logging details in core performance areas (can be re-enabled with --profile-all-database-queries) Removed automatic attempts to rebuild dblock files as it is slow and rarely …

For the record it looks like the acceptable return codes are:

- 0 (run the job)
- 1 (abort job silently)
- 3 (abort job with warning)
- 5 (abort job with error)

---

<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: [November 29, 2018, 9:11am UTC](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/12 "2018-11-29T09:11:49Z")

</div>

> [@JonMikelV](#):
>
> So can this be “Solved” and taken out of Planned mode based on this release?

Yes. This is now in the beta release.
