Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

to preserve hard and symbolic link, permissions while creating tar ball and doing same while untar the tarball [closed]

Tags:

linux

bash

Task: To provide facility to upgrade the system remotely or add new features.

What I am supposed to do Create a back up of current environment of target machine and if upgrading fails at any stage, then revert back to original environment.

Say my directory structures are something like this:

/home/user/project1/....bla bla

project 1 contains symbolic links, hard links, executable files of software and firmware etc.

My dilemma

Should I use strategy 1 or 2?

  1. Should I copy the whole current environment and revert back if upgrading fails.

    example -> cp -p -r /home/user/project1/* /home/user/project1_backup/

    if upgrading fails -->

    mv /home/user/project1_backup/ /home/user/project1

  2. 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.

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.

As far as I know tar -cvfz for creating tar gunzip will not preserve the links and permissions and similarly while untarring the tar ball. Please throw some light?

like image 638
samantha Avatar asked Jun 15 '12 09:06

samantha


1 Answers

I would use the second option: create a tarball; because tarballs have some positive points:

  • You can preserve permission/specials files across filesystems (usefull when you backup your a ext* folder to an NTFS filesystem)
  • A copy of one single big file will be faster than a thousand small files
  • You can compress it.

And here is the command:

tar --preserve-permissions --preserve-order -jc /path/to/your/folder > /path/to/your/backup_file.tar.bz2

This shall preserve your permission, your symlinks. And for the hardlinks, I give you this link (http://www.gnu.org/software/tar/manual/html_node/hard-links.html)

(but by default, tar preserve hardlinks)

Don't forget to test your tarball before upgrading your system !!

(you will avoid almost all lose of data in the case of the archive isn't correctly created)

like image 88
neam Avatar answered Sep 21 '22 02:09

neam