# How to only write to external USB drive on Linux when it's attached?

**URL:** <https://forum.duplicati.com/t/how-to-only-write-to-external-usb-drive-on-linux-when-its-attached/10414>\
**Category:** Support\
**Created:** [August 3, 2020, 4:39pm UTC](https://forum.duplicati.com/t/how-to-only-write-to-external-usb-drive-on-linux-when-its-attached/10414 "2020-08-03T16:39:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimbudarz](https://forum.duplicati.com/user_avatar/forum.duplicati.com/jimbudarz/32/4726_2.png) [@jimbudarz](https://forum.duplicati.com/u/jimbudarz)\
**Post date:** [August 3, 2020, 4:39pm UTC](https://forum.duplicati.com/t/how-to-only-write-to-external-usb-drive-on-linux-when-its-attached/10414/1 "2020-08-03T16:39:04Z")

</div>

Thanks in advance for your help.  
I want to create a backup onto an external USB drive which mounts as an NTFS drive at /media/username/External, but the device isn’t always attached to the computer running Duplicati. My worry is that when the device isn’t connected, it’ll create the necessary folders and write to them (hindering the next mount at that mount point.)

Deja-Dup in Ubuntu can avoid making backups to an empty /media/username/External until the device is reconnected, but I can’t find a setting to do the same in Duplicati.

I see that Duplicati will perform backups if a scheduled time is missed, but can it do the same for disconnected devices?

Thanks!

---

<div class="post-metadata">

**Author:** ![avmaksimov](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/a/f475e1/32.png) [@avmaksimov](https://forum.duplicati.com/u/avmaksimov)\
**Post date:** [August 4, 2020, 5:09am UTC](https://forum.duplicati.com/t/how-to-only-write-to-external-usb-drive-on-linux-when-its-attached/10414/2 "2020-08-04T05:09:33Z")

</div>

Hello! I solved by task in the Windows scheduler that run a script what checked the disk available and run the backup due python duplicati client: [GitHub - Pectojin/duplicati-client: A command line client for controlling the Duplicati Server](https://github.com/Pectojin/duplicati-client) .

---

<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 4, 2020, 4:57pm UTC](https://forum.duplicati.com/t/how-to-only-write-to-external-usb-drive-on-linux-when-its-attached/10414/3 "2020-08-04T16:57:55Z")

</div>

You could use --run-script-before, have it check for the presence of the drive, and then exit the script with a certain errorlevel to prevent the backup from running.

The different error levels are shown here:

> [@Improvements for --run-script-before/after options](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519):
>
> 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: Errorlevel 0: Everything is OK, start backup task Errorlevel 1: Everything is OK, but don't run the backup Errorlevel 2: The…

---

<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 4, 2020, 10:19pm UTC](https://forum.duplicati.com/t/how-to-only-write-to-external-usb-drive-on-linux-when-its-attached/10414/4 "2020-08-04T22:19:06Z")

</div>

> [@jimbudarz](#):
>
> My worry is that when the device isn’t connected, it’ll create the necessary folders and write to them (hindering the next mount at that mount point.)

Unlikely. After first backup, Duplicati will miss the files that its [database](https://duplicati.readthedocs.io/en/latest/03-using-the-graphical-user-interface/#database-management) says _should_ be there, and error.

I’m not clear how writes hinder mounts, but if writes are a concern despite above, they can be stopped:

[Making immutable mount points with chattr](https://forum.duplicati.com/t/making-immutable-mount-points-with-chattr/2849)

---

<div class="post-metadata">

**Author:** ![haus](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/h/5f8ce5/32.png) [@haus](https://forum.duplicati.com/u/haus)\
**Post date:** [August 5, 2020, 6:55pm UTC](https://forum.duplicati.com/t/how-to-only-write-to-external-usb-drive-on-linux-when-its-attached/10414/5 "2020-08-05T18:55:25Z")

</div>

There actually are settings for this, though I still think making the mount point immutable is the best option, along with using /dev/disk/by-uuid in your fstab and specific mount names so you don’t mix things up.

The setting involves two options: “alternate-target-paths” and “alternate-destination-marker”.

The first checks to see if the target path exists (e.g., /media/duplicati\_a/photos), which wouldn’t exist if your drive weren’t mounted. Then you can add a destination marker filename and place that file in the destination folder. So my alternate destination marker file is “photos\_duplicati\_a\_marker” and I just touch that filename in the mounted USB drive to create it.
