Tar

為什麼我需要從磁帶讀取 3 次才能讀取 2 個檔案?

  • March 24, 2017

將兩個 tar 歸檔文件寫入磁帶後:

$ mt -f /dev/st0 rewind
$ tar cvf /dev/nst0 first
$ tar cvf /dev/nst0 second

為什麼我需要從磁帶讀取三遍才能讀取兩個檔案?

$ mt -f /dev/st0 rewind

$ mt -f /dev/nst0 status
SCSI 2 tape drive:
File number=0, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x44 (LTO-3).
Soft error count since last status=0
General status bits on (41010000):
BOT ONLINE IM_REP_EN

$ tar tvf /dev/nst0
drwxrwxr-x oskar/oskar       0 2017-03-23 11:35 first/

$ mt -f /dev/nst0 status
SCSI 2 tape drive:
File number=0, block number=10, partition=0.
Tape block size 0 bytes. Density code 0x44 (LTO-3).
Soft error count since last status=0
General status bits on (1010000):
ONLINE IM_REP_EN

$ tar tvf /dev/nst0
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

$ mt -f /dev/nst0 status
SCSI 2 tape drive:
File number=1, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x44 (LTO-3).
Soft error count since last status=0
General status bits on (81010000):
EOF ONLINE IM_REP_EN

$ tar tvf /dev/nst0
drwxrwxr-x oskar/oskar       0 2017-03-23 11:37 second/

$ mt -f /dev/nst0 status
SCSI 2 tape drive:
File number=1, block number=3, partition=0.
Tape block size 0 bytes. Density code 0x44 (LTO-3).
Soft error count since last status=0
General status bits on (1010000):
ONLINE IM_REP_EN

在 first 結束時tar tvf,磁帶留在第一個文件的最後一個塊上。第二個tar tvf再次讀取並抱怨,但這樣做會將磁帶留在第二個文件的第一個塊上,因此第三個tar tvf可以工作。

在磁帶上處理多個文件時,您應該真正使用mt在執行之前在文件之間移動tar

mt -f /dev/st0 rewind
tar tvf /dev/nst0
mt -f /dev/nst0 fsf 1
tar tvf /dev/nst0

引用自:https://unix.stackexchange.com/questions/353520