title: to preserve hard and symbolic link, permissions while creating tar ball and doing same while untar the tarball
body: <p>Task: To provide facility to upgrade the system remotely or add new features.       </p>
  
  <p><strong>What I am supposed to do</strong> Create a back up of current environment of target machine and if upgrading fails at any stage, then revert back to original environment.       </p>
  
  <p>Say my directory structures are something like this:     </p>
  
  <blockquote>
    <p>/home/user/project1/....bla bla</p>
  </blockquote>
  
  <p>project 1  contains symbolic links, hard links, executable files of software and firmware etc.</p>
  
  <p><strong>My dilemma</strong></p>
  
  <p>Should I use strategy 1 or 2?</p>
  
  <ol>
  <li><p>Should I copy the whole current environment and revert back if upgrading fails.</p>
  
  <blockquote>
    <p><strong>example</strong> -> cp -p -r /home/user/project1/* /home/user/project1_backup/</p>
    
    <p><strong>if upgrading fails --></strong></p>
    
    <p>mv /home/user/project1_backup/ /home/user/project1</p>
  </blockquote></li>
  <li><p>Should I tarball the whole environment and untar it if upgrading fails. To create tar ball, I'm a bit skeptical about preserving symbolic links and hard links .. and same while untar it.      </p></li>
  </ol>
  
  <p>Could some please provide concrete answer which method I should follow and if I go with tar ball approach what will be the bash command.</p>
  
  <p>As far as I know  <code>tar -cvfz</code> for creating tar gunzip <strong>will not</strong> preserve the links and permissions and similarly while untarring the tar ball.
  Please throw some light?</p>