Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/borg_import/rsync_tmbackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def get_tmbackup_snapshots(root, prefix):
"""Return metadata for all snapshots discovered in the rsync root directory."""
regex = re.compile(r"(?P<snapshot_date>.+)")

if not Path("backup.marker").exists():
if not (root / "backup.marker").exists():
raise FileNotFoundError("The backup.marker file must exist for rsync-time-backup import")

for path in discover(str(root), 1):
Expand Down
2 changes: 0 additions & 2 deletions src/borg_import/testsuite/test_borg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions src/borg_import/testsuite/test_tmbackup.py
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")))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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")))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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")))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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"
Loading