To preserve a hard and symbolic link, permissions when creating a tar ball and executing them when unpacking a tarball

Objective: provide the ability to remotely update the system or add new features.

What am I supposed to do . Back up the current environment of the target computer, and if the update fails at any stage, return to the original environment.

Say my directory structures look something like this:

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

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

My dilemma

Should I use strategy 1 or 2?

  • Do I have to copy the entire current environment and come back if the update fails.

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

    if update fails β†’

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

  • Do I have to archive the entire environment and deploy it if the update fails. To create a tar ball, I'm a little skeptical about saving symbolic links and hard links ... and the same, until I figured it out.

Can someone please give a specific answer, which method should I follow, and if I go using the ball-ball approach, what will be the bash command.

As far as I know, tar -cvfz for creating tar gunzip will not save links and permissions and similarly until the tar ball is disclosed. Please throw some light?

+6
source share
1 answer

I would use the second option: create a tarball; because tarballs have a few good points:

  • You can save permissions / special files on file systems (useful when backing up your ext * folder to an NTFS file system)
  • A copy of one large file will be faster than a thousand small files
  • You can squeeze it.

And here is the command:

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

This will save your permission, your symbolic links. And for hard links, I give you this link ( http://www.gnu.org/software/tar/manual/html_node/hard-links.html )

(but by default tar saves hardlinks)

Remember to check your archive before updating the system.

(you will avoid almost all data loss if the archive is created incorrectly)

+10
source

Source: https://habr.com/ru/post/918159/


All Articles