From cbd29a968c199221b796e8d38acac5c2ef952d53 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Thu, 22 Oct 2020 20:39:25 +0200 Subject: [PATCH] Perform a full dump before upgrading MariaDB --- install | 2 +- setup.py | 2 +- wo/cli/plugins/stack_migrate.py | 2 +- wo/cli/plugins/stack_pref.py | 9 ++++-- wo/cli/plugins/stack_upgrade.py | 2 +- wo/core/mysql.py | 56 +++++++++++++++++++++++---------- wo/core/variables.py | 4 +-- 7 files changed, 52 insertions(+), 25 deletions(-) diff --git a/install b/install index ac684ef..8cbe6b8 100755 --- a/install +++ b/install @@ -9,7 +9,7 @@ # ------------------------------------------------------------------------- # wget -qO wo wops.cc && sudo -E bash wo # ------------------------------------------------------------------------- -# Version 3.12.4 - 2020-10-14 +# Version 3.13.0 - 2020-10-22 # ------------------------------------------------------------------------- # CONTENTS diff --git a/setup.py b/setup.py index d60768b..d437072 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ if os.geteuid() == 0: os.makedirs('/var/lib/wo/tmp/') setup(name='wordops', - version='3.12.4', + version='3.13.0', description='An essential toolset that eases server administration', long_description=LONG, long_description_content_type='text/markdown', diff --git a/wo/cli/plugins/stack_migrate.py b/wo/cli/plugins/stack_migrate.py index 205714e..3740a0a 100644 --- a/wo/cli/plugins/stack_migrate.py +++ b/wo/cli/plugins/stack_migrate.py @@ -26,7 +26,7 @@ class WOStackMigrateController(CementBaseController): @expose(hide=True) def migrate_mariadb(self): # Backup all database - WOMysql.backupAll(self) + WOMysql.backupAll(self, fulldump=True) if not WOVar.wo_distro == 'raspbian': if (not WOVar.wo_platform_codename == 'jessie'): diff --git a/wo/cli/plugins/stack_pref.py b/wo/cli/plugins/stack_pref.py index 0cec9fd..a2de59c 100644 --- a/wo/cli/plugins/stack_pref.py +++ b/wo/cli/plugins/stack_pref.py @@ -964,7 +964,9 @@ def post_pref(self, apt_packages, packages, upgrade=False): '/etc/mysql/conf.d/my.cnf') except CommandExecutionError: Log.error(self, "Unable to set MySQL password") - Log.info(self, "Tuning MariaDB configuration") + WOGit.add(self, ["/etc/mysql"], + msg="Adding MySQL into Git") + Log.wait(self, "Tuning MariaDB configuration") if not os.path.isfile("/etc/mysql/my.cnf.default-pkg"): WOFileUtils.copyfile(self, "/etc/mysql/my.cnf", "/etc/mysql/my.cnf.default-pkg") @@ -1013,15 +1015,16 @@ def post_pref(self, apt_packages, packages, upgrade=False): 'mariadb.service.d/limits.conf', '[Service]\nLimitNOFILE=500000') WOShellExec.cmd_exec(self, 'systemctl daemon-reload') + Log.valide(self, "Tuning MySQL configuration") # set innodb_buffer_pool_instances depending # on the amount of RAM - WOService.stop_service(self, 'mysql') + WOService.restart_service(self, 'mysql') + # WOFileUtils.mvfile(self, '/var/lib/mysql/ib_logfile0', # '/var/lib/mysql/ib_logfile0.bak') # WOFileUtils.mvfile(self, '/var/lib/mysql/ib_logfile1', # '/var/lib/mysql/ib_logfile1.bak') - WOService.start_service(self, 'mysql') WOCron.setcron_weekly(self, 'mysqlcheck -Aos --auto-repair ' '> /dev/null 2>&1', diff --git a/wo/cli/plugins/stack_upgrade.py b/wo/cli/plugins/stack_upgrade.py index 7ac60e4..ea4cd8b 100644 --- a/wo/cli/plugins/stack_upgrade.py +++ b/wo/cli/plugins/stack_upgrade.py @@ -315,7 +315,7 @@ class WOStackUpgradeController(CementBaseController): # mariadb upgrade if ("mariadb-server" in apt_packages and mariadbmajorupgrade is True): - WOMysql.backupAll(self) + WOMysql.backupAll(self, fulldump=True) WOAptGet.remove(self, ["mariadb-server"]) # upgrade packages WOAptGet.install(self, apt_packages) diff --git a/wo/core/mysql.py b/wo/core/mysql.py index d9af2ff..cdab230 100644 --- a/wo/core/mysql.py +++ b/wo/core/mysql.py @@ -88,7 +88,7 @@ class WOMysql(): finally: connection.close() - def backupAll(self): + def backupAll(self, fulldump=False): import subprocess try: Log.info(self, "Backing up database at location: " @@ -98,24 +98,47 @@ class WOMysql(): Log.debug(self, 'Creating directory' '/var/lib/wo-backup/mysql') os.makedirs('/var/lib/wo-backup/mysql') - - db = subprocess.check_output(["/usr/bin/mysql " - "-Bse \'show databases\'"], - universal_newlines=True, - shell=True).split('\n') - for dbs in db: - if dbs == "": - continue - Log.info(self, "Backing up {0} database".format(dbs)) + if not fulldump: + db = subprocess.check_output( + ["/usr/bin/mysql " + "-Bse \'show databases\'"], + universal_newlines=True, + shell=True).split('\n') + for dbs in db: + if dbs == "": + continue + Log.info(self, "Backing up {0} database".format(dbs)) + p1 = subprocess.Popen( + "/usr/bin/mysqldump {0} --max_allowed_packet=1024M " + "--single-transaction ".format(dbs), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True) + p2 = subprocess.Popen( + "/usr/bin/zstd -T0 -c > " + "/var/lib/wo-backup/mysql/{0}{1}.sql.zst" + .format(dbs, WOVar.wo_date), + stdin=p1.stdout, shell=True) + # Allow p1 to receive a SIGPIPE if p2 exits + p1.stdout.close() + output = p1.stderr.read() + p1.wait() + if p1.returncode == 0: + Log.debug(self, "done") + else: + Log.error(self, output.decode("utf-8")) + else: + Log.info(self, "Backing up all databases") p1 = subprocess.Popen( - "/usr/bin/mysqldump {0} --max_allowed_packet=1024M " - "--single-transaction ".format(dbs), - stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + "/usr/bin/mysqldump --all-databases " + "--max_allowed_packet=1024M " + "--single-transaction --events", + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True) p2 = subprocess.Popen( "/usr/bin/zstd -T0 -c > " - "/var/lib/wo-backup/mysql/{0}{1}.sql.zst" - .format(dbs, WOVar.wo_date), stdin=p1.stdout, shell=True) - # Allow p1 to receive a SIGPIPE if p2 exits + "/var/lib/wo-backup/mysql/fulldump-{0}.sql.zst" + .format(WOVar.wo_date), + stdin=p1.stdout, shell=True) p1.stdout.close() output = p1.stderr.read() p1.wait() @@ -123,6 +146,7 @@ class WOMysql(): Log.debug(self, "done") else: Log.error(self, output.decode("utf-8")) + except Exception as e: Log.error(self, "Error: process exited with status %s" % e) diff --git a/wo/core/variables.py b/wo/core/variables.py index 879929e..6af68de 100644 --- a/wo/core/variables.py +++ b/wo/core/variables.py @@ -14,7 +14,7 @@ class WOVar(): """Intialization of core variables""" # WordOps version - wo_version = "3.12.4" + wo_version = "3.13.0" # WordOps packages versions wo_wp_cli = "2.4.0" wo_adminer = "4.7.5" @@ -83,7 +83,7 @@ class WOVar(): while not match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", wo_email): print("Whoops, seems like you made a typo - " - "the e-mailaddress is invalid...") + "the e-mail address is invalid...") wo_email = input("Enter your email: ") git.config("--global", "user.name", "{0}".format(wo_user))