How to create tar archive split into, or spanning, multiple files?
You can use split for this:
tar czpvf - /path/to/archive | split -d -b 100M - tardisk
This tells tar to send the data to stdout, and split to pick it from stdin - additionally using a numeric suffix (-d
), a chunk size (-b
) of 100M and using 'tardisk' as the base for the resulting filenames (tardisk00, tardisk01, tardisk02, etc.).
To extract the data afterwards you can use this:
cat tardisk* | tar xzpvf -
Take a look at the --new-volume-script
option, which lets you replace the prompting mechanism with a different mechanism or with a generated filename. ((tar.info)Multi-Volume Archives
in the tar
info page.) The problem with split
is that you need to cat
the pieces back together to do anything, whereas a multivolume archive should be a bit more flexible.
Of course the best option to use is the --new-volume-script
option.
But, if you know the size of the file (in this case, largefile.tgz), then you can do this also:
tar -c -M -L 102400 --file=disk1.tar --file=disk2.tar --file=disk3.tar largefile.tgz
Summary:
-c = Create
-M = multi-volume
-L 102400 = 100MB files (disk1.tar, disk2.tar, disk3.tar ...)
(For the -L, specify as many as needed so that the total sum of the tar files is larger than largefile.tgz)
If you are trying to tar
a directory tree structure