#!/bin/bash

## Copyright (C) 2023 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -x
set -e
set -o errtrace
set -o pipefail
set -o nounset

source /usr/bin/qubes-raw-backup-adrelanos-shared

command -v cmp >/dev/null
command -v blockdev >/dev/null

## Get the size of the original disk in bytes.
original_size=$(blockdev --getsize64 "$original_disk")

## Using cp with --bytes="$original_size" to ensure that the comparison stops
## at the size of the original disk, even if the backup disk is larger.
## This way, the comparison is not confused if the backup_disk is larger.
pv "$original_disk" | cmp --bytes="$original_size" /dev/stdin "$backup_disk"

## Alternative. Untested!
#ddrescue --verbose --no-scrape --size="$original_size" "$original_disk" "$backup_disk" ~/logfile
