0
0
Fork 0

Compare commits

...

3 Commits
main ... main

Author SHA1 Message Date
Moritz 34588bc299 use --sparse flag for rsync 2024-04-22 16:47:01 +02:00
Moritz f25103d216 fix server migration 2024-04-22 16:37:26 +02:00
Moritz 02926f92fe add undeploy and run-backup flag 2024-03-20 12:40:04 +01:00
1 changed files with 13 additions and 8 deletions

View File

@ -17,19 +17,24 @@ from pathlib import Path
@click.option('dst_domain', '--dst_domain', '-d')
@click.option('target_server', '--target_server', '-s')
@click.option('move_volumes', '--move-volumes', '-m', is_flag=True)
def main(loglevel, source_app, dst_domain, target_server, move_volumes):
@click.option('undeploy', '--undeploy', '-u', is_flag=True)
@click.option('run_backup', '--run-backup', '-b', is_flag=True)
def main(loglevel, source_app, dst_domain, target_server, move_volumes, undeploy, run_backup):
if loglevel:
numeric_level = getattr(logging, loglevel.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError('Invalid log level: %s' % loglevel)
logging.basicConfig(level=numeric_level)
move_app(source_app, target_server, dst_domain, move_volumes)
#move_app(source_app, target_server, dst_domain, move_volumes, undeploy, run_backup)
#copy_files_between_servers('source.example.com', '/var/lib/docker/', 'target.example.com', '/var/lib/docker')
def move_app(source_app, target_server=False, target_domain=False, move_vols=False):
backup(source_app)
print(abra('app', 'undeploy', '-n', source_app))
sleep(10)
def move_app(source_app, target_server=False, target_domain=False, move_vols=False, undeploy=False, run_backup=False):
if run_backup:
backup(source_app)
if undeploy:
print(abra('app', 'undeploy', '-n', source_app))
sleep(10)
copy_volumes(source_app, target_server, target_domain, move_vols)
copy_configs(source_app, target_server, target_domain)
copy_secrets(source_app, target_domain)
@ -57,10 +62,10 @@ def copy_files_between_servers(source_server, source_dir, destination_server, de
source_key_file = f'{source_key_dir}/id_ed25519'
run_ssh(source_server, f'chmod 600 {source_key_file}')
# Add the public key to the authorized hosts of the destination server
subprocess.run(['ssh-copy-id', '-i', public_key_path,
subprocess.run(['ssh-copy-id', '-f' ,'-i', public_key_path,
destination_server], check=True, capture_output=True)
# Run rsync over SSH on the source server to copy files to the destination server
source_rsync_cmd = f'rsync -az -e "ssh -i {source_key_file} -o StrictHostKeyChecking=accept-new" {source_dir} {destination_server}:{destination_dir}'
source_rsync_cmd = f'rsync -az -S --delete --info=progress2 -e "ssh -i {source_key_file} -o StrictHostKeyChecking=accept-new" {source_dir} {destination_server}:{destination_dir}'
print(source_rsync_cmd)
run_ssh(source_server, source_rsync_cmd)
# Remove the SSH key pair from the source server