fix(store): a backup is proven after it is written and repaired when a piece is damaged; a drill passes only on the newest backup
A backup that restores old or wrong books while reporting good is the worst defect the product can have. A piece already in the destination was taken as the piece (its name is its hash), the manifest built on the newest backup whose pieces were the right length, no proof ran after a backup, and the drill fell back to older manifests and recorded ok with the older head. - the manifest just written is read back and proven before the backup is recorded good: every journal and access segment re-hashed, the chain replayed to its head, vault and keys present, the index, and the stored files this backup added plus a rotating sixteenth of the others (every stored file is re-read within 16 manifest numbers; the drill re-hashes all) - a piece found damaged is written again under a generation suffix beside the damaged file (never touched), a new manifest names it, and the reader accepts any generation of a piece whose contents hash right - the drill passes only on the newest manifest, and only when it reaches the head of the last backup recorded good; an older whole backup is a failure that says so with its date - no consolidation: a manifest names the one before it and only what is new (a chain of 64, each link proven by the hash its successor holds) - restore and drill read newest first and stop at the first that proves - live books that are the beginning of the destination's longer history are ahead; any other mismatch is diverged or other books - a new set can begin beside the old (.2), never touching it; set folders carry a fixed prefix so no book id is a reserved name on Windows - no hard link is never a reason to replace: only errors that mean the disk makes no links fall back, to a move that refuses to replace - sealed pieces are sharded by two digits; header settings are capped at 4x and bound into the sealed check; find derives one key per distinct setting - vault scratch files are never backed up as records - files a sync service has not downloaded read as not downloaded yet Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
49459c9f6a
commit
6a8dc6c88b
14 files changed
+2116
-439
No files matched your search
@@ -408,7 +408,12 @@ async fn a_book_backs_itself_up_to_its_folder_soon_after_a_write() {
|
||||
let live = live_head(&home, "acme");
|
||||
assert_eq!(s["head_seq"].as_u64(), Some(live.0));
|
||||
assert_eq!(proven(&home, &folder, "folder"), live);
|
||||
assert!(folder.join("acme").join("READ-ME.txt").is_file());
|
||||
assert!(
|
||||
folder
|
||||
.join("wanderbooks-acme")
|
||||
.join("READ-ME.txt")
|
||||
.is_file()
|
||||
);
|
||||
// Its journal is the live journal's beginning (a drill's check).
|
||||
let scratch = home.outside("scratch-prefix");
|
||||
let found = find(&folder, None, &Ctx::new()).unwrap();
|
||||
@@ -651,21 +656,24 @@ async fn restore_beside_existing_books_and_on_a_clean_install() {
|
||||
assert_eq!(figures(©).await, want);
|
||||
// Its own backups carry on in the same folder, under its own name; the
|
||||
// original's stay as they were.
|
||||
let orig = proven(&home, &folder.join("acme"), "orig-before");
|
||||
let orig = proven(&home, &folder.join("wanderbooks-acme"), "orig-before");
|
||||
let s = call(©, "books.back_up_now", json!({})).await.unwrap();
|
||||
assert_eq!(s["targets"][0]["last_error"], Value::Null, "{s}");
|
||||
assert_eq!(
|
||||
proven(&home, &folder.join("acme-copy"), "copy"),
|
||||
proven(&home, &folder.join("wanderbooks-acme-copy"), "copy"),
|
||||
live_head(&home, "acme-copy")
|
||||
);
|
||||
assert_eq!(proven(&home, &folder.join("acme"), "orig-after"), orig);
|
||||
assert_eq!(
|
||||
proven(&home, &folder.join("wanderbooks-acme"), "orig-after"),
|
||||
orig
|
||||
);
|
||||
drop(copy);
|
||||
assert!(server.close().success());
|
||||
// restore_on_clean_install: another computer's root, nothing in it.
|
||||
let other = Home::new("clean");
|
||||
let server = Server::start(&other, Duration::from_secs(3600));
|
||||
assert_eq!(books_held(&other), Vec::<String>::new());
|
||||
let r = restore(&other, "acme", &folder.join("acme"), false).unwrap();
|
||||
let r = restore(&other, "acme", &folder.join("wanderbooks-acme"), false).unwrap();
|
||||
assert_eq!(r.head, live_head(&home, "acme"));
|
||||
let c = connect(&other, "acme", other.token("acme", &["read"])).await;
|
||||
assert_eq!(figures(&c).await, want);
|
||||
@@ -775,7 +783,7 @@ async fn restore_refuses_a_damaged_backup_and_writes_nothing() {
|
||||
];
|
||||
for (tag, spoil) in damage {
|
||||
let copy = home.outside(&format!("bad-{tag}"));
|
||||
copy_dir(&folder.join("acme"), ©);
|
||||
copy_dir(&folder.join("wanderbooks-acme"), ©);
|
||||
spoil(©);
|
||||
let why = restore(&home, "acme-bad", ©, false).unwrap_err();
|
||||
assert!(why.contains("can't be restored"), "{tag}: {why}");
|
||||
@@ -851,7 +859,7 @@ async fn restore_drill_failure_is_flagged() {
|
||||
let (folder, _) = backed_up_acme(&home).await;
|
||||
assert!(server.close().success());
|
||||
// The backup is changed behind the books' back.
|
||||
let j = &files_below(&folder.join("acme"), "journal/")[0];
|
||||
let j = &files_below(&folder.join("wanderbooks-acme"), "journal/")[0];
|
||||
let mut b = std::fs::read(j).unwrap();
|
||||
let mid = b.len() / 2;
|
||||
b[mid] ^= 1;
|
||||
@@ -1017,7 +1025,7 @@ async fn a_restore_brings_the_vault_and_its_key() {
|
||||
let server = Server::start(&third, Duration::from_secs(3600));
|
||||
for gone in ["keys/", "vault/"] {
|
||||
let copy = home.outside(&format!("no-{}", gone.trim_end_matches('/')));
|
||||
copy_dir(&folder.join("acme"), ©);
|
||||
copy_dir(&folder.join("wanderbooks-acme"), ©);
|
||||
for f in files_below(©, gone) {
|
||||
std::fs::remove_file(f).unwrap();
|
||||
}
|
||||
@@ -1036,7 +1044,7 @@ async fn a_replacing_restore_that_fails_leaves_the_books_open() {
|
||||
let (folder, want) = backed_up_acme(&home).await;
|
||||
let before = live_head(&home, "acme");
|
||||
let bad = home.outside("bad");
|
||||
copy_dir(&folder.join("acme"), &bad);
|
||||
copy_dir(&folder.join("wanderbooks-acme"), &bad);
|
||||
let j = &files_below(&bad, "journal/")[0];
|
||||
let mut b = std::fs::read(j).unwrap();
|
||||
let mid = b.len() / 2;
|
||||
@@ -1095,7 +1103,7 @@ async fn restored_books_never_make_their_backup_folder_again() {
|
||||
// there, empty): restored from a copy of the backup.
|
||||
let copy = home.outside("copy-of-disk");
|
||||
copy_dir(&folder, ©);
|
||||
std::fs::rename(folder.join("acme"), home.outside("unmounted")).unwrap();
|
||||
std::fs::rename(folder.join("wanderbooks-acme"), home.outside("unmounted")).unwrap();
|
||||
let other = Home::new("restore-mount-new");
|
||||
let server = Server::start(&other, Duration::from_secs(3600));
|
||||
restore(&other, "acme", ©, false).unwrap();
|
||||
@@ -1108,13 +1116,16 @@ async fn restored_books_never_make_their_backup_folder_again() {
|
||||
.contains("holds no backup"),
|
||||
"{s}"
|
||||
);
|
||||
assert!(!folder.join("acme").exists(), "made on the wrong disk");
|
||||
assert!(
|
||||
!folder.join("wanderbooks-acme").exists(),
|
||||
"made on the wrong disk"
|
||||
);
|
||||
// The human says it's a new disk: begun there again.
|
||||
let s = call(&c, "books.back_up_now", json!({"new_disk": true}))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(s["targets"][0]["last_error"], Value::Null, "{s}");
|
||||
assert!(folder.join("acme").join("manifests").is_dir());
|
||||
assert!(folder.join("wanderbooks-acme").join("manifests").is_dir());
|
||||
drop(c);
|
||||
assert!(server.close().success());
|
||||
}
|
||||
@@ -1147,7 +1158,7 @@ async fn a_damaged_backup_record_never_keeps_the_books_shut() {
|
||||
assert!(server.close().success());
|
||||
// What it knew of whose backups the folder holds was kept: gone, the
|
||||
// folder's backup is a disk not connected, never made again.
|
||||
std::fs::rename(folder.join("acme"), home.outside("away")).unwrap();
|
||||
std::fs::rename(folder.join("wanderbooks-acme"), home.outside("away")).unwrap();
|
||||
let server = Server::start(&home, Duration::from_secs(3600));
|
||||
let c = connect(&home, "acme", home.token("acme", &["read", "admin"])).await;
|
||||
let s = call(&c, "books.back_up_now", json!({})).await.unwrap();
|
||||
@@ -1158,7 +1169,7 @@ async fn a_damaged_backup_record_never_keeps_the_books_shut() {
|
||||
.contains("holds no backup"),
|
||||
"{s}"
|
||||
);
|
||||
assert!(!folder.join("acme").exists());
|
||||
assert!(!folder.join("wanderbooks-acme").exists());
|
||||
drop(c);
|
||||
assert!(server.close().success());
|
||||
}
|
||||
@@ -1232,7 +1243,7 @@ async fn old_settings_and_an_old_backup_history_are_left_alone_and_said() {
|
||||
let s = call(&c, "books.back_up_now", json!({})).await.unwrap();
|
||||
assert_eq!(s["targets"][0]["last_error"], Value::Null, "{s}");
|
||||
assert_eq!(std::fs::read(old.join("HEAD")).unwrap(), before);
|
||||
assert!(folder.join("acme").join("manifests").is_dir());
|
||||
assert!(folder.join("wanderbooks-acme").join("manifests").is_dir());
|
||||
drop(c);
|
||||
assert!(server.close().success());
|
||||
}
|
||||
@@ -1493,7 +1504,7 @@ async fn a_passphrase_seals_the_backups_and_a_restore_asks_for_it() {
|
||||
let s = call(&c, "books.back_up_now", json!({})).await.unwrap();
|
||||
assert_eq!(s["targets"][0]["sealed"], false, "{s}");
|
||||
assert_eq!(s["targets"][0]["last_error"], Value::Null, "{s}");
|
||||
assert!(folder.join("acme").join("manifests").is_dir());
|
||||
assert!(folder.join("wanderbooks-acme").join("manifests").is_dir());
|
||||
let bytes_after: Vec<Vec<u8>> = sealed_before
|
||||
.iter()
|
||||
.map(|p| std::fs::read(p).unwrap())
|
||||
|
||||
@@ -2697,7 +2697,7 @@ fn a_backup_is_restored_from_the_command_line() {
|
||||
);
|
||||
assert_eq!(s["targets"][0]["last_error"], Value::Null, "{s}");
|
||||
let head = s["head_seq"].as_u64().unwrap();
|
||||
let backup = disk.join("acme");
|
||||
let backup = disk.join("wanderbooks-acme");
|
||||
let backup = backup.to_str().unwrap();
|
||||
// Previewed, and not done without a yes.
|
||||
let out = home.books(&["restore", backup, "--id", "copy"]);
|
||||
@@ -2717,7 +2717,7 @@ fn a_backup_is_restored_from_the_command_line() {
|
||||
// A folder named otherwise: restored as the books it holds, by default
|
||||
// (here: over those, refused), said.
|
||||
let renamed = home.dir.path().join("fernhill-backup");
|
||||
copy_folder(&disk.join("acme"), &renamed);
|
||||
copy_folder(&disk.join("wanderbooks-acme"), &renamed);
|
||||
let out = home.books(&["restore", renamed.to_str().unwrap(), "--yes"]);
|
||||
assert!(
|
||||
String::from_utf8_lossy(&out.stderr).contains("already books called \"acme\""),
|
||||
@@ -2925,9 +2925,9 @@ fn books_are_backed_up_now_from_the_command_line() {
|
||||
String::from_utf8_lossy(&out.stdout).contains("Backed up to the backup folder"),
|
||||
"{out:?}"
|
||||
);
|
||||
assert!(disk.join("acme").join("manifests").is_dir());
|
||||
assert!(disk.join("wanderbooks-acme").join("manifests").is_dir());
|
||||
// A folder gone since: said, and --new-disk begins it again.
|
||||
std::fs::rename(disk.join("acme"), home.dir.path().join("away")).unwrap();
|
||||
std::fs::rename(disk.join("wanderbooks-acme"), home.dir.path().join("away")).unwrap();
|
||||
let out = home.books(&["back-up", "acme"]);
|
||||
assert_eq!(out.status.code(), Some(1), "{out:?}");
|
||||
assert!(
|
||||
@@ -2936,7 +2936,7 @@ fn books_are_backed_up_now_from_the_command_line() {
|
||||
);
|
||||
let out = home.books(&["back-up", "acme", "--new-disk"]);
|
||||
assert!(out.status.success(), "{out:?}");
|
||||
assert!(disk.join("acme").join("manifests").is_dir());
|
||||
assert!(disk.join("wanderbooks-acme").join("manifests").is_dir());
|
||||
a.end();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user