mirror of
https://codeberg.org/privacy1st/subprocess-util
synced 2024-12-22 22:06:05 +01:00
cleanup examples
This commit is contained in:
parent
e06409fdce
commit
cbbb4231e8
58
README.md
58
README.md
@ -1,43 +1,29 @@
|
|||||||
# subprocess_util
|
# subprocess-util
|
||||||
|
|
||||||
## Example output
|
## Example to replicate a BTRFS subvolume with an active sending side
|
||||||
|
|
||||||
`btrfs receive` side, actively pulling a snapshot.
|
The sending side "pushes" the BTRFS snapshot to the receiving side. The sender needs password-less SSH access to the receiver.
|
||||||
|
|
||||||
```
|
First, start the receiving side:
|
||||||
[STDOUT] OK
|
|
||||||
Reading chunk /mnt/backup/snap/cloud.privacy1st.de/20221015T1432_u.CHUNK.12212
|
```shell
|
||||||
[STDOUT] OK
|
sudo btrfs-receive-chunks-passive \
|
||||||
Elapsed time: 14 days, 5:38:16.172379
|
/target-snapshot-path/20230213T1809_u/
|
||||||
Transferred: 2.981 TB
|
|
||||||
Speed: 2.542 MB/s
|
|
||||||
Reading chunk /mnt/backup/snap/cloud.privacy1st.de/20221015T1432_u.CHUNK.12213
|
|
||||||
[STDOUT] OK
|
|
||||||
Elapsed time: 14 days, 5:39:54.104637
|
|
||||||
Transferred: 2.982 TB
|
|
||||||
Speed: 2.542 MB/s
|
|
||||||
Reading chunk /mnt/backup/snap/cloud.privacy1st.de/20221015T1432_u.CHUNK.12214
|
|
||||||
[STDOUT] EOF
|
|
||||||
Elapsed time: 14 days, 5:42:02.535829
|
|
||||||
Transferred: 2.982 TB
|
|
||||||
Speed: 2.542 MB/s
|
|
||||||
Reading chunk /mnt/backup/snap/cloud.privacy1st.de/20221015T1432_u.CHUNK.12215
|
|
||||||
Elapsed time: 14 days, 5:42:24.937967
|
|
||||||
Transferred: 2.982 TB
|
|
||||||
Speed: 2.542 MB/s
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`btrfs send` side, passive.
|
Then, start the sending side:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo btrfs-send-chunks-active \
|
||||||
|
/source-snapshot-path/20230213T1809_u/ \
|
||||||
|
ssh-hostname-of-receiving-side \
|
||||||
|
/target-snapshot-path/20230213T1809_u/
|
||||||
```
|
```
|
||||||
Received "b'OK\n'".
|
|
||||||
Handling chunk /mnt/data/btrfs-transfer-chunks/20221015T1432_u.CHUNK.12212
|
See `test16()`.
|
||||||
Saving chunk /mnt/data/btrfs-transfer-chunks/20221015T1432_u.CHUNK.12215
|
|
||||||
Received "b'OK\n'".
|
## Example to replicate a BTRFS subvolume with an active receiving side
|
||||||
Handling chunk /mnt/data/btrfs-transfer-chunks/20221015T1432_u.CHUNK.12213
|
|
||||||
Received "b'OK\n'".
|
The receiving side "pulls" the BTRFS snapshot from the sending side. The receiver needs password-less SSH access to the sender.
|
||||||
Handling chunk /mnt/data/btrfs-transfer-chunks/20221015T1432_u.CHUNK.12214
|
|
||||||
Received "b'OK\n'".
|
See `test17()`.
|
||||||
Handling chunk /mnt/data/btrfs-transfer-chunks/20221015T1432_u.CHUNK.12215
|
|
||||||
Received "b'OK\n'".
|
|
||||||
```
|
|
||||||
|
@ -11,20 +11,17 @@ from subprocess_util.chunked_transfer.active_send.exec_send_chunks_active import
|
|||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
# test1()
|
|
||||||
# test2()
|
|
||||||
# test4()
|
|
||||||
# test8()
|
|
||||||
# test9()
|
|
||||||
# test10()
|
|
||||||
# test11()
|
|
||||||
# test12()
|
|
||||||
# test13()
|
|
||||||
# test14()
|
|
||||||
# test15_recieve()
|
|
||||||
# test15_send()
|
|
||||||
test16()
|
test16()
|
||||||
|
|
||||||
|
|
||||||
|
def _init(test_number: int):
|
||||||
|
print(f"TEST {test_number}")
|
||||||
|
test_dir = Path('test')
|
||||||
|
if test_dir.exists():
|
||||||
|
shutil.rmtree('test')
|
||||||
|
Path('test').mkdir(exist_ok=False)
|
||||||
|
|
||||||
|
|
||||||
def test1():
|
def test1():
|
||||||
_init(1)
|
_init(1)
|
||||||
|
|
||||||
@ -43,41 +40,6 @@ def test2():
|
|||||||
_returncode, _out, _err = execute_print_capture(['ls', '/foo/bar'])
|
_returncode, _out, _err = execute_print_capture(['ls', '/foo/bar'])
|
||||||
|
|
||||||
|
|
||||||
def test8():
|
|
||||||
repo_name = 'subprocess_util'
|
|
||||||
|
|
||||||
child_name = 'test-subvolume'
|
|
||||||
child_dir = '/mnt/backup/test-dir'
|
|
||||||
child_path = f'{child_dir}/{child_name}'
|
|
||||||
target_dir = '/mnt/data/test-dir'
|
|
||||||
target_path = f'{target_dir}/{child_name}'
|
|
||||||
ssh_target = 'rootnas'
|
|
||||||
|
|
||||||
print(f'=== In one shell, connect with "ssh nas" ===')
|
|
||||||
print(f'\tsudo mkdir {target_dir}')
|
|
||||||
print(f'\tcd {repo_name} && make && sudo make clean && cd ..')
|
|
||||||
print()
|
|
||||||
print(f'\tsudo btrfs-receive-chunks {target_path}')
|
|
||||||
print()
|
|
||||||
|
|
||||||
print(f'=== In another shell, connect with "ssh odroid" ===')
|
|
||||||
print(f'\tsudo mkdir {child_dir}')
|
|
||||||
print(f'\tsudo btrfs subvolume create {child_path}.writeable')
|
|
||||||
print(f'\techo foo | sudo tee {child_path}.writeable/bar')
|
|
||||||
print(f'\tsudo btrfs subvolume snapshot -r {child_path}.writeable {child_path}')
|
|
||||||
print(f'\tcd {repo_name} && make && sudo make clean && cd ..')
|
|
||||||
print()
|
|
||||||
print(f'\tsudo btrfs-send-chunks {child_path} {ssh_target} {target_path}')
|
|
||||||
|
|
||||||
|
|
||||||
def test9():
|
|
||||||
child_path = '/mnt/backup/snap/blogger.privacy1st.de/20230104T2255'
|
|
||||||
ssh_target = 'rootnas'
|
|
||||||
target_path = '/mnt/data/test/blogger.privacy1st.de/20230104T2255'
|
|
||||||
print(f'sudo btrfs-receive-chunks {target_path}')
|
|
||||||
print(f'sudo btrfs-send-chunks {child_path} {ssh_target} {target_path}')
|
|
||||||
|
|
||||||
|
|
||||||
def test10():
|
def test10():
|
||||||
_init(10)
|
_init(10)
|
||||||
|
|
||||||
@ -108,69 +70,6 @@ def test10():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test11():
|
|
||||||
repo_name = 'subprocess_util'
|
|
||||||
|
|
||||||
child_name = 'test-subvolume'
|
|
||||||
child_dir = '/mnt/backup/test-dir'
|
|
||||||
child_path = f'{child_dir}/{child_name}'
|
|
||||||
target_dir = '/mnt/data/test-dir'
|
|
||||||
target_path = f'{target_dir}/{child_name}'
|
|
||||||
ssh_target = 'rootnas'
|
|
||||||
|
|
||||||
print(f'=== In one shell, connect with "ssh nas" ===')
|
|
||||||
print(f'\tsudo mkdir {target_dir}')
|
|
||||||
print(f'\tcd {repo_name} && make && sudo make clean && cd ..')
|
|
||||||
print()
|
|
||||||
print(f'\tsudo btrfs-receive-chunks-passive {target_path}')
|
|
||||||
print()
|
|
||||||
|
|
||||||
print(f'=== In another shell, connect with "ssh odroid" ===')
|
|
||||||
print(f'\tsudo mkdir {child_dir}')
|
|
||||||
print(f'\tsudo btrfs subvolume create {child_path}.writeable')
|
|
||||||
print(f'\techo foo | sudo tee {child_path}.writeable/bar')
|
|
||||||
print(f'\tsudo btrfs subvolume snapshot -r {child_path}.writeable {child_path}')
|
|
||||||
print(f'\tcd {repo_name} && make && sudo make clean && cd ..')
|
|
||||||
print()
|
|
||||||
print(f'\tsudo btrfs-send-chunks-active {child_path} {ssh_target} {target_path}')
|
|
||||||
|
|
||||||
|
|
||||||
def test12():
|
|
||||||
child_path = '/mnt/backup/snap/blogger.privacy1st.de/20230104T2255'
|
|
||||||
ssh_target = 'rootnas'
|
|
||||||
target_path = '/mnt/data/test/blogger.privacy1st.de/20230104T2255'
|
|
||||||
target_chunk_path = '/mnt/data/test/chunks'
|
|
||||||
print(f'nas: sudo btrfs-receive-chunks-passive --chunk-dir={target_chunk_path} {target_path}')
|
|
||||||
print(
|
|
||||||
f'odroid: sudo btrfs-send-chunks-active --chunk-dir=/mnt/backup/test/chunks --target-chunk-dir={target_chunk_path} {child_path} {ssh_target} {target_path}')
|
|
||||||
|
|
||||||
|
|
||||||
def test13():
|
|
||||||
ssh_source = 'rootnas'
|
|
||||||
source_path = '/mnt/data/snap/blogger.privacy1st.de/20230104T1622_u'
|
|
||||||
source_chunk_dir = '/mnt/data/test/chunks'
|
|
||||||
|
|
||||||
target_path = '/mnt/backup/test/blogger.privacy1st.de/20230104T1622_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 test14():
|
|
||||||
chunk_size = 256 * 1024 * 1024 # 256MB
|
|
||||||
|
|
||||||
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: [screen] ' +
|
|
||||||
f'sudo btrfs-send-chunks-passive --chunk-size={chunk_size} --chunk-dir={source_chunk_dir} {source_path}')
|
|
||||||
print(f'odroid: [screen] ' +
|
|
||||||
f'sudo btrfs-receive-chunks-active {ssh_source} {source_chunk_dir} {target_path}')
|
|
||||||
|
|
||||||
|
|
||||||
def test15_recieve():
|
def test15_recieve():
|
||||||
"""
|
"""
|
||||||
First start the passive side.
|
First start the passive side.
|
||||||
@ -197,21 +96,32 @@ def test16():
|
|||||||
"""
|
"""
|
||||||
Minimal example to replicate a BTRFS subvolume with an active sending side.
|
Minimal example to replicate a BTRFS subvolume with an active sending side.
|
||||||
"""
|
"""
|
||||||
child_path = '/mnt/backup/snap/blogger.privacy1st.de/20230104T2255'
|
snapshot = 'blogger.privacy1st.de/20230213T1809_u/'
|
||||||
|
|
||||||
|
child_path = '/mnt/backup/snap/' + snapshot
|
||||||
ssh_target = 'rootnas'
|
ssh_target = 'rootnas'
|
||||||
target_path = '/mnt/data/test/blogger.privacy1st.de/20230104T2255'
|
target_path = '/mnt/data/test/' + snapshot
|
||||||
|
|
||||||
print(f'nas: '
|
print(f'nas: '
|
||||||
f'sudo btrfs-receive-chunks-passive {target_path}')
|
f'sudo btrfs-receive-chunks-passive {target_path}')
|
||||||
print(f'odroid: '
|
print(f'pi3bplus: '
|
||||||
f'sudo btrfs-send-chunks-active {child_path} {ssh_target} {target_path}')
|
f'sudo btrfs-send-chunks-active {child_path} {ssh_target} {target_path}')
|
||||||
|
|
||||||
|
|
||||||
def _init(test_number: int):
|
def test17():
|
||||||
print(f"TEST {test_number}")
|
"""
|
||||||
test_dir = Path('test')
|
Minimal example to replicate a BTRFS subvolume with an active receiving side.
|
||||||
if test_dir.exists():
|
"""
|
||||||
shutil.rmtree('test')
|
snapshot = 'blogger.privacy1st.de/20230213T1809_u/'
|
||||||
Path('test').mkdir(exist_ok=False)
|
|
||||||
|
child_path = '/mnt/data/snap/' + snapshot
|
||||||
|
ssh_source = 'rootnas'
|
||||||
|
target_path = '/mnt/backup/test/' + snapshot
|
||||||
|
|
||||||
|
print(f'nas: '
|
||||||
|
f'sudo btrfs-send-chunks-passive {child_path}')
|
||||||
|
print(f'pi3bplus: '
|
||||||
|
f'sudo btrfs-receive-chunks-active --child={child_path} {ssh_source} {target_path}')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user