The following script fails to perform incremental backup, but creates full backup instead.

On another FreeBSD server exactly same script works just fine (creating incremental backups).

Servers are identical, same FreeBSD 10.0-RELEASE on both machines. Script it exactly the same. Version of gtar is identical. File system is identical.

Not sure what's going on. Searched for days! Please help.



now=$(date +"%Y%m%d%H%M")

cd $sourcedir
for dir in */
  base=$(basename "$dir")
  gtar -cz -g "$targetdir/.gtar-incremental" -f "$targetdir/${base}-$now.tar.gz" "/home/$dir"
  chmod 600 "$targetdir/${base}-$now.tar.gz"
  • Can you pls try gtar -cz -G "$targetdir/.gtar-incremental" -f "$targetdir/${base}-$now.tar.gz" "/home/$dir". Let us know how it went. A couple of examples I've seen suggest that [ -g, --listed-incremental F ] [ -G, --incremental ] gtar manual
    – Simply_Me
    Aug 10, 2014 at 5:48
  • That produced same result - full backup. I figured out that it got something to do with for dir in */ loop, when I remove that and specify each directory/file - incremental works! Can you help? In addition to your comment -G can't take any arguments, it does not create a snapshot file.
    – Alex G
    Aug 10, 2014 at 6:03
  • I'll move the comment to the answer section as it's easier to read.
    – Simply_Me
    Aug 10, 2014 at 6:06

1 Answer 1


Spent sometime on this today, and I think there are two issues here:

  1. every for loop iteration, a new incremental file is created (or old one is overwritten :-) . Remember, there is 1:1 mapping between the archive file and the snapshot file, thus one gtar-incremental can not serve all of the archive files.
  2. gtar does not like time stamps.This is because the snapshot file stores the tar.gz file name, and if the string passed by $now is different than the old one it'll just create a new compressed file and new snapshot file.

The way I checked it, and incremental worked, was by changing the gtar line:

gtar --listed-incremental=$targetdir/gtar-incremental-$base  -cvzf $targetdir/$base.tar.gz $dir

This works in incremental.

The above will create incremental file for every directory that is being backed up.

Another way to get this to work w/o multiple incremental files is to backup the whole home directory as a whole instead of individual archives (i.e. w/o the for loop, just straight up /home to /backup/home.tar.gz).

Lastly, I was thinking if time stamps are important for you, you can add time stamp after the gtar is done to the files, and also remove the time stamp from the files (if exists before n > 2 run, can be constructed with if statement)

Are time stamps crucial for your operation?

Hope this helps.

  • Nope. Because /* will give me each directory in the /. I'm looking to backup only /home/*
    – Alex G
    Aug 10, 2014 at 6:12
  • @Radio Awesome, than just change the for loop to always be /home/* .... I thought you want to backup the entire /
    – Simply_Me
    Aug 10, 2014 at 6:13
  • @Radio while describing sourcedir your for loop does not account for it. you should incorporate $sourcedir in your for loop.
    – Simply_Me
    Aug 10, 2014 at 6:16
  • yeah, i changed it to for dir in $sourcedir/* and gtar -cz -g "$targetdir/.gtar-incremental" -f "$targetdir/$base-$now.tar.gz" "$dir" - script runs ok, but still produces full backups! =(( Technically there is no different between my original script and what you suggested to change.
    – Alex G
    Aug 10, 2014 at 6:19
  • @Radio $ for dir in $sourcedir/* ; do echo $dir; done should work.... hmmm.
    – Simply_Me
    Aug 10, 2014 at 6:23

You must log in to answer this question.

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