What is Parchive?

Parchive is redundant file format. If you lose part of your file in transmission or in storage, you can use a Parchive file to repair it. It’s like RAID for files instead of a whole file system. – parchive.github.io

It uses a codec called Reed-Solomon Codes. Yes, the same codec that is used by RAID-5.

Parchive is essentially parity files for files.

Getting Started

Parchive project has been there for nearly 20 years, thus there are a lot of compatible software that can create/use PAR2 files. Since I always like CLI-like programs, this tutorial will focus on POSIX software.

You can use GUI, just pay attention to the proper nouns. For Windows, you can use MultiPar; for Linux, you can use Easy PAR2 for KDE.

This guide will use the official command-line utility called par2cmdline

Installation

You can either downloading them from the Releases page, or you can compile them by yourself. It can be used on Windows, Linux, and macOS.

Run par2 -V to check version. I will use par2cmdline version 0.8.1

Note

This tutorial will focus on getting started, so there will be a lot of arguments that we won’t touch.

Creating PAR2 files

You can use the following command to create a parchive for your file easily.

par2 create -m2048 -r20 -v -t4 -a parity.par2 YOUR_FILE

create indicates that we want to create a PAR2 file.

-m2048 means we want to use 2048 MB RAM, you can decrease or increase it as you wish.

-r20 means we can tolerate at most 20% damage of the file. You can modify this as you want.

-t4 means we want to use 4 threads to calculate the parity.

After that, there will be a lot of files starting with parity and ending with .par2, this is our parity file.

You can specify * as your file so that the software will create parity files for all the files in the current directory (you can create parity files for up to 32768 files at a time, as for now), and the software won’t generate parity files for each file, instead, there will only be a few files, containing the parity data for each file.

Verifying files

You can use the following command to verify the parity file you have just created, to see if it works.

par2 verify -m2048 -v -t4 parity.par2

If everything is going well, you can see All files are correct, repair is not required. at the end of the output.

Use cases: Let’s say you have just pulled out your file from your warehouse, and you want to verify if the file is in good condition, you can verify the file in this way.

It is different from using checksum, checksum can only tell if the file is broken or not, but Parchive can tell you if it is possible to repair the file using the redundancy files you already had.

If your file is broken, and it damaged less than 20% (as we specified before), you will see something like this.

Verifying source files:

Opening: "backup.tar"
No data found between offset 0 and 99
Target: "backup.tar" - damaged. Found 1693 of 1999 data blocks.

Scanning extra files:


Repair is required.
1 file(s) exist but are damaged.
You have 1693 out of 1999 data blocks available.
You have 400 recovery blocks available.
Repair is possible.
You have an excess of 94 recovery blocks.
306 recovery blocks will be used to repair.

But if it exceeds 20%, you will see something like this.

Opening: "file.txt"
Target: "file.txt" - damaged. Found 1 of 3 data blocks.

Scanning extra files:


Repair is required.
1 file(s) exist but are damaged.
You have 1 out of 3 data blocks available.
You have 1 recovery blocks available.
Repair is not possible.
You need 1 more recovery blocks to be able to repair.

This way, it is not possible to repair your file, so that’s why you should make the number after -r as big as possible.

It can be bigger than 100%, let’s say your entire file is gone, and part of the redundant file is also broken, if it is bigger than 100%, then it is still possible to recover the original file.

Repairing files

If repair is possible, you can use the following command to repair your file(s).

par2 repair -m2048 -v -t4 parity.par2

You can check the integrity of the file after you repair the file.

Outro

I haven’t introduced the block size, block number, etc. These things can be specified manually instead of adapting them by the software itself. But this is something that you can explore by yourself. Just use par2 --help to investigate.

I hope none of us will lose a single bit of file from now on!

Video Tutorial: Link to YouTube