I am thinking how to recover .tar.gz HOME backup into almost a new Debian system safely (some files can exist and should be preserved so rsync -u). My main PC broke so I have to use a backup Debian system but I need my HOME backups (only the following home files) of the main system. Characteristics of the system

  • $HOME is /home/masi/

Code to make the home backup as root

#1. [but fails with circular symlinks]

# http://unix.stackexchange.com/a/291720/16920
nice tar czf /media/masi/ext4Masi/backup_home_20.12.2016.tar.gz $HOME/

There are symlinks in my directories. I have noticed that the tarball does not contain all directories such as $HOME/Documents/ and/or /home/masi/Documents/. The directory has many symlinks and maybe also some circular symlinks. The tarball then again contains $HOME/Desktop/ and $HOME/Downloads which should not contain any circular symlinks, and Downloads directory has no symlinks at all.

#2. [Rejected because will cause much duplicate files]

tar czf --dereference \ 
   /media/masi/ext4Masi/backup_home_20.12.2016.tar.gz $HOME/

#3. ...

Code to use the backup [deprecated; use tar xzfC ...]

I think rsync can be the right choice here without deletes but with -u option about skip any files for which the destination file already exists and has a date later than the source file (requirement about almost); pseudocode because I think .tar.gz cannot be input there

# http://unix.stackexchange.com/a/287016/16920
rsync -rtvuc --progress \
    /media/masi/ext4Masi/backup_home_20.12.2016.tar.gz $HOME/

However, I am still unsure

  • about maintaining the file-directory hierarchy correctly
  • how can you have .tar.gz file as input of rsync?

OS: Debian 8.5

  • I'd use a proper backup solution. Recently I'm been suggesting borgbackup. Of course, there are many other options. Commented Dec 21, 2016 at 13:22
  • @FaheemMitha Borg sounds nice but how tested? - - Why not tar? - - I just want something stable which can deal with symlinks. Commented Dec 21, 2016 at 13:24
  • Hi Masi. Borg is better than tar in every way possible. It's intelligent incremental backup. I recommend you do a little reading on the Borg site. Commented Dec 21, 2016 at 13:38

1 Answer 1


Why get rsync involved when you can use tar?

If you created the backup with this command:

tar czf /media/masi/ext4Masi/backup_home_20.12.2016.tar.gz $HOME/

you can then restore the files without overwriting existing files like this:

tar xzfC /media/masi/ext4Masi/backup_home_20.12.2016.tar.gz / --keep-newer-files

The man page for tar documents the various don't overwrite flags.

It transpires that your backup contains symlinks to files outside the tree that was backed up. If you don't mind losing the symlinks you can use the -h (--deference) option during the backup to deference them into real files and directories. On the other hand, if you want to keep the symlinks and their targets you will need to include those targets in your backup.

Example 1, where you are happy to have the symlinks converted into real files or directories:

tar czf /path/to/backup.tgz --deference "$HOME"

Example 2, where you want to include the targets of the symlinks. This assumes your targets are under /bigdisk/myfiles/:

tar czf /path/to/backup.tgz "$HOME" /bigdisk/myfiles
  • You expand the file to root /. Should it be $HOME? How does tar know where to put the files? Commented Dec 20, 2016 at 21:17
  • 2
    The tarball contains the full path in this case (try it and see). Commented Dec 20, 2016 at 21:52
  • 1
    @Masi, I take it $HOME equals /home/masi, is that correct? Commented Dec 21, 2016 at 9:16
  • 1
    Is /home/masi/Documents a real directory, or is it a symlink? Commented Dec 21, 2016 at 10:47
  • I think --deference is not a good option for the solution because it causes much duplicates of the files. - - Is there anything else for the workaround about circular symlinks such that skipping directories could be avoided? - I extended the second part here unix.stackexchange.com/q/332224/16920 Commented Dec 22, 2016 at 17:06

You must log in to answer this question.

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