Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Veracrypt command in dismount() function should use $volume_path not $mount_point #229

Open
snmw opened this issue May 14, 2022 · 2 comments
Labels

Comments

@snmw
Copy link

snmw commented May 14, 2022

Guide

How to back up and encrypt data using rsync and VeraCrypt on macOS

Summary

In trying to implement these backup scripts for the first time, I noticed that the call to veracrypt in the dismount() function that's used in backup.sh and restore.sh errors out and fails to find a valid volume if the command is as written. I think it should check whether the mount point is an existing directory, then dismount the volume path, or am I missing something?

This is current state (errors out):

veracrypt --text --dismount "$mount_point"

But it seems not to work unless I change it to this:

veracrypt --text --dismount "$volume_path"

Which would change the whole function to:

function dismount()
{
  if [ -d "$mount_point" ]; then
    veracrypt --text --dismount "$volume_path"
  fi
}

Or, in the here document:

function dismount()
{
  if [ -d "\$mount_point" ]; then
    veracrypt --text --dismount "\$volume_path"
  fi
}

System:

  • macOS Big Sur 11.6.5
  • bash 5.1.16
@snmw snmw added the bug label May 14, 2022
@sunknudsen
Copy link
Owner

Hey @sn-wolf, thanks for submitting issue.

Can you please paste output of cat backup.sh here making sure you remove anything private references?

In theory, everything should work (just ran a diff on my instance).

Standby!

@snmw
Copy link
Author

snmw commented Aug 16, 2022

Hey @sunknudsen, thanks for the response! I'm not sure what the problem is on my system, because the Veracrypt docs suggest that the "Mount directory of the volume's filesystem (if mounted)" is a valid argument to the --dismount flag, but when I run the script using $mount_point in the dismount function, I get "Error: No such volume is mounted." Maybe it's a weird macOS filesystem thing?

This is what I've been running successfully:

#! /bin/bash

set -e
set -o pipefail

function dismount()
{
  if [ -d "$mount_point" ]; then
    veracrypt --text --dismount "$volume_path"
  fi
}

trap dismount ERR INT

volume_path="$BACKUP_VOLUME_PATH"
mount_point="/Volumes/Backup"

veracrypt \
  --text \
  --mount \
  --pim "0" \
  --keyfiles "" \
  --protect-hidden "no" \
  "$volume_path" \
  "$mount_point"

mkdir -p "$mount_point/Versioning"

files=(
  "$HOME/directory1"
  "$HOME/directory2"
)

for file in "${files[@]}"; do
  rsync \
    -axRS \
    --backup \
    --backup-dir \
    "$mount_point/Versioning" \
    --delete \
    --suffix="$(date +".%F-%H%M%S")" \
    "$file" \
    "$mount_point"
done

if [ "$(find "$mount_point/Versioning" -type f -ctime +90)" != "" ]; then
  printf "Do you wish to prune versions older than 90 days (y or n)? "
  read -r answer
  if [ "$answer" = "y" ]; then
    find "$mount_point/Versioning" -type f -ctime +90 -delete
    find "$mount_point/Versioning" -type d -empty -delete
  fi
fi

open "$mount_point"

printf "Inspect backup and press enter"

read -r answer

dismount

printf "Generate hash (y or n)? "
read -r answer
if [ "$answer" = "y" ]; then
  openssl dgst -sha512 "$volume_path"
fi

printf "%s\n" "Done"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants