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.

/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 finalle 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.