Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

So how should this be done? I have learned that using cat is the preferred way when using split to create multi-volume files, but what about when using tar's own native multi-volume function?

Thanks

share|improve this question

1 Answer 1

up vote 2 down vote accepted

In this answer I give an answer using a callback script, to be used with the -F option of tar.

Here I expand on the automated input to tar prompt requests, both in the creation and the extraction of the archive, and estimating in advance the number of volumes needed:

#!/bin/bash
# CREATION SCRIPT

vol_size=100000

# estimated number of volumes: dir-size / vol-size + 1
# adding a further +1 to be safe
n=$(($(du -s Documents2 | awk '{ print $1 }') / $vol_size + 2))

for ((i = 2; i <= n; i++)); do printf 'n file-%d.tar\n' $i; done |
  tar -ML $vol_size -cf file-1.tar Documents2/ 2>&-

and

#!/bin/bash
# EXTRACTION SCRIPT

n=$(printf '%s\n' file-*.tar | sed 's/^file-//;s/\.tar$//' | sort -nr | head -1)
for ((i = 2; i <= n; i++)); do printf 'n file-%d.tar\n' $i; done |
  tar -M -xf file-1.tar 2>&-
share|improve this answer
    
Hi again :) The extraction script just seems to freak out, so I removed the "to null bit in the end" and found out that it says (freely translated from Swedish to English) Prepare volume 2 for file-20.tar and press carriage return: tar file end on expected user answer. Tar: Error can not be handled, exiting. Any ideas? :) –  Industrial Sep 25 '11 at 20:11
    
@Industrial: you are right, there was an error: the two for loops should begin from 2, not 1. Corrected the answer. –  enzotib Sep 26 '11 at 7:12
    
Hi again! You are really amazing helping me out with this. I have absolutely no idea on what to do now. I managed to get the script running properly at my Ubuntu 10.04 workstation, but when I deploy it to the Debian server where it is meant to live, I get this error: Prepare volume #2 for "file-4.tar" and hit return: tar: EOF where user reply was expected tar: WARNING: Archive is incomplete tar: Error is not recoverable: exiting now. –  Industrial Sep 26 '11 at 10:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.