0

I'd like to use btrfs for backup as well, because it can tell me whether a file is corrupted and I can use snapshots too. Let's assume btrfs found a corrupted file on my backup drive and I still have the original file without the damage. Is there a way to fix the backup file and fix my old snapshots with it as well?

inf3rno
  • 254
  • 1
  • 2
  • 15

1 Answers1

1

You would run a scrub to detect/fix any data issues:

btrfs scrub start /mnt/backup

Once this finishes, if there were unrecoverable errors, search dmesg for details on what files have the errors. Then just copy the files from your main location.

cp /path/to/file /mnt/backup/snapshot/path/to/file

Of course you will have to do this for each snapshot that was corrupted. If the snapshot is read-only, you have to make it writeable first, copy the file, and then set it back to read only.

btrfs property set -ts /mnt/backup/snapshot ro false
cp /path/to/file /mnt/backup/snapshot/path/to/file
btrfs property set -ts /mnt/backup/snapshot ro true

Scripting this should be possible, but in theory this sort of corruption should not happen that often. If you are ending up with many errors it's probably a hardware issue that should be addressed, or potentially a software bug.

Snapshots
btrfs-property

fooot
  • 774
  • 7
  • 16