-
Notifications
You must be signed in to change notification settings - Fork 29
test and fixes for rsync_tmbackup importer #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,6 @@ def test_borg_import(tmpdir, monkeypatch): | |
|
|
||
| # Create archives in the source repository | ||
| subprocess.check_call(["borg", "create", f"{source_repo}::archive1", "."], cwd=str(archive1_data)) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this PR is not about test_borg, so you should revert all changes to that file. |
||
| subprocess.check_call(["borg", "create", f"{source_repo}::archive2", "."], cwd=str(archive2_data)) | ||
|
|
||
| # Initialize the target repository | ||
|
|
@@ -49,7 +48,6 @@ def test_borg_import(tmpdir, monkeypatch): | |
| extract_dir2 = tmpdir.mkdir("extract2") | ||
|
|
||
| subprocess.check_call(["borg", "extract", f"{target_repo}::archive1"], cwd=str(extract_dir1)) | ||
|
|
||
| subprocess.check_call(["borg", "extract", f"{target_repo}::archive2"], cwd=str(extract_dir2)) | ||
|
|
||
| # Verify the contents of the extracted archives | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def test_rsync_tmbackup_import(tmpdir, monkeypatch): | ||
| """Test importing rsync-time-backup style snapshots into a borg repo.""" | ||
| src = Path(str(tmpdir.mkdir("tmbackup"))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is that Path(str(...)) needed? |
||
|
|
||
| # backup.marker is required by rsync-time-backup | ||
| (src / "backup.marker").touch() | ||
|
|
||
| # two timestamped snapshot directories | ||
| snap1 = src / "2023-01-01-120000" | ||
| snap1.mkdir() | ||
| (snap1 / "file1.txt").write_text("This is file 1 in snap1") | ||
|
|
||
| snap2 = src / "2023-01-02-120000" | ||
| snap2.mkdir() | ||
| (snap2 / "file1.txt").write_text("This is file 1 in snap2") | ||
|
|
||
| target_repo = Path(str(tmpdir.mkdir("target_repo"))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
|
|
||
| # Initialize the target repository | ||
| subprocess.check_call(["borg", "init", "--encryption=none", str(target_repo)]) | ||
|
|
||
| # Run the importer | ||
| monkeypatch.setattr( | ||
| "sys.argv", ["borg-import", "rsync_tmbackup", "--prefix", "backup-", str(src), str(target_repo)] | ||
| ) | ||
|
|
||
| from borg_import.main import main | ||
|
|
||
| main() | ||
|
|
||
| # Verify archives were created | ||
| output = subprocess.check_output(["borg", "list", "--short", str(target_repo)]).decode() | ||
| archives = output.splitlines() | ||
|
|
||
| assert len(archives) == 2 | ||
| assert any("2023-01-01" in a for a in archives) | ||
| assert any("2023-01-02" in a for a in archives) | ||
|
Comment on lines
+40
to
+41
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why so complicated? archives is a list of str, so you can just assert "2023-01-01" in archives. |
||
|
|
||
| # Extract and verify file contents | ||
| extract_dir = Path(str(tmpdir.mkdir("extracted"))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
| first_archive = f"{target_repo}::{archives[0]}" | ||
| subprocess.check_call(["borg", "extract", first_archive], cwd=str(extract_dir)) | ||
|
|
||
| restored = extract_dir / "file1.txt" | ||
| assert restored.exists() | ||
| assert restored.read_text() == "This is file 1 in snap1" | ||
Uh oh!
There was an error while loading. Please reload this page.