您好,登錄后才能下訂單哦!
trove upgrade 用于將數據庫從一個版本更新到另一個版本,如:將mysql5.5更換到mysql5.6
trove/taskmanager/manager.py 368行
def upgrade(self, context, instance_id, datastore_version_id): instance_tasks = models.BuiltInstanceTasks.load(context, instance_id) datastore_version = DatastoreVersion.load_by_uuid(datastore_version_id) with EndNotification(context): instance_tasks.upgrade(datastore_version)
instance_tasks.upgrade(datastore_version)調用
trove/taskmanager/models.py 1501行
def upgrade(self, datastore_version): ... try: upgrade_info = self.guest.pre_upgrade() ... self.server.rebuild(datastore_version.p_w_picpath_id, files=injected_files) ... if volume: upgrade_info['device'] = volume_device self.guest.post_upgrade(upgrade_info) self.reset_task_status() ...
upgrade instance 主要是以下幾步完成:
self.guest.pre_upgrade:更新前的一些操作,主要是將mysql的配置文件保存在cinder volume中
self.server.rebuild:用新的數據庫基礎鏡像重建trove的nova實例
self.guest.post_upgrade:重建nova instance後的一些操作,主要操作是從cinder volume中恢復mysql配置文件,啟動mysql
self.guest.pre_upgrade,self.guest.post_upgrade 通過rcp方式調用運行在nova instance上的trove-guestagent的中對應方法
trove/guestagent/datastore/mysql/_common/manager.py 245行
def pre_upgrade(self, context): app = self.mysql_app(self.mysql_app_status.get()) data_dir = app.get_data_dir() mount_point, _data = os.path.split(data_dir) save_dir = "%s/etc_mysql" % mount_point save_etc_dir = "%s/etc" % mount_point home_save = "%s/trove_user" % mount_point app.status.begin_restart() app.stop_db() if operating_system.exists("/etc/my.cnf", as_root=True): operating_system.create_directory(save_etc_dir, as_root=True) operating_system.copy("/etc/my.cnf", save_etc_dir, preserve=True, as_root=True) operating_system.copy("/etc/mysql/.", save_dir, preserve=True, as_root=True) operating_system.copy("%s/." % os.path.expanduser('~'), home_save, preserve=True, as_root=True) self.unmount_volume(context, mount_point=data_dir) return { 'mount_point': mount_point, 'save_dir': save_dir, 'save_etc_dir': save_etc_dir, 'home_save': home_save }
pre_upgrade備份數據庫的配置文件、guestagent位于trove home 目錄下的配置信息,返回包含備份信息的一個字典
trove/guestagent/datastore/mysql/_common/manager.py 275行
def post_upgrade(self, context, upgrade_info): app = self.mysql_app(self.mysql_app_status.get()) app.stop_db() if 'device' in upgrade_info: self.mount_volume(context, mount_point=upgrade_info['mount_point'], device_path=upgrade_info['device'], write_to_fstab=True) if operating_system.exists(upgrade_info['save_etc_dir'], is_directory=True, as_root=True): operating_system.copy("%s/." % upgrade_info['save_etc_dir'], "/etc", preserve=True, as_root=True) operating_system.copy("%s/." % upgrade_info['save_dir'], "/etc/mysql", preserve=True, as_root=True) operating_system.copy("%s/." % upgrade_info['home_save'], os.path.expanduser('~'), preserve=True, as_root=True) self.configuration_manager.refresh_cache() app.start_mysql()
post_upgrade恢復備份中的配置文件,不對老數據庫的任何文件作修改,直接使用老數據庫的配置文件與數據文件啟動數據庫
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。