From f5d1caea889f85196dfc1efe4892560f0b145191 Mon Sep 17 00:00:00 2001 From: Doug Shelley Date: Tue, 19 Jan 2016 20:22:03 +0000 Subject: [PATCH] Fix backup of mysql variants on Centos The switch to XtraBackup 2.3 was causing an issue on RHEL/Centos related to is using the "mysql" user instead of "trove". The fix on Ubuntu was to move the os_admin credentials to ~trove/.my.cnf. While this is a better place to write the credentials anyway (i.e. they shouldn't be stored in server my.cnf) this doesn't solve the whole issue on Centos. This commit changes the XB backup strategy to pass the user/password in on the innobackupex command line. Also, it was noticed that the "socket" option wasn't being specified in the config.template. This is causing some client connections, such as XB to fail connect because it can't locate the socket. Forcing the server/client to write/read the socket from a known location fixes this. Change-Id: Iea941ce60179ef4dc5c403c2fc374cc8eb7d1617 Closes-bug: 1649592 --- api-ref/source/samples/db-list-cfg-defaults-response.json | 3 ++- ...b-get-default-instance-configuration-response-json.txt | 5 +++++ trove/guestagent/strategies/backup/mysql_impl.py | 8 ++++++++ trove/templates/mariadb/config.template | 2 ++ trove/tests/unittests/backup/test_backupagent.py | 3 ++- trove/tests/unittests/guestagent/test_backups.py | 7 +++++-- 6 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 apidocs/src/samples/db-get-default-instance-configuration-response-json.txt diff --git a/api-ref/source/samples/db-list-cfg-defaults-response.json b/api-ref/source/samples/db-list-cfg-defaults-response.json index 58422431f5..c506d3aac2 100644 --- a/api-ref/source/samples/db-list-cfg-defaults-response.json +++ b/api-ref/source/samples/db-list-cfg-defaults-response.json @@ -22,7 +22,8 @@ "open_files_limit": 512, "performance_schema": "ON", "pid_file": "/var/run/mysqld/mysqld.pid", - "port": 3306, + "socket": "/var/run/mysqld/mysqld.sock", + "port": "3306", "query_cache_limit": "1M", "query_cache_size": "8M", "query_cache_type": 1, diff --git a/apidocs/src/samples/db-get-default-instance-configuration-response-json.txt b/apidocs/src/samples/db-get-default-instance-configuration-response-json.txt new file mode 100644 index 0000000000..d8d78fc397 --- /dev/null +++ b/apidocs/src/samples/db-get-default-instance-configuration-response-json.txt @@ -0,0 +1,5 @@ +HTTP/1.1 200 OK +Content-Type: application/json +Content-Length: 1151 +Date: Mon, 18 Mar 2013 19:09:17 GMT + diff --git a/trove/guestagent/strategies/backup/mysql_impl.py b/trove/guestagent/strategies/backup/mysql_impl.py index a9d8b9f272..5d0b9ef3cb 100644 --- a/trove/guestagent/strategies/backup/mysql_impl.py +++ b/trove/guestagent/strategies/backup/mysql_impl.py @@ -49,11 +49,18 @@ class InnoBackupEx(base.BackupRunner): """Implementation of Backup Strategy for InnoBackupEx.""" __strategy_name__ = 'innobackupex' + @property + def user_and_pass(self): + return (' --user=%(user)s --password=%(password)s ' % + {'user': ADMIN_USER_NAME, + 'password': MySqlApp.get_auth_password()}) + @property def cmd(self): cmd = ('sudo innobackupex' ' --stream=xbstream' ' %(extra_opts)s ' + + self.user_and_pass + MySqlApp.get_data_dir() + ' 2>/tmp/innobackupex.log' ) @@ -109,6 +116,7 @@ class InnoBackupExIncremental(InnoBackupEx): ' --incremental' ' --incremental-lsn=%(lsn)s' ' %(extra_opts)s ' + + self.user_and_pass + MySqlApp.get_data_dir() + ' 2>/tmp/innobackupex.log') return cmd + self.zip_cmd + self.encrypt_cmd diff --git a/trove/templates/mariadb/config.template b/trove/templates/mariadb/config.template index 88614bdeaf..8507e0f3dd 100644 --- a/trove/templates/mariadb/config.template +++ b/trove/templates/mariadb/config.template @@ -1,5 +1,6 @@ [client] port = 3306 +socket = /var/run/mysqld/mysqld.sock [mysqld_safe] nice = 0 @@ -13,6 +14,7 @@ basedir = /usr datadir = /var/lib/mysql/data tmpdir = /var/tmp pid_file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock skip-external-locking = 1 key_buffer_size = {{ (50 * flavor['ram']/512)|int }}M max_allowed_packet = {{ (1024 * flavor['ram']/512)|int }}K diff --git a/trove/tests/unittests/backup/test_backupagent.py b/trove/tests/unittests/backup/test_backupagent.py index e0644653a2..936a9cf8fb 100644 --- a/trove/tests/unittests/backup/test_backupagent.py +++ b/trove/tests/unittests/backup/test_backupagent.py @@ -230,7 +230,8 @@ class BackupAgentTest(trove_testtools.TestCase): self.assertIsNotNone(inno_backup_ex.cmd) str_innobackup_cmd = ('sudo innobackupex' ' --stream=xbstream' - ' %(extra_opts)s' + ' %(extra_opts)s ' + ' --user=os_admin --password=123' ' /var/lib/mysql/data 2>/tmp/innobackupex.log' ' | gzip |' ' openssl enc -aes-256-cbc -salt ' diff --git a/trove/tests/unittests/guestagent/test_backups.py b/trove/tests/unittests/guestagent/test_backups.py index 1f4644b189..565fd1ce2c 100644 --- a/trove/tests/unittests/guestagent/test_backups.py +++ b/trove/tests/unittests/guestagent/test_backups.py @@ -77,13 +77,16 @@ ZIP = "gzip" UNZIP = "gzip -d -c" ENCRYPT = "openssl enc -aes-256-cbc -salt -pass pass:default_aes_cbc_key" DECRYPT = "openssl enc -d -aes-256-cbc -salt -pass pass:default_aes_cbc_key" -XTRA_BACKUP_RAW = ("sudo innobackupex --stream=xbstream %(extra_opts)s" +XTRA_BACKUP_RAW = ("sudo innobackupex --stream=xbstream %(extra_opts)s " + " --user=os_admin --password=password" " /var/lib/mysql/data 2>/tmp/innobackupex.log") XTRA_BACKUP = XTRA_BACKUP_RAW % {'extra_opts': ''} XTRA_BACKUP_EXTRA_OPTS = XTRA_BACKUP_RAW % {'extra_opts': '--no-lock'} XTRA_BACKUP_INCR = ('sudo innobackupex --stream=xbstream' ' --incremental --incremental-lsn=%(lsn)s' - ' %(extra_opts)s /var/lib/mysql/data' + ' %(extra_opts)s ' + ' --user=os_admin --password=password' + ' /var/lib/mysql/data' ' 2>/tmp/innobackupex.log') SQLDUMP_BACKUP_RAW = ("mysqldump --all-databases %(extra_opts)s " "--opt --password=password -u os_admin"