How to auto-start Deja Dup backup when the external backup drive is mounted

Published: Sunday, Jun 8, 2025
Cover

It’s important to backup your files, both locally and to the cloud. I use Deja Dup to handle local backups to an external drive but I don’t keep the drive plugged in all the time (it would make grabbing my laptop to go very awkward). So I wanted to make it easier by having Deja Dup start automatically when I plugged in the drive. After some research, I figured out how to do this using a systemd service

Step 1. Create a shell script to trigger Deja Dup

This assumes you have Deja Dup installed via Flatpak, which is the recommended way to install it on modern Linux distributions. Create a script at ~/.local/bin/start-dejadup-backup.sh with the following contents:

#!/usr/bin/bash
now=$(date +"%F %T")
msg="${now} Starting Deja Dup backup to BACKUP drive"
echo "${msg}" >> start-dejadup-backup.log
flatpak run org.gnome.DejaDup --backup

Make sure to make the script executable by running:

chmod +x ~/.local/bin/start-dejadup-backup.sh

Step 2. Create the systemd service

Create ~/.config/systemd/user/backup-drive.service like the following.

Note: change the mount points based on the name of your backup drive and update the path to the script you created.

[Unit]
Description=BACKUP Deja Dup trigger
Requires=run-media-jed-BACKUP.mount
After=run-media-jed-BACKUP.mount

[Service]
ExecStart=/var/home/jed/.local/bin/start-dejadup-backup.sh

[Install]
WantedBy=run-media-jed-BACKUP.mount

My drive was called BACKUP and the drive gets mounted by default to run-media-jed-BACKUP but you can check by running systemctl list-units -t mount and looking for the name of your external drive mount.

Step 3. Enable the service

Lastly, enable the service like

sudo systemctl enable backup-drive.service

Now when you mount your backup drive, Deja Dup will start backing up automatically and close when done.