Proxmox Backup Server: Eject removable drive or RDX cartridge

If you ever handled a Proxmox Backup Server (PBS) with removable drives you perhaps noticed that ejecting that media is not as easy as one would imagine out of the box. But there is a solution. We use some systemd services and timers to make this happen.

In no event, unless required by applicable law or agreed to in writing will I be liable to you for damages, including any general, special, incidental, or consequential damages arising out of the use or inability to use the information, commands, scripts and snippets provided here (including but not limited to loss of data or data being rendered inaccurate, or losses sustained by you or third parties, or a failure of the command/script/snippets to operate with any other programs), even if such holder or other party has been advised of the possibility of such damages.

Writing articles like this one requires time and resources. If you found it helpful or even if you didn't, I'd love to hear from you—whether you have feedback, suggestions, or spotted any bugs or typos. Your input would mean the world to me! You can reach out using the email address listed in the imprint.

/etc/systemd/system/rdx1-eject.service

[Unit]
Description=Eject rdx1

[Service]
Type=oneshot
RequiresMountsFor=/mnt/datastore/rdx1
ExecStart=proxmox-backup-manager datastore update rdx1 --maintenance-mode "offline" 
ExecStart=systemctl restart proxmox-backup proxmox-backup-proxy
ExecStart=eject /mnt/datastore/rdx1

[Install]
WantedBy=multi-user.target

This systemd unit will only run if the removable drive (here: RDX cartridge) is mounted (/mnt/datastore/rdx1). If this is the case it will set the PBS datastore in maintenance mode. Because the .lock file is still used by PBS we still can't eject the drive. That is why we need to restart the proxmox-backup and proxmox-backup-proxy services (see Proxmox Forum on this topic). After this step we can finally eject the disk/cartridge.

If we want to automatically connect the disk/cartridge again we need to have following unit:

/etc/systemd/system/rdx1-connect.service

[Unit]
Description=Connect rdx1

[Service]
Type=oneshot
ExecStart=systemctl start mnt-datastore-rdx1.mount
ExecStart=proxmox-backup-manager datastore update rdx1 --delete maintenance-mode

[Install]
WantedBy=multi-user.target

First we activate the mount unit. If this fails (e.g. because the drive is not connected) the next step is not executed (In units with Type=oneshot the ExecStart= commands are exectued sequentially and if one command fails the following commands are not executed). When the mount worked the maintenance mode on the datastore is disabled.

After that you can use simple systemd-timers or other hooks to execute the services when needed and depending on the need of your clients.