Perform a full dump before upgrading MariaDB

This commit is contained in:
VirtuBox
2020-10-22 20:39:25 +02:00
parent e2bfcd326e
commit cbd29a968c
7 changed files with 52 additions and 25 deletions

View File

@@ -9,7 +9,7 @@
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# wget -qO wo wops.cc && sudo -E bash wo # wget -qO wo wops.cc && sudo -E bash wo
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# Version 3.12.4 - 2020-10-14 # Version 3.13.0 - 2020-10-22
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# CONTENTS # CONTENTS

View File

@@ -27,7 +27,7 @@ if os.geteuid() == 0:
os.makedirs('/var/lib/wo/tmp/') os.makedirs('/var/lib/wo/tmp/')
setup(name='wordops', setup(name='wordops',
version='3.12.4', version='3.13.0',
description='An essential toolset that eases server administration', description='An essential toolset that eases server administration',
long_description=LONG, long_description=LONG,
long_description_content_type='text/markdown', long_description_content_type='text/markdown',

View File

@@ -26,7 +26,7 @@ class WOStackMigrateController(CementBaseController):
@expose(hide=True) @expose(hide=True)
def migrate_mariadb(self): def migrate_mariadb(self):
# Backup all database # Backup all database
WOMysql.backupAll(self) WOMysql.backupAll(self, fulldump=True)
if not WOVar.wo_distro == 'raspbian': if not WOVar.wo_distro == 'raspbian':
if (not WOVar.wo_platform_codename == 'jessie'): if (not WOVar.wo_platform_codename == 'jessie'):

View File

@@ -964,7 +964,9 @@ def post_pref(self, apt_packages, packages, upgrade=False):
'/etc/mysql/conf.d/my.cnf') '/etc/mysql/conf.d/my.cnf')
except CommandExecutionError: except CommandExecutionError:
Log.error(self, "Unable to set MySQL password") 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"): if not os.path.isfile("/etc/mysql/my.cnf.default-pkg"):
WOFileUtils.copyfile(self, "/etc/mysql/my.cnf", WOFileUtils.copyfile(self, "/etc/mysql/my.cnf",
"/etc/mysql/my.cnf.default-pkg") "/etc/mysql/my.cnf.default-pkg")
@@ -1013,15 +1015,16 @@ def post_pref(self, apt_packages, packages, upgrade=False):
'mariadb.service.d/limits.conf', 'mariadb.service.d/limits.conf',
'[Service]\nLimitNOFILE=500000') '[Service]\nLimitNOFILE=500000')
WOShellExec.cmd_exec(self, 'systemctl daemon-reload') WOShellExec.cmd_exec(self, 'systemctl daemon-reload')
Log.valide(self, "Tuning MySQL configuration")
# set innodb_buffer_pool_instances depending # set innodb_buffer_pool_instances depending
# on the amount of RAM # on the amount of RAM
WOService.stop_service(self, 'mysql') WOService.restart_service(self, 'mysql')
# WOFileUtils.mvfile(self, '/var/lib/mysql/ib_logfile0', # WOFileUtils.mvfile(self, '/var/lib/mysql/ib_logfile0',
# '/var/lib/mysql/ib_logfile0.bak') # '/var/lib/mysql/ib_logfile0.bak')
# WOFileUtils.mvfile(self, '/var/lib/mysql/ib_logfile1', # WOFileUtils.mvfile(self, '/var/lib/mysql/ib_logfile1',
# '/var/lib/mysql/ib_logfile1.bak') # '/var/lib/mysql/ib_logfile1.bak')
WOService.start_service(self, 'mysql')
WOCron.setcron_weekly(self, 'mysqlcheck -Aos --auto-repair ' WOCron.setcron_weekly(self, 'mysqlcheck -Aos --auto-repair '
'> /dev/null 2>&1', '> /dev/null 2>&1',

View File

@@ -315,7 +315,7 @@ class WOStackUpgradeController(CementBaseController):
# mariadb upgrade # mariadb upgrade
if ("mariadb-server" in apt_packages and if ("mariadb-server" in apt_packages and
mariadbmajorupgrade is True): mariadbmajorupgrade is True):
WOMysql.backupAll(self) WOMysql.backupAll(self, fulldump=True)
WOAptGet.remove(self, ["mariadb-server"]) WOAptGet.remove(self, ["mariadb-server"])
# upgrade packages # upgrade packages
WOAptGet.install(self, apt_packages) WOAptGet.install(self, apt_packages)

View File

@@ -88,7 +88,7 @@ class WOMysql():
finally: finally:
connection.close() connection.close()
def backupAll(self): def backupAll(self, fulldump=False):
import subprocess import subprocess
try: try:
Log.info(self, "Backing up database at location: " Log.info(self, "Backing up database at location: "
@@ -98,24 +98,47 @@ class WOMysql():
Log.debug(self, 'Creating directory' Log.debug(self, 'Creating directory'
'/var/lib/wo-backup/mysql') '/var/lib/wo-backup/mysql')
os.makedirs('/var/lib/wo-backup/mysql') os.makedirs('/var/lib/wo-backup/mysql')
if not fulldump:
db = subprocess.check_output(["/usr/bin/mysql " db = subprocess.check_output(
"-Bse \'show databases\'"], ["/usr/bin/mysql "
universal_newlines=True, "-Bse \'show databases\'"],
shell=True).split('\n') universal_newlines=True,
for dbs in db: shell=True).split('\n')
if dbs == "": for dbs in db:
continue if dbs == "":
Log.info(self, "Backing up {0} database".format(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( p1 = subprocess.Popen(
"/usr/bin/mysqldump {0} --max_allowed_packet=1024M " "/usr/bin/mysqldump --all-databases "
"--single-transaction ".format(dbs), "--max_allowed_packet=1024M "
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) "--single-transaction --events",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
p2 = subprocess.Popen( p2 = subprocess.Popen(
"/usr/bin/zstd -T0 -c > " "/usr/bin/zstd -T0 -c > "
"/var/lib/wo-backup/mysql/{0}{1}.sql.zst" "/var/lib/wo-backup/mysql/fulldump-{0}.sql.zst"
.format(dbs, WOVar.wo_date), stdin=p1.stdout, shell=True) .format(WOVar.wo_date),
# Allow p1 to receive a SIGPIPE if p2 exits stdin=p1.stdout, shell=True)
p1.stdout.close() p1.stdout.close()
output = p1.stderr.read() output = p1.stderr.read()
p1.wait() p1.wait()
@@ -123,6 +146,7 @@ class WOMysql():
Log.debug(self, "done") Log.debug(self, "done")
else: else:
Log.error(self, output.decode("utf-8")) Log.error(self, output.decode("utf-8"))
except Exception as e: except Exception as e:
Log.error(self, "Error: process exited with status %s" Log.error(self, "Error: process exited with status %s"
% e) % e)

View File

@@ -14,7 +14,7 @@ class WOVar():
"""Intialization of core variables""" """Intialization of core variables"""
# WordOps version # WordOps version
wo_version = "3.12.4" wo_version = "3.13.0"
# WordOps packages versions # WordOps packages versions
wo_wp_cli = "2.4.0" wo_wp_cli = "2.4.0"
wo_adminer = "4.7.5" 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]*$", while not match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
wo_email): wo_email):
print("Whoops, seems like you made a typo - " 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: ") wo_email = input("Enter your email: ")
git.config("--global", "user.name", "{0}".format(wo_user)) git.config("--global", "user.name", "{0}".format(wo_user))