This is a generic Python3 script that is able to back-up directories to tapes/tape-libraries using tar & mtx.
Tested with Dell PowerVault TL1000.
It is meant to be lightweight.
A status e-mail with some stats is sent once the backup is finished.
You can test it by setting TRY_RUN
to True
. This will create snapshots and move cartridges inside the tape library - but skip the actual backup.
The first file on the tape is a tape-content-index that can be used when restoring data!
If there are many small files - the throughput will be low. With larger files we've seen 150-300MB/s with TLO7 (uncompressed).
Backup job stati:
Backup start time: 2024-02-06 18:00:00
Backup finish time: 2024-02-08 03:06:53
Change the listed tapes and mark them with the folder-lists!!
...
Backup status for tape in slot '5' with label 'D0018M8':
Start time: 2024-02-08 01:03:12
Stop time: 2024-02-08 03:05:40
Exit code: 0
Folder 'archive' size: 10 MB
Folder 'app1' size: 271 MB
Folder 'app2' size: 307 MB
Folder 'app3' size: 358.06 GB
Folder 'app4' size: 84.67 GB
...
Full size: 0.428 TB
Calculated throughput: 61.02 MB/s
...
Warning: Tape restores can take a long time.
Make sure no Tape-Backup-Job is started while restoring data!
Load tape to restore from.
ls /dev/ | grep sg[0-9]
mtx -f /dev/sgN status 2> /dev/null # correct one displays the current inventory
Update the /dev/sg0
references in the other commands.
mtx -f /dev/sg0 inventory
mtx -f /dev/sg0 status
mtx -f /dev/sg0 load <ID>
ls -l ${BACKUP_PATH}/tape_content_index/
less ${BACKUP_PATH}/tape_content_index/tape_content_index_${DATETIME}.txt
RESTORE_PATH="${BACKUP_PATH}/restore"
mkdir "$RESTORE_PATH"
tar -xvf /dev/st0 -C "$RESTORE_PATH" --blocking-factor 2048 "tmp/tape_content_index.txt"
# press CTRL+C after a few seconds
mt -f /dev/sg0 rewind
less "${BACKUP_PATH}/restore/tmp/tape_content_index.txt"
tar -tvf /dev/sg0 --blocking-factor 2048 | tee -a tape_content.log
mt -f /dev/sg0 rewind
RESTORE_PATH="${BACKUP_PATH}/restore"
TO_RESTORE='<PATH-TO-FILE-OR-DIR>' # find in tape-content-index
mkdir "$RESTORE_PATH"
tar -xvf /dev/sg0 -C "$RESTORE_PATH" --blocking-factor 2048 "$TO_RESTORE" >> /var/log/backup/tape_restore.log 2>&1 &
# put the restore process into the background (session independent)
jobs
disown
# check if process is still running
ps -aux | grep tar
mt -f /dev/st0 rewind
mtx -f /dev/sg0 unload