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

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!

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 .

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:

1 Like

Unlikely. After first backup, Duplicati will miss the files that its database 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

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.

1 Like