2

Given a tree structure with files in it, say:

source
|-- bar
|   +-- three.txt
|-- baz
|   +-- four.txt
+-- foo
    |-- one.txt
    +-- two.txt

If I do

tar czvf dest/archive-1.tgz --listed-incremental dest/archive.snar source/*

That creates a .tgz file containing all the current files and folders, just what I'd expect:

source/bar/
source/baz/
source/foo/
source/bar/three.txt
source/baz/four.txt
source/foo/one.txt
source/foo/two.txt

If I immediately do:

tar czvf dest/archive-2.tgz --listed-incremental dest/archive.snar source/*

That seems to create .tgz file containing all the subfolders of the current directory, with no files:

source/bar/
source/baz/
source/foo/

This isn't what I want. On a toy example like this one, it's not so bad, but on a large folder structure it makes it much harder to tell that the .tgz is essentially empty. It's a lot of noise. Ideally, tar would tell me that there are no updated files and exit with an error code, but even if it made an empty tar, that'd be better (for me, in this case) than an archive with lots of empty folders.

Is there any way to make tar --listed-incremental behave the way that I would like? I've done a few searches to find solutions, but I haven't found much.

I may end up just stop using --listed-incremental and doing some work with find to assemble a file list instead, but that's a lot more work if there's a way to make --listed-incremental do what I want. Any suggestions?

  • What/where was the typo? Future readers might encounter similar symptoms, so perhaps updating your post with your fix (and where) might help them? – Castaglia Mar 10 '16 at 23:26
  • I had a typo in my question that a commenter pointed out. The question has been corrected, but the problem I was experienced was unrelated to the type in the question. I don't have an answer to the question. – Geoffrey Wiseman Mar 11 '16 at 14:26
0

The manual page mentions:

When extracting from the incremental backup GNU tar attempts to restore the exact state the file system had when the archive was created. In particular, it will delete those files in the file system that did not exist in their directories when the archive was created.

To implement this they would either need a special file within the archive containing a list of all deleted files, or a copy of all directory inodes so that the relevant files can be removed. To keep in-line with the archive format it was probably cleaner for them just to include the directories rather than complicate things with an additional file.

  • 2
    I do not find this answer completely clear. An example showing what would happen without those directories present in the archive and how the presence of the directories helps would make it a lot more clear. – kasperd May 21 '17 at 23:57
  • Furthermore, it is unclear to me whether the omission of empty directories in the incremental tar archive would causes the existing files in these directories to be deleted on the extraction side. In other words, the question is whether extracting an incremental tar holding only non-empty dirs a and b to a directory holding existing dirs a, b and c would delete directory c on the receiving side. – fredo Nov 29 '17 at 16:29

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.