In my last post I introduced ZPAQ and sang it's praises.

However, the fact that it's faster than Gzip,Bzip2 and XZ and produces smaller files than all of them is not why I fell in love with it.

It's ability to do incremental backups is.

In this post I'll demonstrate how incremental backups work and how to use them.

1. Once again, let's install ZPAQ:

yum install http://download.opensuse.org/repositories/home:/antonbatenev:/zpaq-upstream/ScientificLinux_6/x86_64/zpaq-upstream-7.13-3.1.x86_64.rpm -y

2. To demonstrate this, we're going to grab the same source code of Firefox again:

mkdir /tmp/firefox
curl https://archive.mozilla.org/pub/firefox/releases/47.0/firefox-47.0.linux-x86_64.sdk.tar.bz2 | tar jxf - -C /tmp/firefox/

3. Nice - now let's create a base ZPAQ archive - there is only one difference from the way we used the command before - that is the '?' at the end of the filename.

Before:

zpaq add firefox47source /tmp/firefox/

Now:

zpaq add firefox47source? /tmp/firefox/

Note the following in the output:

zpaq v7.13 journaling archiver, compiled May 7 2016
Creating firefox47source1.zpaq at offset 0 + 0
Adding 447.897244 MB in 6136 files -method 14 -threads 2 at 2016-06-21 04:12:02

firefox47source1.zpaq - ZPAQ automatically suffixed the filename with the number 1.

Let's also check our directory contents:

ls -alh /root/*.zpaq
-rw-r--r-- 1 root root 80M Jun 21 04:12 /root/firefox47source1.zpaq

4. Now, let's try running another backup and see what happens:

zpaq add firefox47source? /tmp/firefox/
zpaq v7.13 journaling archiver, compiled May 7 2016
firefox47source?.zpaq: 1 versions, 6250 files, 8952 fragments, 83.551155 MB
Creating firefox47source2.zpaq at offset 0 + 83551155
Adding 0.000000 MB in 0 files -method 14 -threads 2 at 2016-06-21 04:16:30.
0 +added, 0 -removed.
deleted firefox47source2.zpaq

0.000000 + (0.000000 -> 0.000000 -> 0.000000) = 0.000000 MB
0.094 seconds (all OK)

In the above note the line: deleted firefox47source2.zpaq - this is because there was nothing added since the last backup.

5. Let's add some files and run it again - I'm going to copy the /etc directory inside /tmp/firefox:

cp -R /etc/ /tmp/firefox/

And run the backup again:

zpaq add firefox47source? /tmp/firefox/
zpaq v7.13 journaling archiver, compiled May 7 2016
firefox47source?.zpaq: 1 versions, 6250 files, 8952 fragments, 83.551155 MB
Creating firefox47source2.zpaq at offset 0 + 83551155
Adding 26.770446 MB in 712 files -method 14 -threads 2 at 2016-06-21 04:17:54.

As you can see it did create the file this time - added 26.7MB in 712 files.

Let's check our files again:

ls -alh /root/*.zpaq
-rw-r--r-- 1 root root 80M Jun 21 04:12 /root/firefox47source1.zpaq
-rw-r--r-- 1 root root 6.9M Jun 21 04:17 /root/firefox47source2.zpaq

And there you have it - incremental backups.

6. How do we restore this?

zpaq extract firefox47source? -to /goatmaster/

The result includes the /etc/ directory as well:

du -hs /goatmaster/tmp/firefox/etc/
28M /goatmaster/tmp/firefox/etc/