0

I'm trying to dump our online backups to tape; for obvious reasons I want to encrypt the data on the tapes, so to write to the tape I need to tar everything up, pipe that to openssl to encrypt it, then write that to tape:

tar c /etc | openssl aes-128-cbc -salt -pass "pass:Test123" | dd of=/dev/nst0

However it appears the dd doesn't like this. Writing directly to the tape from tar works fine:

svr-bup1 # tar cf /dev/nst0  /etc
tar: Removing leading `/' from member names
svr-bup1 #

Adding dd into the chain and it breaks:

svr-bup1 # tar c /etc | dd of=/dev/nst0
tar: /dev/nst0: Cannot open: Device or resource busy
tar: Error is not recoverable: exiting now
0+0 records in
0+0 records out
0 bytes (0 B) copied, 9.6274e-05 s, 0.0 kB/s

The same happens with and without the openssl command; I omitted it above to simplify the testing.

mt commands work fine (with env variable TAPE set):

svr-bup1 # mt status
SCSI 2 tape drive:
File number=6, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x46 (LTO-4).
Soft error count since last status=0
General status bits on (81010000):
 EOF ONLINE IM_REP_EN
svr-bup1 # mt rewi
svr-bup1 # 

Hardware is a HP 1720 LTO4 SAS drive using the mpt2sas driver on CentOS 6.

fukawi2
  • 5,396
  • 3
  • 32
  • 51
  • It's obvious from the error message "tar: /dev/nst0: Cannot open: Device or resource busy" (please enjoy good error messages) that *tar* reports an error writing to `/dev/nst0`, and *not* `dd`. Most likely because `dd` opens the tape device before `tar`, and the OS prevents the tape device from being opened multiple times. As answers indicated use `-f -` to send `tar` output to `stdout`. – U. Windl Jul 27 '21 at 09:20

1 Answers1

4

Your version of tar appears to be trying to write to the tape device by default, rather than standard output. It appears to be GNU tar. Autodetecting the tape drive was the default before version 1.11.5 of GNU tar and I suspect you have such an old version. Versions of tar on other UNIX systems may also attempt to write to the tape device by default.

Force tar to write to stdout by specifying the file -:

tar cf - /etc | dd of=/dev/nst0
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972