diff --git a/src/p1st/btrfs_receive_chunks_active.py b/src/p1st/btrfs_receive_chunks_active.py index 1d89904..385316b 100644 --- a/src/p1st/btrfs_receive_chunks_active.py +++ b/src/p1st/btrfs_receive_chunks_active.py @@ -11,6 +11,8 @@ from p1st.repeat import repeat_until_successful def main(): + + args = parse_args() # ssh_source: str = args.ssh_source diff --git a/src/p1st/exec_consume_chunks.py b/src/p1st/exec_consume_chunks.py index bcc0d22..dab959b 100644 --- a/src/p1st/exec_consume_chunks.py +++ b/src/p1st/exec_consume_chunks.py @@ -1,12 +1,16 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import datetime import subprocess import sys import threading +import time from pathlib import Path from queue import Queue from typing import Callable, IO, AnyStr +from p1st.data_units import DataUnitConverter + def execute_consume_chunks(command: list[str], handle_chunks: Callable[[Queue.put], None], @@ -56,11 +60,23 @@ def execute_consume_chunks(command: list[str], def _stdin_worker(queue_get: Queue.get, binary_stdin: IO[AnyStr], ): + start_time = time.time() + transferred_bytes = 0 + while True: chunk_path, last_chunk = queue_get() chunk = _read_chunk(chunk_path) binary_stdin.write(chunk) # binary_stdin.flush() # TODO: is this required? + + current_time = time.time() + elapsed_time = current_time - start_time + transferred_bytes += len(chunk) + bytes_per_second = round(transferred_bytes / elapsed_time) + print(f'Elapsed time: {datetime.timedelta(seconds=elapsed_time)}\n' + f'Transferred: {DataUnitConverter.to_unit_auto_str(transferred_bytes)}\n' + f'Speed: {DataUnitConverter.to_unit_auto_str(bytes_per_second)}/s') + if last_chunk: break diff --git a/src/p1st/test.py b/src/p1st/test.py index 6d6f502..12bf5c6 100644 --- a/src/p1st/test.py +++ b/src/p1st/test.py @@ -21,7 +21,8 @@ def test(): # test10() # test11() # test12() - test13() + # test13() + test14() def test1(): @@ -182,6 +183,17 @@ def test13(): print(f'odroid: sudo btrfs-receive-chunks-active {ssh_source} {source_chunk_dir} {target_path}') +def test14(): + ssh_source = 'rootnas' + source_path = '/mnt/data/snap/cloud.privacy1st.de/20221015T1432_u' + source_chunk_dir = '/mnt/data/btrfs-transfer-chunks' + + target_path = '/mnt/backup/snap/cloud.privacy1st.de/20221015T1432_u' + + print(f'nas: sudo btrfs-send-chunks-passive --chunk-dir={source_chunk_dir} {source_path}') + print(f'odroid: sudo btrfs-receive-chunks-active {ssh_source} {source_chunk_dir} {target_path}') + + def _init(test_number: int): print(f"TEST {test_number}") test_dir = Path('test')