add undeploy and run-backup flag

This commit is contained in:
Moritz 2024-03-20 12:40:04 +01:00
parent 9b5c3857fb
commit 02926f92fe
1 changed files with 12 additions and 7 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('kaputt.cloud', '/var/lib/docker/', 'kollektiv-02.local-it.cloud', '/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)
@ -60,7 +65,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, 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 --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