tape backup without changer

lxuser

New Member
Apr 27, 2024
3
0
1
i want to use tape backup without a changer. For a small installation ( complete backup fits on one tape ) i want to create something with minimal user interaction.
X tapes are available and in the worst case, the user should be able to insert a random tape and take one offline.
The only thing he must take care of, is that a new tape is inserted and no tape stays ejected.
Only with the gui something like this seems not to be possible, as a job starts a single pool with attached named tapes and then expects the right names at execution.
Did i overlook something?
I helped myself with an unelegant script:

( edited version from 05.05.24 without using jobs, better error capturing )

Bash:
# edited on 05.05.24
#!/bin/bash
# date of execution
date=$(date)

# sometimes proxmox-backup-proxy is not answering proxmox-tape (GET /api2/json/tape/drive/LTO5/status?: 400 Bad Request:...timeout while trying to lock)

locked=$(proxmox-tape status --drive XXX 2>&1 >/dev/null | grep lock | awk -F' ' '{print $6}')

case $locked in
    "lock" )
       systemctl restart proxmox-backup-proxy
       echo "proxmox-backup-proxy restarted"
       ;;
    * )
       echo "proxmox-backup-proxy ok, go on ..."
       ;;
esac

# check if tape device is accessible

deviceexists=$(proxmox-tape status --drive XXX 2>&1 >/dev/null | grep Error: | awk -F' ' '{print $1}')

case $deviceexists in
    "Error:" )
       echo "Backup am $date fehlgeschlagen. Das Bandlaufwerk ist nicht eingeschaltet oder verbunden. Bitte überprüfen." | mail -s "Backup: Bandlaufwerk ist nicht eingeschaltet." user@domain.de
       echo "device missing, email sent"
       exit 1
       ;;
    * )
       echo "device exists, go on ..."
       ;;
esac

# test if tape is inserted (capture stderr and search for "Error:"), send mail that user should insert a tape

notape=$(proxmox-tape read-label --drive XXX 2>&1 >/dev/null | grep Error: | awk -F' ' '{print $1}')

case $notape in
    "Error:" )
        echo "Backup am $date fehlgeschlagen. Es wurde kein Band gefunden. Bitte legen Sie ein neues Band in das Laufwerk" | mail -s "Backup: Bandlaufwerk ist leer. Bitte Band einlegen." user@domain.de
        echo "tape missing, email sent"
        exit 1
        ;;
    * )
       echo "tape exists, go on ..."
       ;;
esac

# bevore use create seperate mediapools for every tape with the name of the tape/barcode 
# then "proxmox-tape read-label --drive XXX" in terminal to get uuids/label-text of all used tapes. They have to be listed here

# read name of inserted tape label-text, uuid and pool name

tapename=$(proxmox-tape read-label --drive XXX | grep -oP '(?<=label-text).*' | awk -F ' ' '{print $2}')
uuid=$(proxmox-tape read-label --drive XXX | grep -oP '(?<=uuid).*' | awk -F ' ' 'NR==1{print $2}')
poolname=$(proxmox-tape read-label --drive XXX | grep -oP '(?=pool).*' | awk -F ' ' '{print $3}')

case $uuid in
    "07a772f5-fa67-46e6-a0c7-e74a8e69d658" )
       proxmox-tape backup local-ds1 A22166L5 --drive XXX --notify-user root@pam
       ;;
    "c63d5cef-e1fa-419d-a990-3f8d9fcb9be7" )
       proxmox-tape backup local-ds1 A23490L5 --drive XXX --notify-user root@pam
       ;;
    "9bed08cd-2138-483c-a3ab-71b961fd02b9" )
       proxmox-tape backup local-ds1 A22943L5 --drive XXX --notify-user root@pam
       ;;
    "2524e45d-ec9b-4fa3-8a29-475104cdb944" )
       proxmox-tape backup local-ds1 A22396L5 --drive XXX --notify-user root@pam
       ;;
    * )
       echo "Backup am $date fehlgeschlagen. Es wurde ein unbekanntes Band mit dem Namen $tape und der UUID $uuid gefunden, zugehörig zum Pool $poolname. Bitte legen Sie ein passendes Band in das Laufwerk" | mail -s "Backup: falsches Band im Laufwerk." user@domain.de
       echo "unknown tape $tapename with $uuid of pool $poolname found, mail sent"
       exit 1
       ;;
esac

# eject tape

proxmox-tape eject --drive XXX

# notification

echo "Das Band $tapename wurde am $date für die Sicherung benutzt. Bitte legen Sie ein neues Band in das Laufwerk" | mail -s "Backup erfolgreich: Bitte Band wechseln" user@domain.de

This seems to work, but is there a simpler way to achieve my goal?

Greetings
 
Last edited:
why is it so important that the next tape is 'quasi random' ? normally the gui shows you what the next expected tape for the job is, and when the job starts, it sends an email which tape is required.

depending on when you want to change the tape (e.g. weekly) you can also build multiple jobs with media pools that are timed in a way that there is only one choice for that
(e.g. a MONDAY, TUESDAY, etc. pool that only has one tape each)
 
'quasi random' because in this special case not everybody has access to e-mail and more interaction is needed if a tape is moved off-site in that you have to set a location.
I tried your suggestion with creating multiple pools with one tape, but i did not find a solution to intercept errors (wrong tape inserted). Reading the notifications would of course help ;-) , but i try to find a solution without user interaction.
thanks
 
Hello - i have the same topic, we do the logic by choosing the correct tape ourselves. So you suggest to make for each tape an individual pool? Right now i have to format the tape myself and then recreate the label which is a bit annoying. But with mulitiple single tape pools i would need to make multiple jobs then? how about monthly backups that are never overwritte?
 
