Product SiteDocumentation Site

11.2. Practice

11.2.1. Unix/Linux

For those who don’t know “tar” stands for tape archive, which is used by System administrators to take backup. The tar command used to rip a collection of files and directories into highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux. The tar is most widely used command to create compressed archive files and that can be moved easily from one disk to another disk or machine to machine. In this tutorial, we are going to show you the usage of a rarely used feature of the tar command known as Incremental Dumps.
  1. Login to the remote system, see - Chapter 2, Cvičenie 1/Practice 1 - Connection Setup
  2. Execute virtualbox and run CentOS machine.
    $ virtualbox
  3. Login as a root/password.
  4. Creating archives from tar
    $ tar -cvf archive.tar /etc
    This example creates an archive archive.tar for files in directory /etc
    • c – creating archive
    • v – verbose mode
    • f – filename type for the archive

    Note

    Note that this command creates a normal archive, not a compressed one. For compression use “z” for tar.gz and “j” for tar.bz2.
  5. Uncompressing the archives
    $ tar -xvf archive.tar
    • Here, “x” argument is given for extraction of the archive.
  6. Normally, If we have a large amount of data (which is common nowadays) stored on our devices backup can a long time to complete. So Initially we would want to a full backup for the first time and then for all the next times we would want that only those files which are modified or added should get in the backup leaving behind the obsolete and unchanged files. This feature is provided by “tar” by simply providing an argument “-listed-incremental=snapshot-file” where snapshot-file is a special file maintained by the tar command to determine the files that are been added,modified or deleted. So let’s see an example :
    $ tar --listed-incremental=snapshot.file -cvzf backup.tar.gz /var/www
    Let’s understand what’s happening with the above command. Only the –listed-incremental argument is added more to usual creating archive command. In the above command if the snapshot.file is not existing then tar takes a full (level-0) backup and creating the snapshot file with the additional metadata. Otherwise, it will create an incremented archive backup.tar.gz containing only the changed files by examining the snapshot.file. This will be called “level-1” backup.
    $ touch /var/www/test.txt
    $ tar --listed-incremental=snapshot.file -cvzf backup.1.tar.gz /var/www
  7. Note that, the original snapshot file will be lost and it will be updated to the new contents again. So if we want to make more “level-1” backups we can copy the snapshot file and then provide it to tar. If we don’t need that then we need to do nothing it will simply created another incremented archive.
    $ cp snapshot.file snapshot.file.1
    $ tar --listed-incremental=snapshot.file.1 -cvzf backup.1.tar.gz /var/www
    
    This will use the old snapshot file and make again a “level-1” backup.

    Note

    Note that, incremental dumps crucially on time-stamps. Any interference with them could cause trouble.
  8. In the same way, we can extract the incremental backups. So if we had created several levels of incremental files, then in order to restore the exact contents the file system had when the last level was created, we will need to restore from all backups in turn. At first, do level-0 extraction:
    tar -xvf backup.tar.gz -C /var/www
    and then, level-1 extraction:
    $ tar -xvf backup.1.tar.gz -C /var/www