-1

I create a backup by the following command as root (TODO right? because roaima observes that this can cause a complication) in a directory tree which has circular symlinks in some directories; those directories, tar skips. Command 1 which output in Fig. 1

root@masi:/home/masi# tar czf /media/masi/ext4Masi/backup_home_20.12.2016.tar.gz $HOME/

Characteristics of the system

  • $HOME/Documents/

    masi@masi:~$ ls -ld /home/masi/Documents/
    drwxr-xr-x 36 masi masi 4096 Nov 23 22:02 /home/masi/Documents/
    
  • $HOME

    masi@masi:~$ echo $HOME
    /home/masi
    

Fig. 1 Output of Command (1) AND output of Command (2) (same output), Fig. 2 Home tree

enter image description here enter image description here

Characteristics of tarballs

  • Tarball from Command 1; same case for Command 2. It indicates no Documents directory in the backup.

    root@masi:/home/masi/Documents/bin# tar tzvf /media/masi/masiWeek/backup_home_22.12.2016.tar.gz | grep 'Documents/*$' 
    root@masi:/home/masi/Documents/bin# 
    

If circular symlink to the directory, tar skips the directory, in my case, Documents. Other directory, Downloads, is then again backup. I would like to avoid this behaviour. You can do --deference for a workaround but it is main disadvantage is duplicate data i.e. deferencing the symlinks which I would like to maintain in my backups too.

Command 2, but fails, output in Fig. 1 too

# DopeGhoti
root@masi:/home/masi/Documents/bin# nice tar czf \
    /media/masi/masiWeek/backup_home_22.12.2016.tar.gz \
    --keep-directory-symlink $HOME/

Command 3, but fails, output same in Fig. 1 too

root@masi:/home/masi# nice tar --keep-directory-symlink -czf \ 
  /media/masi/masiWeek/backup_home_22.12.2016.tar.gz $HOME/ 

OS: Debian 8.5
Related: to restore such a backup in the thread How to recover home backup into almost new Debian?

  • 1
    tar will just store the symlinks, not interpret/traverse them (unless asked to). – ctrl-alt-delor Dec 22 '16 at 17:20
  • The command that you have does not create a zipped file, so you will not want to end file name with .gz – ctrl-alt-delor Dec 22 '16 at 17:20
  • 2
    Just use tar --keep-directory-symlink? – DopeGhoti Dec 22 '16 at 17:23
  • 1
    You will get that if you use czf rather than -czf; I rapidly fixed my comment but you may have seen the earlier version before I could make the correction. – DopeGhoti Dec 22 '16 at 18:02
  • 1
    Um. You are running the tar cvf ... as yourself, rather than root, aren't you...? The backup appears to contain root's directory rather than yours, which is indicative of HOME=/root rather than HOME=/home/masi – roaima Dec 22 '16 at 18:19
1

In the comments you confirm that you're running the backup as the root user rather than as yourself. When you become the root user, your value of $HOME also changes. (This is affected by the way in which you become root.)

Thus, when you run tar cvf /tmp/backup.tar $HOME you get the $HOME directory for root. What has been very confusing in your question (and the linked one) is that you have been interchanging $HOME and /home/masi.

To backup /home/masi you should use something like tar cvf /tmp/backup.tar /home/masi. Or change the means by which you become the root user so that $HOME is not changed too.

When you backup the correct directory tree I suspect you'll find your missing Documents folder.

  • How can you change your way of becoming root without changing $HOME? – Léo Léopold Hertz 준영 Dec 22 '16 at 18:35
  • Can --keep-directory-symlink be necessary in taking such backups here in any cases? – Léo Léopold Hertz 준영 Dec 22 '16 at 18:36
  • @Masi what command or process do you use to become the root user? – roaima Dec 22 '16 at 18:45
  • Just the command su. – Léo Léopold Hertz 준영 Dec 22 '16 at 18:46
  • 1
    @Masi man su says (amongst other things) « The $HOME, $SHELL, $USER, $LOGNAME, $PATH, and $IFS environment variables are reset. ». It also says you can use -m or -p to avoid this reset, ie su -p. One question I would ask you to consider is whether you really need to take the backup as root in the first place; after all, you already own the files being backed up. – roaima Dec 22 '16 at 19:05

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.