I have hundreds of directories under /var/Recording
, and each directory there will have subdirectories, including files, hard links and soft links.
I want to compress all directories under /var/Recording
to create a single compressed file.
Which command would give me the best compression? tar
or cpio
(especially considering the fact that I have hard and soft link files).
Also, what is the right syntax of the tar
/cpio
command ?
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1034
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1033
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1038
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1037
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1036
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1041
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1040
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1039
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1044
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1043
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1042
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1047
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1046
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1045
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1049
drwxr-x--- 2 root root 4096 Nov 22 18:57 458ca4e8-0edf-4204-9f9b-9c3dc02953c5.1048
.
.
.
.
.
Best Answer
cpio
(the older of the two utilities counting shipping with UNIX) only used to have hard link support for the-p
option (i.e. copying from filesystem to filesystem), but thenewc
output format (not the default onecpio
uses) also supports hard links in the output file. (GNU)tar
supports hard links without any special options. A comparison can be found here.So if you run a test with a large hard linked file and 100 small files:
You see that the uncompressed versions (
outnewc.cpio
andout.tar
) give cpio an advantage and that compressing them withxz -9
gives better results thanbzip2 -9
(gzip
is usually much worse than either). And that compression withxz
minimizes thetar
andcpio
output difference. Compression is however heavily dependent on the data, and also on the ordering of the data in the archives, so you should really test this on (a sample of) your real data.If you want to compress in parallel, you might want to look at my article here