Announcement

Collapse
No announcement yet.

Backup with Tar in Linux

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Backup with Tar in Linux

    As Linux system administrator one of the most important tasks to be done is the system backup. Hardware/software failures will bring down your system and then you must be prepared to recover it as quickly and efficiently as possible. In order to perform system backup Linux offers several commands/services depending on the type of backup required.
    tar

    This command is used for creating full backups of an entire part of the system that do not change a lot. For example to backup the /usr/local system directory :

    Code:
    $ tar cvfz usr_local.tar.gz /usr/local
    It creates 'c' a compressed 'z' tar file 'usr_local.tar.gz' that contains all /usr/local structure and data preserving files permissions and ownership. As the data is compressed and archived on the tar file the backups uses less space that the original data, and can be transferred to another machines using scp or ftp.

    Note: By default selinux file attributes are not preserved on the tar file. In order to preserve selinux atributtes '--selinux' flag must be used.

    * In order to recover tar file on the system the following command must be used :
    Code:
    $ tar tvzf usr_local.tar.gz
    ...
    drwxr-xr-x root/root 0 2009-12-04 14:33 usr/local/share/man/man4x/
    drwxr-xr-x root/root 0 2009-12-04 14:33 usr/local/libexec/
    drwxr-xr-x root/root 0 2009-12-04 14:33 usr/local/include/
    It shows the files that are going to be restored on the system without performing the restore at all. It is just a test 't' to be warned where the files will be restored on the system. NOTE: the file path reported is the file system path where the file will be restored: in this case is usr/local/ what means that if the tar file is restored on /tmp directory the files will be written on /tmp/usr/local.

    Once sure where the files are going to be written using tar test mode the restore can be done :
    Code:
    $ cd /
    $ tar xvfz /root/usr_local.tar.gz
    ...
    usr/local/share/man/man4x/
    usr/local/libexec/
    usr/local/include/
    Last edited by kuldeep; 02-22-2015, 12:06 AM.
Working...
X