Skip to content
Snippets Groups Projects
Commit 26f112fa authored by Gary Ruben's avatar Gary Ruben
Browse files

Changes to ignore empty nodes and tarring single files.

parent 711a751c
No related branches found
No related tags found
No related merge requests found
Pipeline #6908 failed
......@@ -51,18 +51,38 @@ def tar_and_send_directory(node):
e.g. /home/grub0002/bapcxi/vault/imbl2018
"""
if node.src == SRC_PATH:
filename = os.path.basename(node.src)
# Check if there are any files in the node
with Connection(REMOTE_LOGIN) as c:
files = c.run(f'cd {node.src}; find -type f -maxdepth 1')
files = files.stdout.strip()
count = files.count('/')
if count == 0:
# No files at this node, just return
return
elif count == 1:
# Only one file. No need to tar. Just copy unchanged.
os.system(
f"ssh {REMOTE_LOGIN} 'cd {node.src};"
f"find -type f -maxdepth 1 | cpio -o' |"
f"cat > {node.dest}/{files}"
)
os.chmod(f'{node.dest}/{files}', 0o550)
print(f'transfer {node.src} -> {node.dest}')
else:
filename = node.src.replace(SRC_PATH+'/', '').replace('/', '_')
os.system(
f"ssh {REMOTE_LOGIN} 'cd {node.src};"
f"find -type f -maxdepth 1 -print0 | cpio -o -H ustar -0' |"
f"cat > {node.dest}/{filename}.tar"
)
os.chmod(f'{node.dest}/{filename}.tar', 0o550)
print(f'transfer {node.src} -> {node.dest}')
# More than one file. Transfer all files to a tarball.
if node.src == SRC_PATH:
filename = os.path.basename(node.src)
else:
filename = node.src.replace(SRC_PATH+'/', '').replace('/', '_')
os.system(
f"ssh {REMOTE_LOGIN} 'cd {node.src};"
f"find -type f -maxdepth 1 -print0 | cpio -o -H ustar -0' |"
f"cat > {node.dest}/{filename}.tar"
)
os.chmod(f'{node.dest}/{filename}.tar', 0o550)
print(f'transfer {node.src} -> {node.dest}')
if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment