Using Veracrypt and Rsync for Backup Between Multiple Computers [2021-08-11]
I thank Sun Knudsen's privacy guides for this post. This method of backup is not convenient, rather it offers a secure and privacy-friendly alternative to the usual means of file synchronization. There are three notable levels of precaution. First, we prefer physical external drives as a way to prevent unwanted access and tampering from third parties. Second, we will store files in an encrypted volume by way of Veracrypt. Third, we will hash the volume using the SHA-512 algorithm as a final measure against tampering.
For my use case, Rsync was the most appropriate tool that I found. I highly recommend checking out the algorithm below.
The general process to backup files to the veracrypt volume using rsync is as follows.
However, I have also written a Linux bash shell script to do this for me. Remember to enable this scripts execution permission using chmod +x /path_to_script
#! /bin/sh
set -e
set -o pipefail
veracrypt -t -m --pim=0 -k "" --protect-hidden=no /path_to_volume /path_to_mount
rsync -axSP --exclude="file_type_to_exclude" --exclude=/path_to_file /path_of_source1 /path_to_mount
rsync -axSP --exclude="file_type_to_exclude" --exclude=/path_to_file /path_of_source2 /path_to_mount
veracrypt -t -d /path_to_mount
openssl dgst -sha512 /path_to_volume
Below is a script for checking the hash of your backup.
#! /bin/sh
set -e
set -o pipefail
printf "Backup hash: "
read -r previous
current=$(openssl dgst -sha512 /path_to_volume)
current=${current:39}
printf "Current hash: %s\n" $current
if [ "$current" != "$previous" ]; then
printf "%s\n" "Integrity check failed"
exit 1
fi
if [ "$current" == "$previous" ]; then
printf "%s\n" "Integrity check passed"
exit 1
fi
Note, we use the --delete option in the below rsync commands. Use precaution as this will delete files so your local machine will sync with your backup on your usb flash drive. When you are syncing folders, follow the syntax I have given below.
#! /bin/sh
set -e
set -o pipefail
veracrypt -t -m --pim=0 -k "" --protect-hidden=no /path_to_volume /path_to_mount
rsync -axSP --delete /path_to_mount/path_of_folder/ /path_of_folder
rsync -axSP --delete /path_to_mount/path_of_file /path_of_file
veracrypt -t -d /path_to_mount
printf "%s\n" "Done"
If you are familiar with collaborating through git, I would treat your usb flash drive as a remote repository and your backup as the master branch. However, with my current script, you MUST load from back up before you make any changes on your local machine as they will be deleted in order to match the backup. To change this, simply omit --delete from the load script.
If you have any suggestions, please email me.