Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In an incremental backup, tar does not seem to be able to add new files :

$ tar -cvzf test.tar.gz -g test.snar a.txt
a.txt
$ tar -cvzf test2.tar.gz -g test.snar a.txt b.txt

The second command returns nothing and the archive is empty. Yet it works if I specify the directory instead of the files. Anything I'm missing here ?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

The snapshot file contains a.txt on the first tar command. On the second tar the snapshot does not know about b.txt. a.txt has not changed so the incremental archive is empty.

If the incremental archive is at directory level, it will detect the change (b.txt) because b.txt exists within the directory's heirarchy.

If the snapshot file exists, it determines which files are modified.

See GNU Tar reference incremental backups

The option ‘--listed-incremental’ instructs tar to operate on an incremental archive with additional metadata stored in a standalone file, called a snapshot file. The purpose of this file is to help determine which files have been changed, added or deleted since the last backup, so that the next incremental backup will contain only modified files. The name of the snapshot file is given as an argument to the option:

share|improve this answer
    
So tar only works well on directories for incremental backup then ? –  alex_reader Feb 7 at 13:16
    
In the way you are using it - yes. As an alternative you could remove the snapshot file if additional files are to be added. –  suspectus Feb 7 at 13:34
add comment

Have you looked at using the "–listed-incremental" option to tar ? It will allow you to incrementally add specific folders and helps to ensure you only compress the files changed since the last time they were added to tar with the --list-incremental option.

A more generic option is simply to append new files using -a or the append option, which puts the file onto the end of the archive.

If this is a backup situation, I'd suggest you look at rsync as a more feature rich option but again all depends on what you're trying to do with your backup procedure.

share|improve this answer
    
In my version, -g is a synonym for --listed-incremental. My question was more about why it works for directories and not for a list of files. –  alex_reader Feb 7 at 13:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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