Skip to content

Commit

Permalink
init snapshots
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Mar 12, 2024
1 parent 90efaab commit 674ba06
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 28 deletions.
127 changes: 107 additions & 20 deletions crates/core/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,35 +113,60 @@ fn test_backup_with_dir_passes(dir_testdata: PathBuf, set_up_repo: Result<RepoOp
let opts = BackupOptions::default().as_path(PathBuf::from_str("test")?);

// first backup
let first_backup = repo.backup(&opts, &paths, SnapshotFile::default())?;
assert_debug_snapshot!(TestSummary(&first_backup));
assert_eq!(first_backup.parent, None);
let first_snapshot = repo.backup(&opts, &paths, SnapshotFile::default())?;
#[cfg(windows)]
assert_debug_snapshot!(
"backup-dir-summary-first-windows",
TestSummary(&first_snapshot)
);

#[cfg(not(windows))]
assert_debug_snapshot!("backup-dir-summary-first-nix", TestSummary(&first_backup));

assert_eq!(first_snapshot.parent, None);

// tree of first backup
// re-read index
let repo = repo.to_indexed_ids()?;
let tree = repo.node_from_path(first_backup.tree, Path::new("test/tests"))?;
let tree = repo.node_from_path(first_snapshot.tree, Path::new("test/tests"))?;
let tree = repo.get_tree(&tree.subtree.expect("Sub tree"))?;
assert_debug_snapshot!(tree);

#[cfg(windows)]
assert_debug_snapshot!("backup-dir-tree-windows", tree);

#[cfg(not(windows))]
assert_debug_snapshot!("backup-dir-tree-nix", tree);

// get all snapshots and check them
let all_snapshots = repo.get_all_snapshots()?;
assert_eq!(vec![first_backup.clone()], all_snapshots);
assert_eq!(vec![first_snapshot.clone()], all_snapshots);
// save list of pack files
let packs1: Vec<_> = repo.list(rustic_core::FileType::Pack)?.collect();

// re-read index
let repo = repo.to_indexed_ids()?;
// second backup
let second_snapshot = repo.backup(&opts, &paths, SnapshotFile::default())?;
assert_debug_snapshot!(TestSummary(&second_snapshot));
assert_eq!(second_snapshot.parent, Some(first_backup.id));
assert_eq!(first_backup.tree, second_snapshot.tree);

#[cfg(windows)]
assert_debug_snapshot!(
"backup-dir-summary-second-windows",
TestSummary(&second_snapshot)
);

#[cfg(not(windows))]
assert_debug_snapshot!(
"backup-dir-summary-second-nix",
TestSummary(&second_snapshot)
);

assert_eq!(second_snapshot.parent, Some(first_snapshot.id));
assert_eq!(first_snapshot.tree, second_snapshot.tree);

// get all snapshots and check them
let mut all_snapshots = repo.get_all_snapshots()?;
all_snapshots.sort_unstable();
assert_eq!(vec![first_backup, second_snapshot], all_snapshots);
assert_eq!(vec![first_snapshot, second_snapshot], all_snapshots);

// pack files should be unchanged
let packs2: Vec<_> = repo.list(rustic_core::FileType::Pack)?.collect();
Expand All @@ -166,28 +191,60 @@ fn test_backup_with_tar_gz_passes(
let opts = BackupOptions::default().as_path(PathBuf::from_str("test")?);

// first backup
let first_backup = repo.backup(&opts, paths, SnapshotFile::default())?;
assert_debug_snapshot!(TestSummary(&first_backup));
assert_eq!(first_backup.parent, None);
let first_snapshot = repo.backup(&opts, paths, SnapshotFile::default())?;

#[cfg(windows)]
assert_debug_snapshot!(
"backup-tar-summary-first-windows",
TestSummary(&first_snapshot)
);

#[cfg(not(windows))]
assert_debug_snapshot!("backup-tar-summary-first-nix", TestSummary(&first_backup));

assert_eq!(first_snapshot.parent, None);

// // tree of first backup
// // re-read index
// let repo = repo.to_indexed_ids()?;
// let tree = repo.node_from_path(first_snapshot.tree, Path::new("test/tests"))?;
// let tree = repo.get_tree(&tree.subtree.expect("Sub tree"))?;

// #[cfg(windows)]
// assert_debug_snapshot!("backup-tar-tree-windows", tree);

// #[cfg(not(windows))]
// assert_debug_snapshot!("backup-tar-tree-nix", tree);

// get all snapshots and check them
let all_snapshots = repo.get_all_snapshots()?;
assert_eq!(vec![first_backup.clone()], all_snapshots);
assert_eq!(vec![first_snapshot.clone()], all_snapshots);
// save list of pack files
let packs1: Vec<_> = repo.list(rustic_core::FileType::Pack)?.collect();

// re-read index
let repo = repo.to_indexed_ids()?;
// second backup
let second_snapshot = repo.backup(&opts, paths, SnapshotFile::default())?;
assert_debug_snapshot!(TestSummary(&second_snapshot));
assert_eq!(second_snapshot.parent, Some(first_backup.id));
assert_eq!(first_backup.tree, second_snapshot.tree);

#[cfg(windows)]
assert_debug_snapshot!(
"backup-tar-summary-second-windows",
TestSummary(&second_snapshot)
);
#[cfg(not(windows))]
assert_debug_snapshot!(
"backup-tar-summary-second-nix",
TestSummary(&second_snapshot)
);

assert_eq!(second_snapshot.parent, Some(first_snapshot.id));
assert_eq!(first_snapshot.tree, second_snapshot.tree);

// get all snapshots and check them
let mut all_snapshots = repo.get_all_snapshots()?;
all_snapshots.sort_unstable();
assert_eq!(vec![first_backup, second_snapshot], all_snapshots);
assert_eq!(vec![first_snapshot, second_snapshot], all_snapshots);

// pack files should be unchanged
let packs2: Vec<_> = repo.list(rustic_core::FileType::Pack)?.collect();
Expand All @@ -212,7 +269,16 @@ fn test_backup_dry_run_with_tar_gz_passes(

// dry-run backup
let snap_dry_run = repo.backup(&opts, paths, SnapshotFile::default())?;
assert_debug_snapshot!(TestSummary(&snap_dry_run));

#[cfg(windows)]
assert_debug_snapshot!(
"dryrun-tar-summary-first-windows",
TestSummary(&snap_dry_run)
);

#[cfg(not(windows))]
assert_debug_snapshot!("dryrun-tar-summary-first-nix", TestSummary(&snap_dry_run));

// check that repo is still empty
let snaps = repo.get_all_snapshots()?;
assert_eq!(snaps.len(), 0);
Expand All @@ -225,12 +291,33 @@ fn test_backup_dry_run_with_tar_gz_passes(
assert_eq!(snap_dry_run.tree, first_snapshot.tree);
let packs: Vec<_> = repo.list(rustic_core::FileType::Pack)?.collect();

// // tree of first backup
// // re-read index
// let repo = repo.to_indexed_ids()?;
// let tree = repo.node_from_path(first_snapshot.tree, Path::new("test/tests"))?;
// let tree = repo.get_tree(&tree.subtree.expect("Sub tree"))?;

// #[cfg(windows)]
// assert_debug_snapshot!("dryrun-tar-tree-windows", tree);

// #[cfg(not(windows))]
// assert_debug_snapshot!("dryrun-tar-tree-nix", tree);

// re-read index
let repo = repo.to_indexed_ids()?;
// second dry-run backup
let opts = opts.dry_run(true);
let snap_dry_run = repo.backup(&opts, paths, SnapshotFile::default())?;
assert_debug_snapshot!(TestSummary(&snap_dry_run));

#[cfg(windows)]
assert_debug_snapshot!(
"dryrun-tar-summary-second-windows",
TestSummary(&snap_dry_run)
);

#[cfg(not(windows))]
assert_debug_snapshot!("dryrun-tar-summary-second-nix", TestSummary(&snap_dry_run));

// check that no data has been added
let snaps = repo.get_all_snapshots()?;
assert_eq!(snaps, vec![first_snapshot]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/core/tests/integration.rs
expression: TestSummary(&first_backup)
expression: TestSummary(&first_snapshot)
---
TestSnap {
hostname: "",
Expand All @@ -17,13 +17,13 @@ TestSnap {
files_changed: 0,
files_unmodified: 0,
total_files_processed: 73,
total_bytes_processed: 1125676,
total_bytes_processed: 1125674,
dirs_new: 5,
dirs_changed: 0,
dirs_unmodified: 0,
total_dirs_processed: 5,
data_blobs: 70,
tree_blobs: 5,
data_added_files: 1125654,
data_added_files_packed: 78741,
data_added_files: 1125653,
data_added_files_packed: 78740,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/core/tests/integration.rs
expression: TestSummary(&snap2)
expression: TestSummary(&second_snapshot)
---
TestSnap {
hostname: "",
Expand All @@ -17,7 +17,7 @@ TestSnap {
files_changed: 0,
files_unmodified: 73,
total_files_processed: 73,
total_bytes_processed: 1125682,
total_bytes_processed: 1125674,
dirs_new: 0,
dirs_changed: 0,
dirs_unmodified: 5,
Expand Down
129 changes: 129 additions & 0 deletions crates/core/tests/snapshots/integration__backup-dir-tree-windows.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
source: crates/core/tests/integration.rs
expression: tree
---
Tree {
nodes: [
Node {
name: "empty-file",
node_type: File,
meta: Metadata {
mode: None,
mtime: Some(
2014-11-30T16:03:11+01:00,
),
atime: Some(
2014-11-30T16:03:11+01:00,
),
ctime: Some(
2024-03-12T22:32:55+01:00,
),
uid: None,
gid: None,
user: None,
group: None,
inode: 0,
device_id: 0,
size: 0,
links: 0,
extended_attributes: [],
},
content: Some(
[],
),
subtree: None,
},
Node {
name: "testfile",
node_type: File,
meta: Metadata {
mode: None,
mtime: Some(
2014-08-09T14:14:20+02:00,
),
atime: Some(
2014-08-09T14:14:20+02:00,
),
ctime: Some(
2024-03-12T22:32:55+01:00,
),
uid: None,
gid: None,
user: None,
group: None,
inode: 0,
device_id: 0,
size: 21,
links: 0,
extended_attributes: [],
},
content: Some(
[
649b8b471e7d7bc175eec758a7006ac693c434c8297c07db15286788c837154a,
],
),
subtree: None,
},
Node {
name: "testfile-hardlink",
node_type: File,
meta: Metadata {
mode: None,
mtime: Some(
2014-08-09T14:14:20+02:00,
),
atime: Some(
2014-08-09T14:14:20+02:00,
),
ctime: Some(
2024-03-12T22:32:55+01:00,
),
uid: None,
gid: None,
user: None,
group: None,
inode: 0,
device_id: 0,
size: 21,
links: 0,
extended_attributes: [],
},
content: Some(
[
649b8b471e7d7bc175eec758a7006ac693c434c8297c07db15286788c837154a,
],
),
subtree: None,
},
Node {
name: "testfile-symlink",
node_type: Symlink {
linktarget: "testfile",
linktarget_raw: None,
},
meta: Metadata {
mode: None,
mtime: Some(
2024-03-12T22:32:55.218816+01:00,
),
atime: Some(
2024-03-12T22:32:55.218816+01:00,
),
ctime: Some(
2024-03-12T22:32:55.218816+01:00,
),
uid: None,
gid: None,
user: None,
group: None,
inode: 0,
device_id: 0,
size: 0,
links: 0,
extended_attributes: [],
},
content: None,
subtree: None,
},
],
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/core/tests/integration.rs
expression: TestSummary(&first_backup)
expression: TestSummary(&first_snapshot)
---
TestSnap {
hostname: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TestSnap {
files_changed: 0,
files_unmodified: 73,
total_files_processed: 73,
total_bytes_processed: 1125682,
total_bytes_processed: 1125674,
dirs_new: 0,
dirs_changed: 0,
dirs_unmodified: 6,
Expand Down

0 comments on commit 674ba06

Please sign in to comment.