There is an important difference that could make using tar
important under some circumstances: Besides the "metadata" that @jofel mentioned in his answer, tar
records the filename in the archive. When you extract it, you get the original filename regardless of what the archive is called.
In your case the tar archive and the file it contains have the related names db.dump.tar.gz
and db.tar
, but suppose you rename the tar file to 20-Apr-16.dump.tgz
, or whatever. Untar this with tar xvfz
, and you get db.dump
. For comparison, unzip 20-Apr-16.dump.gz
and you've got 20-Apr-16.dump
. (Edit: as pointed out in the comments, gzip also makes a record of the filename; but it's not normally used when unzipping). A tar
archive can also contain a relative pathname that puts the extracted file in a subdirectory.
Your use case will dictate whether this kind of filename persistence is needed, or even wanted, or is actually undesirable. But certainly, regardless of compression, a tar
archive travels differently from a regular file.
tar -zxvf
. But for those who look at the file name and see it doesn't have.tgz
as extension, it is perfectly fine to gzip the db dump file. Since I don't know the compression algorithms in detail, I am not sure if tar makes any compression on sparse files like db dump, but for plain text files, direct gzip of the file has a very tiny size advantage over taring first and gzip ing the file.tar.gz
to be superior to most other common methods. I recall it was superior to just.tar
but cannot remember if it was better than just.gz
. Ironically Window's.cab
format was the best of the methods I tried, which was very unexpected.tar
is not a compression algorithm, it's an archiving format