# Feature-Request: Start backup only if some host is available

**URL:** <https://forum.duplicati.com/t/feature-request-start-backup-only-if-some-host-is-available/11169>\
**Category:** Features\
**Created:** [November 19, 2020, 12:10pm UTC](https://forum.duplicati.com/t/feature-request-start-backup-only-if-some-host-is-available/11169 "2020-11-19T12:10:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkn777](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@tkn777](https://forum.duplicati.com/u/tkn777)\
**Post date:** [November 19, 2020, 12:10pm UTC](https://forum.duplicati.com/t/feature-request-start-backup-only-if-some-host-is-available/11169/1 "2020-11-19T12:10:41Z")

</div>

Hi there,

it would be great, if there is a feature, so that a backup is only started, if a specified host is available.

Background: I am using duplicati on my laptop. But sometimes I have no or a limited internet connection. So the backup should wait until my backup server is available.

Thanks in advance  
Thomas

---

<div class="post-metadata">

**Author:** ![drwtsn32](https://forum.duplicati.com/user_avatar/forum.duplicati.com/drwtsn32/32/2591_2.png) [@drwtsn32](https://forum.duplicati.com/u/drwtsn32)\
**Post date:** [November 20, 2020, 12:08am UTC](https://forum.duplicati.com/t/feature-request-start-backup-only-if-some-host-is-available/11169/2 "2020-11-20T00:08:30Z")

</div>

Welcome to the forum!

You can do this with [–run-script-before](https://duplicati.readthedocs.io/en/latest/06-advanced-options/#run-script-before) and a custom errorlevel for the batch file. Errorlevel 1 is probably what you want unless you want a warning/error to be triggered:

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

```

Is this on Windows? Here’s an example of what to put in your batch file:

```
ping -n 2 hostname || exit 1

```

Edit: ping on Windows doesn’t seem to return a testable error code, so the above actually doesn’t work. ping works as a test on Linux, though. For Windows you’ll want to use something else.

---

<div class="post-metadata">

**Author:** ![max](https://forum.duplicati.com/user_avatar/forum.duplicati.com/max/32/6084_2.png) [@max](https://forum.duplicati.com/u/max)\
**Post date:** [August 18, 2021, 10:28am UTC](https://forum.duplicati.com/t/feature-request-start-backup-only-if-some-host-is-available/11169/3 "2021-08-18T10:28:32Z")

</div>

Hello,  
i have the same Problem like [tkn777] but the solution from [drwtsn32] dont work for me. I also use duplicati on my laptop.

I would like the backup to start automatically when I’m at home (e.g. via a certain wlan ssid)

Also the option that the backup only starts when the laptop is connected to the power would be useful.

Also the option that a backup is made when a USB stick with a certain name is connected would be useful. alternatively, a certain file could be stored on the usb stick to check whether the correct stick is connected. but please not with “–run-script-before” that is too complicated for many people.

For me, duplicati is already the best backup program, but many other backup programs have these options, it would be great if duplicati becomes more user-friendly.

Thanks max

---

<div class="post-metadata">

**Author:** ![drwtsn32](https://forum.duplicati.com/user_avatar/forum.duplicati.com/drwtsn32/32/2591_2.png) [@drwtsn32](https://forum.duplicati.com/u/drwtsn32)\
**Post date:** [August 18, 2021, 9:05pm UTC](https://forum.duplicati.com/t/feature-request-start-backup-only-if-some-host-is-available/11169/4 "2021-08-18T21:05:39Z")

</div>

I’m curious as to why it didn’t work. Do you need help developing a pre-backup script? Can you show me what you tried?

---

<div class="post-metadata">

**Author:** ![drwtsn32](https://forum.duplicati.com/user_avatar/forum.duplicati.com/drwtsn32/32/2591_2.png) [@drwtsn32](https://forum.duplicati.com/u/drwtsn32)\
**Post date:** [August 24, 2021, 1:10pm UTC](https://forum.duplicati.com/t/feature-request-start-backup-only-if-some-host-is-available/11169/5 "2021-08-24T13:10:37Z")

</div>

I was revisiting this and just realized my ping example doesn’t work on Windows! Something similar works on Linux, and I incorrectly assumed it would also work with Windows. Unfortunately ping on Windows doesn’t seem to return a testable error condition.

So you’ll probably want to use something besides ping to do the test on Windows.

---

<div class="post-metadata">

**Author:** ![ts678](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@ts678](https://forum.duplicati.com/u/ts678)\
**Post date:** [August 24, 2021, 2:24pm UTC](https://forum.duplicati.com/t/feature-request-start-backup-only-if-some-host-is-available/11169/6 "2021-08-24T14:24:54Z")

</div>

> [@drwtsn32](#):
>
> Unfortunately ping on Windows doesn’t seem to return a testable error condition.

It does, but not the way I’d prefer. It’s thrown off by things like “Destination host unreachable” responses.

[Destination host unreachable, but the errorlevel is 0 (from a win7) [closed]](https://serverfault.com/questions/372673/destination-host-unreachable-but-the-errorlevel-is-0-from-a-win7) links to [Ping Errorlevel](https://www.tek-tips.com/viewthread.cfm?qid=304609) script.

Or if you trust my shaky Command Prompt skills, a one-liner demo similar to the original might be to do:

> ping -n 1 hostname | find “Reply” \> NUL || exit 1

> [@max](#):
>
> I would like the backup to start automatically when I’m at home

I think the “Destination host unreachable” oddity is relevant to hosts on local network. Is that your case?  
If so, maybe look-for-an-actual-Reply fix will help. If not, then I’m not sure exactly what the situation is…

> [@max](#):
>
> Also the option that a backup is made when a USB stick with a certain name is connected would be useful. alternatively, a certain file could be stored on the usb stick to check whether the correct stick is connected.

I don’t think there’s normally a guarantee of the Windows drive letter the USB stick will receive, but see  
[Windows Drive Letters](https://www.duplicati.com/articles/Windows-Drive-Letters/) which describes the [Local folder or drive](https://duplicati.readthedocs.io/en/latest/05-storage-providers/#local-folder-or-drive) options `alternate-target-paths` to handle the potentially changing drive letter, and `alternate-destination-marker` for your “certain file”.

It’s not an automatic start, has no friendly GUI, but is a start. Look for related forum topics for more info.

> [@max](#):
>
> it would be great if duplicati becomes more user-friendly.

This is all limited by lack of new developers to add things… Volunteers are also encouraged in all areas.

---

<div class="post-metadata">

**Author:** ![drwtsn32](https://forum.duplicati.com/user_avatar/forum.duplicati.com/drwtsn32/32/2591_2.png) [@drwtsn32](https://forum.duplicati.com/u/drwtsn32)\
**Post date:** [August 24, 2021, 2:49pm UTC](https://forum.duplicati.com/t/feature-request-start-backup-only-if-some-host-is-available/11169/7 "2021-08-24T14:49:45Z")

</div>

> [@ts678](#):
>
> It does, but not the way I’d prefer. It’s thrown off by things like “Destination host unreachable” responses.

Ah, you’re right. If I only get “request timed out” then it works. Or if DNS resolution fails it works.
