forked from moritz/migrabrator
Fix rsync command
This commit is contained in:
parent
d158e7721b
commit
d3c2d48ef1
@ -39,7 +39,7 @@ def backup(app):
|
||||
def copy_files_between_servers(source_server, source_dir, destination_server, destination_dir):
|
||||
# Generate temporary SSH key pair
|
||||
ssh_key_pair_dir = tempfile.mkdtemp()
|
||||
ssh_key_id = ssh_key_pair_dir.split('/')[2]
|
||||
ssh_key_id = 'migrabrator_key'
|
||||
private_key_path = os.path.join(ssh_key_pair_dir, 'id_ed25519')
|
||||
public_key_path = os.path.join(ssh_key_pair_dir, 'id_ed25519.pub')
|
||||
subprocess.run(['ssh-keygen', '-t', 'ed25519', '-N', '',
|
||||
@ -55,7 +55,7 @@ def copy_files_between_servers(source_server, source_dir, destination_server, de
|
||||
subprocess.run(['ssh-copy-id', '-i', public_key_path,
|
||||
destination_server], check=True)
|
||||
# Run rsync over SSH on the source server to copy files to the destination server
|
||||
source_rsync_cmd = f'rsync -avz -e "ssh -i {source_key_file} -o StrictHostKeyChecking=accept-new" {source_dir} {destination_server}:{destination_dir}'
|
||||
source_rsync_cmd = f'rsync -az -e "ssh -i {source_key_file} -o StrictHostKeyChecking=accept-new" {source_dir} {destination_server}:{destination_dir}'
|
||||
run_ssh(source_server, source_rsync_cmd)
|
||||
# Remove the SSH key pair from the source server
|
||||
run_ssh(source_server, f'rm -r {source_key_dir}')
|
||||
@ -85,7 +85,7 @@ def copy_volumes(source_app, target_server=False, target_domain=False, move=Fals
|
||||
cmd = 'mv'
|
||||
elif target_domain:
|
||||
server = source_server
|
||||
cmd = 'cp -r'
|
||||
cmd = 'rsync -a --delete'
|
||||
if move:
|
||||
cmd = 'mv'
|
||||
if target_domain:
|
||||
@ -95,10 +95,10 @@ def copy_volumes(source_app, target_server=False, target_domain=False, move=Fals
|
||||
return
|
||||
target_service = target_domain.replace(".", "_")
|
||||
for old_path in paths:
|
||||
container = old_path.split('_')[-1]
|
||||
new_path = f'{target_dir}/{target_service}_{container}'
|
||||
print(f'{cmd} {old_path} {new_path}')
|
||||
run_ssh(server, f'{cmd} {old_path} {new_path}')
|
||||
new_dir = Path(old_path).name.replace(source_service, target_service)
|
||||
new_path = f'{target_dir}/{new_dir}'
|
||||
print(f'{cmd} {old_path}/ {new_path}')
|
||||
run_ssh(server, f'{cmd} {old_path}/ {new_path}')
|
||||
|
||||
|
||||
def copy_configs(source_app, target_server=False, target_domain=False):
|
||||
@ -168,9 +168,10 @@ def get_secrets(source_app):
|
||||
subprocess.run(['abra', 'app', 'run', backupbot, 'app', '--', 'backup', '-h',
|
||||
source_app, 'download', '--secrets'])
|
||||
output = subprocess.run(['abra', 'app', 'cp', backupbot, f"app:/tmp/backup.tar.gz", "/tmp"])
|
||||
if output.returncode:
|
||||
logging.error(f"Could not dump secrets for {source_app}")
|
||||
exit()
|
||||
# Todo: https://git.coopcloud.tech/coop-cloud/organising/issues/525
|
||||
# if output.returncode:
|
||||
# logging.error(f"Could not dump secrets for {source_app}")
|
||||
# exit()
|
||||
with tarfile.open('/tmp/backup.tar.gz') as tar:
|
||||
source_service = source_app.replace(".", "_")
|
||||
file = tar.extractfile(f"{source_service}.json")
|
||||
|
Loading…
x
Reference in New Issue
Block a user