Page MenuHomeMiraheze
Paste P500

rename without clusters for debug

Authored by Reception123 on Jan 21 2024, 14:52.
Referenced Files
F2707763: rename without clusters for debug
Jan 21 2024, 17:29
F2707735: Strange mysql output for rename
Jan 21 2024, 14:58
F2707733: Strange mysql output for rename
Jan 21 2024, 14:52
import subprocess
import sys
import argparse
from typing import Optional, TypedDict
class DbClusterMap(TypedDict):
c1: str
c2: str
c3: str
c4: str
c5: str
# Define the mapping of db clusters to db names
db_clusters: DbClusterMap = {
'c1': 'db131',
'c2': 'db101',
'c3': 'db142',
'c4': 'db121',
'c5': 'db131',
def generate_salt_command(cluster: str, command: str) -> str:
return f'salt-ssh -E "{cluster}" \'{command}\''
def execute_salt_command(salt_command: str) -> Optional[subprocess.CompletedProcess]:
response = input(f'EXECUTE (type c(continue), s(kip), a(bort): {salt_command}')
if response in ['c', 'continue']:
return, shell=True)
if response in ['s', 'skip']:
return None
sys.exit(1) # noqa: R503
def get_db_cluster(oldwiki_db: str, oldwikicluster: str) -> str:
return oldwikicluster # Use user-provided oldwikicluster
def rename_wiki(oldwiki_db: str, newwiki_db: str, oldwikicluster: str) -> None:
# Step 1: Get the db cluster for the old wiki dbname
oldwiki_cluster = get_db_cluster(oldwiki_db, oldwikicluster)
oldwiki_cluster = get_db_cluster(oldwiki_db, oldwikicluster)
except KeyError:
print(f'Error: Unable to determine the db cluster for {oldwiki_db}')
# Step 2: Execute SQL commands for rename
execute_salt_command(salt_command=generate_salt_command(oldwiki_cluster, f'sudo -i mysqldump {oldwiki_db} > /home/reception/{oldwiki_db}.sql'))
execute_salt_command(salt_command=generate_salt_command(oldwiki_cluster, f'sudo -i mysql -e "CREATE DATABASE {newwiki_db}"'))
execute_salt_command(salt_command=generate_salt_command(oldwiki_cluster, f'sudo -i mysql -e "USE {newwiki_db}; SOURCE /home/reception/{oldwiki_db}.sql;"'))
# Step 3: Execute MediaWiki rename script
execute_salt_command(salt_command=generate_salt_command('mwtask141', f'sudo -u www-data php /srv/mediawiki/1.40/extensions/CreateWiki/maintenance/renameWiki.php --wiki=loginwiki --rename {oldwiki_db} {newwiki_db} Reception123'))
execute_salt_command(salt_command=generate_salt_command('mwtask141', f'/usr/local/bin/logsalmsg "Renamed {oldwiki_db} to {newwiki_db} using"'))
def main() -> None:
parser = argparse.ArgumentParser(description='Executes the commands needed to rename wikis')
parser.add_argument('--oldwiki', required=True, help='Old wiki database name')
parser.add_argument('--newwiki', required=True, help='New wiki database name')
parser.add_argument('--oldwikicluster', required=True, help='Old wiki cluster name')
args = parser.parse_args()
rename_wiki(args.oldwiki, args.newwiki, args.oldwikicluster)
if __name__ == '__main__':

Event Timeline

Reception123 changed the title of this paste from Strange mysql output for rename to rename without clusters for debug.Jan 21 2024, 17:29
Reception123 edited the content of this paste. (Show Details)