hi,
normaly a user gets an e-mail with the name of the next tape to insert, but in my case not everyone has access to the account. so my goal was that if the tape was thrown out of the drive , one can grab a random tape, insert it and it gets written . and yes every tape is in a seperate pool and the tapes have to be manualy listed inside the script, that they can be identified. all unknown tapes are ignored. if new tapes are added, their identifiers have to be placed in the script. i do not use the integrated backup-jobs. thats the task of the script ( for my special needs).
 
i want to use tape backup without a changer. For a small installation ( complete backup fits on one tape ) i want to create something with minimal user interaction.
X tapes are available and in the worst case, the user should be able to insert a random tape and take one offline.
The only thing he must take care of, is that a new tape is inserted and no tape stays ejected.
Only with the gui something like this seems not to be possible, as a job starts a single pool with attached named tapes and then expects the right names at execution.
Did i overlook something?
I helped myself with an unelegant script:

( edited version from 05.05.24 without using jobs, better error capturing )

Bash:
# edited on 05.05.24
#!/bin/bash
# date of execution
date=$(date)

# sometimes proxmox-backup-proxy is not answering proxmox-tape (GET /api2/json/tape/drive/LTO5/status?: 400 Bad Request:...timeout while trying to lock)

locked=$(proxmox-tape status --drive XXX 2>&1 >/dev/null | grep lock | awk -F' ' '{print $6}')

case $locked in
    "lock" )
       systemctl restart proxmox-backup-proxy
       echo "proxmox-backup-proxy restarted"
       ;;
    * )
       echo "proxmox-backup-proxy ok, go on ..."
       ;;
esac

# check if tape device is accessible

deviceexists=$(proxmox-tape status --drive XXX 2>&1 >/dev/null | grep Error: | awk -F' ' '{print $1}')

case $deviceexists in
    "Error:" )
       echo "Backup am $date fehlgeschlagen. Das Bandlaufwerk ist nicht eingeschaltet oder verbunden. Bitte überprüfen." | mail -s "Backup: Bandlaufwerk ist nicht eingeschaltet." user@domain.de
       echo "device missing, email sent"
       exit 1
       ;;
    * )
       echo "device exists, go on ..."
       ;;
esac

# test if tape is inserted (capture stderr and search for "Error:"), send mail that user should insert a tape

notape=$(proxmox-tape read-label --drive XXX 2>&1 >/dev/null | grep Error: | awk -F' ' '{print $1}')

case $notape in
    "Error:" )
        echo "Backup am $date fehlgeschlagen. Es wurde kein Band gefunden. Bitte legen Sie ein neues Band in das Laufwerk" | mail -s "Backup: Bandlaufwerk ist leer. Bitte Band einlegen." user@domain.de
        echo "tape missing, email sent"
        exit 1
        ;;
    * )
       echo "tape exists, go on ..."
       ;;
esac

# bevore use create seperate mediapools for every tape with the name of the tape/barcode
# then "proxmox-tape read-label --drive XXX" in terminal to get uuids/label-text of all used tapes. They have to be listed here

# read name of inserted tape label-text, uuid and pool name

tapename=$(proxmox-tape read-label --drive XXX | grep -oP '(?<=label-text).*' | awk -F ' ' '{print $2}')
uuid=$(proxmox-tape read-label --drive XXX | grep -oP '(?<=uuid).*' | awk -F ' ' 'NR==1{print $2}')
poolname=$(proxmox-tape read-label --drive XXX | grep -oP '(?=pool).*' | awk -F ' ' '{print $3}')

case $uuid in
    "07a772f5-fa67-46e6-a0c7-e74a8e69d658" )
       proxmox-tape backup local-ds1 A22166L5 --drive XXX --notify-user root@pam
       ;;
    "c63d5cef-e1fa-419d-a990-3f8d9fcb9be7" )
       proxmox-tape backup local-ds1 A23490L5 --drive XXX --notify-user root@pam
       ;;
    "9bed08cd-2138-483c-a3ab-71b961fd02b9" )
       proxmox-tape backup local-ds1 A22943L5 --drive XXX --notify-user root@pam
       ;;
    "2524e45d-ec9b-4fa3-8a29-475104cdb944" )
       proxmox-tape backup local-ds1 A22396L5 --drive XXX --notify-user root@pam
       ;;
    * )
       echo "Backup am $date fehlgeschlagen. Es wurde ein unbekanntes Band mit dem Namen $tape und der UUID $uuid gefunden, zugehörig zum Pool $poolname. Bitte legen Sie ein passendes Band in das Laufwerk" | mail -s "Backup: falsches Band im Laufwerk." user@domain.de
       echo "unknown tape $tapename with $uuid of pool $poolname found, mail sent"
       exit 1
       ;;
esac

# eject tape

proxmox-tape eject --drive XXX

# notification

echo "Das Band $tapename wurde am $date für die Sicherung benutzt. Bitte legen Sie ein neues Band in das Laufwerk" | mail -s "Backup erfolgreich: Bitte Band wechseln" user@domain.de

This seems to work, but is there a simpler way to achieve my goal?

Greetings

nice script!
the check for the lock of the proxmox backup server will fail if a backup job is running at the moment.
the restart of the proxmox-backup-proxy is not save.

why don't you just use the uuid, tapename and poolname from the currently inserted tape for the backup?
this data should not actually be hardcoded in the script.

by setting "--ns NAMESPACE" you can also restrict the backup to a namespace, which is sometimes quite useful if, for example, you use a namespace for temporary backups that do not belong on the tape.