I would like to generate parchive par2 parity files for long-term storage of a restic repository. This helps to recover from errors in case repository is corrupted. Restic currently doesn’t have error correction feature (Duplicity is the only backup app that generates par2 files AFAIK).
Does anyone know what’s the best way to create these par2 files? Should I write a bash script to recursively create par2 files for each file in the restic depository? Or should I generate a tar file from the whole restic repository and then create Par2 files for that one file? But this increases the required space by factor 2 since tarball must be saved too (a tarball generated 10 years later from the same repository may not be same as today’s tarball due to software updates).
Anyone has dealt with error correction with Restic?
That’s the way I do it. It means that it’s nice and quick to make par2 files for the newest additions after each backup (just find any recently-created files). I don’t tend to prune much, so am happy for the odd par2 file to hang around even when the corresponding restic file has been deleted. Otherwise, just make a script to delete the unused par2 files after a prune operation.
In order to avoid making a mess in my repo directory (although I don’t think restic would care if I did), I have a corresponding directory tree just for the par2 files.
My scripts are rather amateurish, and proper engineers would probably balk at them. Happy to share if needed, but it would be better to have more elegant examples in the forum if anyone has any?
Yes, I seem to recall that was a bit of a hassle. I think you have to be careful from where you execute the command. My script does the following (I don’t know which bits are critical, and which are just how I wrote it)…
Assuming you want to make a parchive of the file: /backup/restic_repo/data/c4/c4048768c4bd77232a7ffc5c4c3671b13e0234c246c80ceabbcd1a68365d1c58
into the file: /backup/restic_par/restic_repo/data/c4/c4048768c4bd77232a7ffc5c4c3671b13e0234c246c80ceabbcd1a68365d1c58-5.par2
Then run the following commands:
cd /backup
par2create -B ./ -p -n1 -r5 /backup/restic-par/restic-repo/data/c4/c4048768c4bd77232a7ffc5c4c3671b13e0234c246c80ceabbcd1a68365d1c58 restic-repo/data/c4/c4048768c4bd77232a7ffc5c4c3671b13e0234c246c80ceabbcd1a68365d1c58
My full script is below. Use at your own risk :)
#!/bin/bash
#paths to the repo and the parchive directory
rootpath=/path/below/repo
repodir=restic_repo
pardir=restic_repo_parchive
#percentage redundancy desired
PERC=5
#oldest file for which to create parchive files (-3 = 3 days before present)
mtime=-3
cd $rootpath
#find any files changed within $mtime days and pipe them into the do loop
find $repodir -type f -mtime $mtime -print0 | while IFS= read -r -d '' FILE
do
DIR=$(dirname "${FILE}")
DIR_OUT="$rootpath/$pardir/${DIR}"
FILENAME=$(basename "${FILE}")
PAR_ROOT_OUT="$DIR_OUT/${FILENAME}"
FILE_OUT="$DIR_OUT/${FILENAME}"-$PERC.par2
#create directory if it doesn't exist
if [[ ! -d $DIR_OUT ]]; then
echo making directory "$DIR_OUT"
mkdir -p "$DIR_OUT"
fi
#create par file if it doesn't exist
if [ ! -f "$FILE_OUT" ]; then
echo executing: par2create -B ./ -p -n1 -r$PERC "${PAR_ROOT_OUT}" "${FILE}"
echo in `pwd`
par2create -B ./ -q -n1 -r$PERC "${PAR_ROOT_OUT}" "${FILE}"
#remove the unnecessary file created by par2create
rm "${PAR_ROOT_OUT}".par2
#and rename the other file to the correct name
mv "${PAR_ROOT_OUT}".vol*par2 "$FILE_OUT"
fi
done
Thank you so much. Much effort to get something most other tools can do by command-line options
I have scheduled par2 for our existing restic repos for Friday, so it can finish over the weekend…
Indeed i had to restore a 8 years old version of file some weeks ago and was very happy not no have any errors on this 8 years more or less untouched backup (bacula)…
Actually a much nicer solution would be to post-process created/deleted files directly after they are written to or deleted from the backend. That would need support from restic, but it would be only a comparably small enhancement.
I think about implementing such a feature in rustic.
This is great! Amazing how fast and easily you can push forward Rustic.
I suppose it can add par2 files to the current restic repositories. Will Restic normally function afterwards, since par2 files are separate? I have a lot of backup scripts with restic.
Sorry that I have to disappoint you - this does only add par2 files to newly added files (and remove the corresponding par2 files when files are removed). So, for existing repos the par2 files must be manually generated for all already existing repo files.
restic (and rustic) will happily ignore additional files which don’t have a filename corresponding to a sha256 hash. But keep in mind that restic won’t add .par2 files to newly created files unless a similar solution is added like the one I’ve added to rustic.