mirror of
https://github.com/octoleo/restic.git
synced 2024-11-29 16:23:59 +00:00
Add test for incremental backup
This commit is contained in:
parent
7b54c21726
commit
6d5f1c0197
@ -143,11 +143,11 @@ func BenchmarkArchiveDirectory(b *testing.B) {
|
|||||||
b.Logf("snapshot archived as %v", id)
|
b.Logf("snapshot archived as %v", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func snapshot(t testing.TB, server restic.Server, path string) *restic.Snapshot {
|
func snapshot(t testing.TB, server restic.Server, path string, parent backend.ID) *restic.Snapshot {
|
||||||
arch, err := restic.NewArchiver(server)
|
arch, err := restic.NewArchiver(server)
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
ok(t, arch.Preload())
|
ok(t, arch.Preload())
|
||||||
sn, _, err := arch.Snapshot(nil, []string{path}, nil)
|
sn, _, err := arch.Snapshot(nil, []string{path}, parent)
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
return sn
|
return sn
|
||||||
}
|
}
|
||||||
@ -176,25 +176,39 @@ func archiveWithPreload(t testing.TB) {
|
|||||||
server := restic.NewServerWithKey(be, key)
|
server := restic.NewServerWithKey(be, key)
|
||||||
|
|
||||||
// archive a few files
|
// archive a few files
|
||||||
sn := snapshot(t, server, *benchArchiveDirectory)
|
sn := snapshot(t, server, *benchArchiveDirectory, nil)
|
||||||
t.Logf("archived snapshot %v", sn.ID())
|
t.Logf("archived snapshot %v", sn.ID().Str())
|
||||||
|
|
||||||
// get archive stats
|
// get archive stats
|
||||||
blobsBefore := countBlobs(t, server)
|
blobsBefore := countBlobs(t, server)
|
||||||
t.Logf("found %v blobs", blobsBefore)
|
t.Logf("found %v blobs", blobsBefore)
|
||||||
|
|
||||||
// archive the same files again
|
// archive the same files again, without parent snapshot
|
||||||
sn2 := snapshot(t, server, *benchArchiveDirectory)
|
sn2 := snapshot(t, server, *benchArchiveDirectory, nil)
|
||||||
t.Logf("archived snapshot %v", sn2.ID())
|
t.Logf("archived snapshot %v", sn2.ID().Str())
|
||||||
|
|
||||||
// get archive stats
|
// get archive stats
|
||||||
blobsAfter := countBlobs(t, server)
|
blobsAfter2 := countBlobs(t, server)
|
||||||
t.Logf("found %v blobs", blobsAfter)
|
t.Logf("found %v blobs", blobsAfter2)
|
||||||
|
|
||||||
// if there are more than 50% more blobs, something is wrong
|
// if there are more than 50% more blobs, something is wrong
|
||||||
if blobsAfter > (blobsBefore + blobsBefore/2) {
|
if blobsAfter2 > (blobsBefore + blobsBefore/2) {
|
||||||
t.Fatalf("TestArchiverPreload: too many blobs in repository: before %d, after %d, threshhold %d",
|
t.Fatalf("TestArchiverPreload: too many blobs in repository: before %d, after %d, threshhold %d",
|
||||||
blobsBefore, blobsAfter, (blobsBefore + blobsBefore/2))
|
blobsBefore, blobsAfter2, (blobsBefore + blobsBefore/2))
|
||||||
|
}
|
||||||
|
|
||||||
|
// archive the same files again, with a parent snapshot
|
||||||
|
sn3 := snapshot(t, server, *benchArchiveDirectory, sn2.ID())
|
||||||
|
t.Logf("archived snapshot %v, parent %v", sn3.ID().Str(), sn2.ID().Str())
|
||||||
|
|
||||||
|
// get archive stats
|
||||||
|
blobsAfter3 := countBlobs(t, server)
|
||||||
|
t.Logf("found %v blobs", blobsAfter3)
|
||||||
|
|
||||||
|
// if there are more than 50% more blobs, something is wrong
|
||||||
|
if blobsAfter3 > (blobsBefore + blobsBefore/2) {
|
||||||
|
t.Fatalf("TestArchiverPreload: too many blobs in repository: before %d, after %d, threshhold %d",
|
||||||
|
blobsBefore, blobsAfter3, (blobsBefore + blobsBefore/2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ func TestServerStats(t *testing.T) {
|
|||||||
server := restic.NewServerWithKey(be, key)
|
server := restic.NewServerWithKey(be, key)
|
||||||
|
|
||||||
// archive a few files
|
// archive a few files
|
||||||
sn := snapshot(t, server, *benchArchiveDirectory)
|
sn := snapshot(t, server, *benchArchiveDirectory, nil)
|
||||||
t.Logf("archived snapshot %v", sn.ID())
|
t.Logf("archived snapshot %v", sn.ID())
|
||||||
|
|
||||||
stats, err := server.Stats()
|
stats, err := server.Stats()
|
||||||
@ -154,7 +154,7 @@ func TestLoadJSONID(t *testing.T) {
|
|||||||
server := restic.NewServerWithKey(be, key)
|
server := restic.NewServerWithKey(be, key)
|
||||||
|
|
||||||
// archive a few files
|
// archive a few files
|
||||||
sn := snapshot(t, server, *benchArchiveDirectory)
|
sn := snapshot(t, server, *benchArchiveDirectory, nil)
|
||||||
t.Logf("archived snapshot %v", sn.ID())
|
t.Logf("archived snapshot %v", sn.ID())
|
||||||
|
|
||||||
// benchmark loading first tree
|
// benchmark loading first tree
|
||||||
@ -181,7 +181,7 @@ func BenchmarkLoadJSONID(t *testing.B) {
|
|||||||
server := restic.NewServerWithKey(be, key)
|
server := restic.NewServerWithKey(be, key)
|
||||||
|
|
||||||
// archive a few files
|
// archive a few files
|
||||||
sn := snapshot(t, server, *benchArchiveDirectory)
|
sn := snapshot(t, server, *benchArchiveDirectory, nil)
|
||||||
t.Logf("archived snapshot %v", sn.ID())
|
t.Logf("archived snapshot %v", sn.ID())
|
||||||
|
|
||||||
// benchmark loading first tree
|
// benchmark loading first tree
|
||||||
|
Loading…
Reference in New Issue
Block a user