def load_parser_origin(parser): # check origin output.message(output.get_subject().ORIGIN, 'Checking database configuration', True) if mode.is_origin_remote(): connect.load_ssh_client_origin() parser.check_remote_configuration(mode.get_clients().ORIGIN) else: parser.check_local_configuration(mode.get_clients().ORIGIN)
def load_parser_target(parser): # check target output.message(output.get_subject().TARGET, 'Checking database configuration', True) if mode.is_target_remote(): connect.load_ssh_client_target() parser.check_remote_configuration(mode.get_clients().TARGET) else: parser.check_local_configuration(mode.get_clients().TARGET)
def check_local_configuration(client): if os.path.isfile(system.config['host'][client]['path']) == False: sys.exit( output.message(output.get_subject().ERROR, 'Local database configuration not found', False)) system.config['db'] = {} _db_credentials = check_output( helper.get_command(client, 'grep') + ' -v "^#" ' + system.config['host'][client]['path'] + ' | ' + helper.get_command(client, 'grep') + ' DATABASE_URL', stderr=subprocess.STDOUT, shell=True) _db_config = parse_database_credentials(_db_credentials) if system.option['verbose']: if client == mode.get_clients().TARGET: _subject = output.get_subject().TARGET else: _subject = output.get_subject().ORIGIN output.message( _subject, output.get_bcolors().BLACK + helper.get_command(client, 'grep') + ' -v "^#" ' + system.config['host'][client]['path'] + ' | ' + helper.get_command(client, 'grep') + ' DATABASE_URL' + output.get_bcolors().ENDC, True) system.config['db'][client] = _db_config
def prepare_target_database_dump(): output.message(output.get_subject().TARGET, 'Extracting database dump', True) mode.run_command( helper.get_command('target', 'tar') + ' xzf ' + helper.get_target_dump_dir() + origin_database_dump_file_name + '.tar.gz -C ' + helper.get_target_dump_dir(), mode.get_clients().TARGET )
def get_database_configuration(client): system.config['db'] = {} # check framework type _base = '' if 'type' in system.config['host']: if system.config['host']['type'] == 'TYPO3': _base = framework.TYPO3 elif system.config['host']['type'] == 'Symfony': _base = framework.SYMFONY else: sys.exit( output.message(output.get_subject().ERROR, 'Framework type not supported', False)) else: _base = framework.TYPO3 if _base == framework.TYPO3: sys.path.append('./extension') from extension import typo3 _parser = typo3 elif _base == framework.SYMFONY: sys.path.append('./extension') from extension import symfony _parser = symfony if client == mode.get_clients().ORIGIN: output.message(output.get_subject().INFO, 'Sync base: ' + _base, True) load_parser_origin(_parser) else: load_parser_target(_parser)
def check_configuration(): load_pip_modules() get_host_configuration() if not option['use_origin_ssh_key'] and mode.is_origin_remote(): option['ssh_password']['origin'] = get_password( mode.get_clients().ORIGIN) if mode.get_sync_mode() == mode.get_sync_modes().DUMP_REMOTE: option['ssh_password']['target'] = option['ssh_password']['origin'] if not option['use_target_ssh_key'] and mode.is_target_remote( ) and mode.get_sync_mode() != mode.get_sync_modes().DUMP_REMOTE: option['ssh_password']['target'] = get_password( mode.get_clients().TARGET) # first get data configuration for origin client parser.get_database_configuration(mode.get_clients().ORIGIN)
def prepare_origin_database_dump(): output.message( output.get_subject().ORIGIN, 'Compressing database dump', True ) mode.run_command( helper.get_command('origin', 'tar') + ' cfvz ' + helper.get_origin_dump_dir() + origin_database_dump_file_name + '.tar.gz -C ' + helper.get_origin_dump_dir() + ' ' + origin_database_dump_file_name, mode.get_clients().ORIGIN )
def create_origin_database_dump(): generate_database_dump_filename() output.message( output.get_subject().ORIGIN, 'Creating database dump', True ) mode.run_command( helper.get_command('origin', 'mysqldump') + ' ' + generate_mysql_credentials('origin') + ' ' + system.config['db']['origin'][ 'dbname'] + ' ' + generate_ignore_database_tables() + ' > ' + helper.get_origin_dump_dir() + origin_database_dump_file_name, mode.get_clients().ORIGIN ) prepare_origin_database_dump()
def import_database_dump(): if (not system.option['is_same_client']): prepare_target_database_dump() # @ToDo: Enable check_dump feature again # if system.option['check_dump']: # check_target_database_dump() if not system.option['keep_dump'] and not system.option['is_same_client']: output.message( output.get_subject().TARGET, 'Importing database dump', True ) mode.run_command( helper.get_command('target', 'mysql') + ' ' + generate_mysql_credentials('target') + ' ' + system.config['db']['target'][ 'dbname'] + ' < ' + helper.get_target_dump_dir() + origin_database_dump_file_name, mode.get_clients().TARGET )
def remove_target_database_dump(): _file_path = helper.get_target_dump_dir() + database.origin_database_dump_file_name # # Move dump to specified directory # if system.option['keep_dump']: helper.create_local_temporary_data_dir() _keep_dump_path = system.default_local_sync_path + database.origin_database_dump_file_name mode.run_command( helper.get_command('target', 'cp') + ' ' + _file_path + ' ' + _keep_dump_path, mode.get_clients().TARGET ) output.message( output.get_subject().INFO, 'Database dump file is saved to: ' + _keep_dump_path, True ) # # Clean up # if not system.option['is_same_client']: output.message( output.get_subject().TARGET, 'Cleaning up', True ) if mode.is_target_remote(): sftp = ssh_client_target.open_sftp() sftp.remove(_file_path) sftp.remove(_file_path + '.tar.gz') sftp.close() else: if os.path.isfile(_file_path): os.remove(_file_path) if os.path.isfile(_file_path + '.tar.gz'): os.remove(_file_path + '.tar.gz')
def check_target_configuration(): parser.get_database_configuration(mode.get_clients().TARGET)
def client_to_subject(client): if client == mode.get_clients().ORIGIN: return subject.ORIGIN elif client == mode.get_clients().TARGET: return subject.TARGET
def load_ssh_client_target(): global ssh_client_target ssh_client_target = load_ssh_client(mode.get_clients().TARGET)
def load_ssh_client_origin(): global ssh_client_origin ssh_client_origin = load_ssh_client(mode.get_clients().ORIGIN)