1

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 ?

2 Answers 2

1

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:

2
  • So tar only works well on directories for incremental backup then ? Commented Feb 7, 2014 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
    Commented Feb 7, 2014 at 13:34
1

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.

1
  • 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. Commented Feb 7, 2014 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .