Ok, so I've just had a read through this page after a way to improve my current backup solution on my Debian server. Tar seems to be offering a quite nice multi-volume feature, although when I try it out, it asks me to Prepare volume #X for ‘mybackup.tar.gz’ and hit return:.

How should I automate this as I would like to take usage of this feature in an automated CRON script where no one is there to push return and enter whatever is rquired by the multi-volume prompt.

Is using split the only way?


Here is a solution:

printf 'n file-%02d.tar\n' {2..100} | 
    tar -ML 716800 -cf file-01.tar Documents/ 2>/dev/null

where 100 is a number greater or equal to the number of volumes.


Setting a big number should not be a problem, though I tend to not take a ridiculous one.

An alternative could be a "next volume" script, that you can set with the -F option,

tar -ML 716800 -F './myscript file' -cf file.tar Documents/ 2>/dev/null

then in ./myscript put


while [[ -e "$prefix-$n.tar" ]]; do
mv "$prefix.tar" "$prefix-$n.tar"
echo "$prefix-$n.tar"

It will be executed at each volume end, and will move file.tar to the appropriate fileNNN.tar. For the last volume the script will not be executed, so the last volume name stay file.tar.

Edit 2

I ended up with the following elaborated solution.
Here are two script, one for the creation and the other for the extraction:


# save on file the initial volume number
echo 1 >number

# multi-volume archive creation
tar -ML 100000 -F './tar-multi-volume-script c file' -cf file.tar Documents2/ 2>&-

# execute the "change-volume" script a last time
./tar-multi-volume-script c file



# save on file the initial volume number
echo 1 >number

# execute the "change-volume" script a first time
./tar-multi-volume-script x file

# multi-volume archive extraction
tar -M -F './tar-multi-volume-script x file' -xf file.tar 2>&-

# remove a spurious file
rm file.tar

where ./tar-multi-volume-script is given by



case $mode in
  c) mv "$prefix.tar"    "$prefix-$n.tar" ;;
  x) cp "$prefix-$n.tar" "$prefix.tar"    ;;

echo $((n+1)) >number

Obviously you have to change many bits here and there to adapt to your situation and to be sure it would work in cron, that is always a little challenge.

| improve this answer | |
  • I like that, but then I need to know the max number of volumes per directory in beforehand? I mean, what happens when I exceed 716m in 100 directories? Can I just set max to a ridiculously high number like 919191 and leave it? – Industrial Sep 25 '11 at 9:09
  • @Industrial: see edit – enzotib Sep 25 '11 at 9:34
  • Thanks a lot for this great answer, Enzotib! How would you suggest restoring/extracting using this "next-volume" script? – Industrial Sep 25 '11 at 15:31
  • @Industrial: here an almost complete solution – enzotib Sep 25 '11 at 16:30
  • Great approaches! Thanks to everyone involved. -- Caveat: I can see that the first solution uses a bash built-in feature called brace expansion; this may not be available in all shells. Should you run into an error message or unexpected behavior, use printf 'n file-%02d.tar\n' $(seq 2 100) | (etc.) instead, which ought to work anywhere. – syntaxerror Nov 7 '14 at 21:40

When in doubt, read the manual ...


or simply use the following search string at your favorite internet search engine:

"Archives Longer than One Tape or Disk"

That section of the GNU tar manual provides a suitable script (called new-volume) to use with the -F option of the tar command. You could tweak that script to your taste if you wish.


| improve this answer | |
  • You seem to have forgotten to mention the --new-volume-script flag? – SamB Oct 19 '12 at 2:10
  • 7
    Please don't just post links; include some context so that, should the other site go down, there is sufficient information here to make sense of your answer. – jasonwryan Oct 19 '12 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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