Execute virtualbox and run CentOS machine.
$ virtualbox
Login as a root/password.
Creating archives from tar
$ tar -cvf archive.tar /etc
This example creates an archive archive.tar for files in directory /etc
Note that this command creates a normal archive, not a compressed one. For compression use “z” for tar.gz and “j” for tar.bz2.
Uncompressing the archives
$ tar -xvf archive.tar
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
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 that, incremental dumps crucially on time-stamps. Any interference with them could cause trouble.
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