You've hit on a very important distinction that often confuses people when it comes to checksums! You're absolutely right: if you modify a file, even slightly (like adding layers to a Photoshop file), its checksum will be completely different.
This means that checksums are not for telling you if a file has been modified by you. They are for detecting unintended changes or corruption.
Let me clarify how checksums are used in the context of preventing and detecting corruption during backups:
How Checksums Work for Corruption Detection
-
Before Backup (Source Integrity Check):
- Purpose: To ensure the file you're about to back up on your source disk (e.g., your C: drive) is not already corrupted.
- Process: You would (ideally) calculate a checksum of the source file just before the backup starts.
- Example: You have
my_ps_file.psd with many layers. You calculate its SHA256 hash: hash_A. This hash_A represents the "known good" state of that file at this moment.
- What it detects: If
my_ps_file.psd on your source disk somehow got corrupted before you even started the backup (e.g., due to a disk error), calculating its hash might produce an error, or the hash might not match a previously known good hash (if you maintain such a record for long-term source integrity). However, this is less common for pre-backup checks; its primary use is for the next step.
-
During/After Backup (Transfer/Storage Integrity Check):
- Purpose: This is the primary use of checksums in backup verification. It ensures that the file was transferred correctly and stored on the backup medium without corruption.
- Process:
- Step 1 (Source Baseline): Just before the file is transferred, its checksum is calculated on the source system. Let's say
hash_A for my_ps_file.psd.
- Step 2 (Destination Verification): After the file has been copied to the backup destination (e.g., external drive, cloud storage), its checksum is calculated again on the backup destination. Let's say
hash_B for my_ps_file.psd on the backup drive.
- Step 3 (Comparison): The backup software then compares
hash_A and hash_B.
- What it detects:
- If
hash_A == hash_B: The file was transferred correctly and the copy on the backup destination is an exact, byte-for-byte duplicate of the file on the source at the moment it was backed up. This means no corruption occurred during the transfer or initial storage.
- If
hash_A != hash_B: This immediately flags the backup as corrupt for that file. Something went wrong during the copy process (e.g., a bad sector on the destination drive, a network glitch for cloud backups, RAM error during copying).
-
Long-Term Archival Integrity (Bit Rot Detection):
- Purpose: To detect silent data corruption (often called "bit rot") on the backup medium over time. Disks, tapes, and even SSDs can silently flip bits over months or years.
- Process:
- When the backup is initially made, the checksum (
hash_A) of the file as it was backed up is stored alongside the backup (e.g., in a manifest file, or within the backup archive itself).
- Months or years later, you can instruct your backup software (or a separate utility) to "scrub" or "verify" your backups. This involves recalculating the checksum of the file on the backup medium (let's call it
hash_C).
hash_C is then compared to the hash_A that was stored at the time of backup.
- What it detects: If
hash_C != hash_A, it means the file on your backup medium has become corrupted since it was backed up. This is critical for long-term data preservation.
Your Photoshop Example Revisited
-
Scenario 1: You modify my_ps_file.psd (add layers) on your source drive.
- The new
my_ps_file.psd (with layers) is now the file you want to back up.
- Its checksum will be different from the single-layer version. This is expected.
- When you back it up, the process will calculate the checksum of this new file before transfer, then again on the backup destination, and compare them. This ensures the new, multi-layer version is backed up correctly.
-
Scenario 2: You back up my_ps_file.psd (with many layers). Its checksum at this point is hash_X. This hash_X is stored with the backup.
- Months later, you restore it. If the restored file's checksum is still
hash_X, it's good.
- If, however, the backup disk suffered bit rot and the file on the backup disk itself is now subtly altered, its current checksum will be
hash_Y (where hash_Y != hash_X). The checksum verification process will flag this as corruption on the backup.
In essence:
Checksums don't care what the file's content is, only that the digital fingerprint of that content is consistent between two points in time or two locations. They are primarily a tool for guaranteeing the integrity of a file during transfer and storage, not for tracking user-initiated modifications.
Many sophisticated backup solutions (like Duplicati, BorgBackup, Veeam, ZFS/Btrfs filesystems) leverage checksums extensively for exactly these purposes.