Exemplo n.º 1
0
    def pre_upgrade(self, context):
        mount_point = self._app.get_working_dir()
        save_etc_dir = "%s/etc" % mount_point
        home_save = "%s/trove_user" % mount_point

        self._app.status.begin_restart()
        self._app.stop_db()

        operating_system.copy("%s/." % system.REDIS_CONF_DIR,
                              save_etc_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=mount_point)

        return {
            'mount_point': mount_point,
            'save_etc_dir': save_etc_dir,
            'home_save': home_save
        }
Exemplo n.º 2
0
 def _run_pre_backup(self):
     try:
         for cmd in self.pre_backup_commands:
             utils.execute_with_timeout(*cmd)
         root = service.CouchbaseRootAccess()
         pw = root.get_password()
         self._save_buckets_config(pw)
         with open(OUTFILE, "r") as f:
             out = f.read()
             if out != "[]":
                 d = json.loads(out)
                 all_memcached = True
                 for i in range(len(d)):
                     bucket_type = d[i]["bucketType"]
                     if bucket_type != "memcached":
                         all_memcached = False
                         break
                 if not all_memcached:
                     self._backup(pw)
                 else:
                     LOG.info(_("All buckets are memcached.  "
                                "Skipping backup."))
         operating_system.move(OUTFILE, system.COUCHBASE_DUMP_DIR)
         if pw != "password":
             # Not default password, backup generated root password
             operating_system.copy(system.pwd_file,
                                   system.COUCHBASE_DUMP_DIR,
                                   preserve=True, as_root=True)
     except exception.ProcessExecutionError as p:
         LOG.error(p)
         raise p
Exemplo n.º 3
0
    def enable_as_master(self, service, master_config, for_failover=False):
        # For a server to be a master in postgres, we need to enable
        # replication user in pg_hba and ensure that WAL logging is
        # the appropriate level (use the same settings as backups)
        self._get_or_create_replication_user()
        hba_entry = "host   replication   replicator    0.0.0.0/0   md5 \n"

        tmp_hba = '/tmp/pg_hba'
        operating_system.copy(self.pgsql_hba_config,
                              tmp_hba,
                              force=True,
                              as_root=True)
        operating_system.chmod(tmp_hba, FileMode.SET_ALL_RWX(), as_root=True)
        with open(tmp_hba, 'a+') as hba_file:
            hba_file.write(hba_entry)

        operating_system.copy(tmp_hba,
                              self.pgsql_hba_config,
                              force=True,
                              as_root=True)
        operating_system.chmod(self.pgsql_hba_config,
                               FileMode.SET_USR_RWX(),
                               as_root=True)
        operating_system.remove(tmp_hba, as_root=True)
        pgutil.psql("SELECT pg_reload_conf()")
Exemplo n.º 4
0
    def enable_as_master(self, service, master_config, for_failover=False):
        """For a server to be a master in postgres, we need to enable
        the replication user in pg_hba and ensure that WAL logging is
        at the appropriate level (use the same settings as backups)
        """
        LOG.debug("Enabling as master, with cfg: %s " % master_config)
        self._get_or_create_replication_user(service)
        hba_entry = "host   replication   replicator    0.0.0.0/0   md5 \n"

        # TODO(atomic77) Remove this hack after adding cfg manager for pg_hba
        tmp_hba = '/tmp/pg_hba'
        operating_system.copy(service.pgsql_hba_config,
                              tmp_hba,
                              force=True,
                              as_root=True)
        operating_system.chmod(tmp_hba,
                               FileMode.OCTAL_MODE("0777"),
                               as_root=True)
        with open(tmp_hba, 'a+') as hba_file:
            hba_file.write(hba_entry)

        operating_system.copy(tmp_hba,
                              service.pgsql_hba_config,
                              force=True,
                              as_root=True)
        operating_system.chmod(service.pgsql_hba_config,
                               FileMode.OCTAL_MODE("0600"),
                               as_root=True)
        operating_system.remove(tmp_hba, as_root=True)
        service.reload_configuration()
Exemplo n.º 5
0
    def enable_as_master(self, service, master_config):
        """Primary postgredql settings.

        For a server to be a master in postgres, we need to enable
        the replication user in pg_hba.conf
        """
        self._get_or_create_replication_user(service)

        hba_entry = f"host replication {REPL_USER} 0.0.0.0/0 md5\n"
        tmp_hba = '/tmp/pg_hba'
        operating_system.copy(pg_service.HBA_CONFIG_FILE, tmp_hba,
                              force=True, as_root=True)
        operating_system.chmod(tmp_hba, FileMode.SET_ALL_RWX(),
                               as_root=True)
        with open(tmp_hba, 'a+') as hba_file:
            hba_file.write(hba_entry)

        operating_system.copy(tmp_hba, pg_service.HBA_CONFIG_FILE,
                              force=True, as_root=True)
        operating_system.chown(pg_service.HBA_CONFIG_FILE,
                               user=CONF.database_service_uid,
                               group=CONF.database_service_uid, as_root=True)
        operating_system.chmod(pg_service.HBA_CONFIG_FILE,
                               FileMode.SET_USR_RWX(),
                               as_root=True)
        operating_system.remove(tmp_hba, as_root=True)
        LOG.debug(f"{pg_service.HBA_CONFIG_FILE} changed")

        service.restart()
Exemplo n.º 6
0
 def _run_pre_backup(self):
     try:
         for cmd in self.pre_backup_commands:
             utils.execute_with_timeout(*cmd)
         root = service.CouchbaseRootAccess()
         pw = root.get_password()
         self._save_buckets_config(pw)
         with open(OUTFILE, "r") as f:
             out = f.read()
             if out != "[]":
                 d = json.loads(out)
                 all_memcached = True
                 for i in range(len(d)):
                     bucket_type = d[i]["bucketType"]
                     if bucket_type != "memcached":
                         all_memcached = False
                         break
                 if not all_memcached:
                     self._backup(pw)
                 else:
                     LOG.info(
                         _("All buckets are memcached.  "
                           "Skipping backup."))
         operating_system.move(OUTFILE, system.COUCHBASE_DUMP_DIR)
         if pw != "password":
             # Not default password, backup generated root password
             operating_system.copy(system.pwd_file,
                                   system.COUCHBASE_DUMP_DIR,
                                   preserve=True,
                                   as_root=True)
     except exception.ProcessExecutionError as p:
         LOG.error(p)
         raise p
Exemplo n.º 7
0
    def pre_upgrade(self, context):
        data_dir = self.app.cassandra_data_dir
        mount_point, _data = os.path.split(data_dir)
        save_etc_dir = "%s/etc" % mount_point
        home_save = "%s/trove_user" % mount_point

        self.app.status.begin_restart()
        self.app.drain()
        self.app.stop_db()

        operating_system.copy("%s/." % self.app.cassandra_conf_dir,
                              save_etc_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=mount_point)

        return {
            'mount_point': mount_point,
            'save_etc_dir': save_etc_dir,
            'home_save': home_save
        }
Exemplo n.º 8
0
    def enable_as_master(self, service, master_config, for_failover=False):
        """For a server to be a master in postgres, we need to enable
        the replication user in pg_hba and ensure that WAL logging is
        at the appropriate level (use the same settings as backups)
        """
        LOG.debug("Enabling as master, with cfg: %s " % master_config)
        self._get_or_create_replication_user()
        hba_entry = "host   replication   replicator    0.0.0.0/0   md5 \n"

        # TODO(atomic77) Remove this hack after adding cfg manager for pg_hba
        tmp_hba = '/tmp/pg_hba'
        operating_system.copy(self.PGSQL_HBA_CONFIG, tmp_hba,
                              force=True, as_root=True)
        operating_system.chmod(tmp_hba, FileMode.OCTAL_MODE("0777"),
                               as_root=True)
        with open(tmp_hba, 'a+') as hba_file:
            hba_file.write(hba_entry)

        operating_system.copy(tmp_hba, self.PGSQL_HBA_CONFIG,
                              force=True, as_root=True)
        operating_system.chmod(self.PGSQL_HBA_CONFIG,
                               FileMode.OCTAL_MODE("0600"),
                               as_root=True)
        operating_system.remove(tmp_hba, as_root=True)
        pgutil.psql("SELECT pg_reload_conf()")
Exemplo n.º 9
0
 def store_key(self, key):
     """Store the cluster key."""
     LOG.debug("Storing key for MongoDB cluster.")
     with tempfile.NamedTemporaryFile() as f:
         f.write(key)
         f.flush()
         operating_system.copy(f.name, system.MONGO_KEY_FILE, force=True, as_root=True)
     operating_system.chmod(system.MONGO_KEY_FILE, operating_system.FileMode.SET_USR_RO, as_root=True)
     operating_system.chown(system.MONGO_KEY_FILE, system.MONGO_USER, system.MONGO_USER, as_root=True)
Exemplo n.º 10
0
 def save_files_pre_upgrade(self, mount_point):
     LOG.debug('Saving files pre-upgrade.')
     mnt_etc_dir = os.path.join(mount_point, 'save_etc')
     if self.OS != operating_system.REDHAT:
         # No need to store the config files away for Redhat because
         # they are already stored in the data volume.
         operating_system.remove(mnt_etc_dir, force=True, as_root=True)
         operating_system.copy(self.pgsql_config_dir, mnt_etc_dir,
                               preserve=True, recursive=True, as_root=True)
     return {'save_etc': mnt_etc_dir}
Exemplo n.º 11
0
 def save_files_pre_upgrade(self, mount_point):
     LOG.debug('Saving files pre-upgrade.')
     for save_dir, save_dir_info in self.upgrade_copy_info.items():
         is_dir = save_dir_info['is_dir']
         from_path = save_dir_info['path']
         to_path = os.path.join(mount_point, save_dir)
         operating_system.remove(to_path, force=True, as_root=True)
         operating_system.copy(from_path, to_path,
                               preserve=True, recursive=is_dir,
                               as_root=True)
     return {'copy_info': self.upgrade_copy_info}
Exemplo n.º 12
0
 def restore_files_post_upgrade(self, upgrade_info):
     LOG.debug('Restoring files post-upgrade.')
     if self.OS != operating_system.REDHAT:
         # No need to restore the config files for Redhat because
         # they are already in the data volume.
         operating_system.copy('%s/.' % upgrade_info['save_etc'],
                               self.pgsql_config_dir,
                               preserve=True, recursive=True,
                               force=True, as_root=True)
         operating_system.remove(upgrade_info['save_etc'], force=True,
                                 as_root=True)
Exemplo n.º 13
0
 def restore_files_post_upgrade(self, upgrade_info):
     LOG.debug('Restoring files post-upgrade.')
     operating_system.copy('%s/.' % upgrade_info['save_opt_etc'],
                           self.couchbase_opt_etc_dir,
                           preserve=True, recursive=True,
                           force=True, as_root=True)
     operating_system.copy(upgrade_info['save_etc'],
                           self.couchbase_conf_dir,
                           preserve=True, force=True, as_root=True)
     for save_dir in [upgrade_info['save_opt_etc'],
                      upgrade_info['save_etc']]:
         operating_system.remove(save_dir, force=True, as_root=True)
Exemplo n.º 14
0
 def restore_files_post_upgrade(self, upgrade_info):
     operating_system.copy('%s/.' % upgrade_info['save_confs'],
                           system.CONFIG_DIR,
                           preserve=True, recursive=True,
                           force=True, as_root=True)
     operating_system.copy('%s/.' % upgrade_info['save_creds'],
                           os.path.expanduser('~'),
                           preserve=True, recursive=True,
                           force=True, as_root=True)
     for save_dir in [upgrade_info['save_confs'],
                      upgrade_info['save_creds']]:
         operating_system.remove(save_dir, force=True, as_root=True)
Exemplo n.º 15
0
 def _restore_directory(self, restore_dir, target_dir, owner=None):
     restore_path = os.path.join(restore_dir, ".")
     operating_system.copy(restore_path,
                           target_dir,
                           preserve=True,
                           as_root=True)
     if owner is not None:
         operating_system.chown(path=target_dir,
                                user=owner,
                                group=owner,
                                recursive=True,
                                as_root=True)
Exemplo n.º 16
0
 def apply_next(self, options):
     revision_num = self.count_revisions() + 1
     old_revision_backup = guestagent_utils.build_file_path(
         self._revision_backup_dir, self._base_config_name, str(revision_num), self._BACKUP_EXT
     )
     operating_system.copy(
         self._base_config_path, old_revision_backup, force=True, preserve=True, as_root=self._requires_root
     )
     current = operating_system.read_file(self._base_config_path, codec=self._codec)
     guestagent_utils.update_dict(options, current)
     operating_system.write_file(self._base_config_path, current, codec=self._codec, as_root=self._requires_root)
     operating_system.chown(self._base_config_path, self._owner, self._group, as_root=self._requires_root)
     operating_system.chmod(self._base_config_path, FileMode.ADD_READ_ALL, as_root=self._requires_root)
Exemplo n.º 17
0
 def save_files_pre_upgrade(self, mount_point):
     LOG.debug('Saving files pre-upgrade.')
     mnt_etc_dir = os.path.join(mount_point, 'save_etc')
     if self.OS not in [operating_system.REDHAT]:
         # No need to store the config files away for Redhat because
         # they are already stored in the data volume.
         operating_system.remove(mnt_etc_dir, force=True, as_root=True)
         operating_system.copy(self.pgsql_config_dir,
                               mnt_etc_dir,
                               preserve=True,
                               recursive=True,
                               as_root=True)
     return {'save_etc': mnt_etc_dir}
Exemplo n.º 18
0
 def save_files_pre_upgrade(self, mount_point):
     LOG.debug('Saving files pre-upgrade.')
     mnt_opt_etc = os.path.join(mount_point, 'save_opt_etc')
     mnt_etc = os.path.join(mount_point, 'save_etc')
     for save_dir in [mnt_opt_etc, mnt_etc]:
         operating_system.remove(save_dir, force=True, as_root=True)
     operating_system.copy(self.couchbase_opt_etc_dir, mnt_opt_etc,
                           preserve=True, recursive=True, as_root=True)
     operating_system.copy(self.couchbase_conf_dir,
                           mnt_etc, preserve=True, recursive=True,
                           as_root=True)
     return {'save_opt_etc': mnt_opt_etc,
             'save_etc': mnt_etc}
Exemplo n.º 19
0
 def restore_files_post_upgrade(self, upgrade_info):
     LOG.debug('Restoring files post-upgrade.')
     if self.OS not in [operating_system.REDHAT, operating_system.ORACLE]:
         # No need to restore the config files for Redhat because
         # they are already in the data volume.
         operating_system.copy('%s/.' % upgrade_info['save_etc'],
                               self.pgsql_config_dir,
                               preserve=True, recursive=True,
                               force=True, as_root=True)
         operating_system.remove(upgrade_info['save_etc'], force=True,
                                 as_root=True)
     self.configuration_manager.refresh_cache()
     self.status.set_ready()
Exemplo n.º 20
0
 def restore_files_post_upgrade(self, upgrade_info):
     LOG.debug('Restoring files post-upgrade.')
     mount_point = upgrade_info['mount_point']
     upgrade_copy_info = upgrade_info['copy_info']
     for save_dir, save_dir_info in upgrade_copy_info.items():
         is_dir = save_dir_info['is_dir']
         from_path = os.path.join(mount_point, save_dir)
         files = os.path.join(from_path, '.') if is_dir else from_path
         operating_system.copy(files, save_dir_info['path'],
                               preserve=True, recursive=is_dir,
                               force=True, as_root=True)
         operating_system.remove(from_path, force=True, as_root=True)
     self.status.set_ready()
Exemplo n.º 21
0
 def restore_files_post_upgrade(self, upgrade_info):
     operating_system.copy('%s/.' % upgrade_info['save_confs'],
                           system.CONFIG_DIR,
                           preserve=True, recursive=True,
                           force=True, as_root=True)
     operating_system.copy(os.path.join(upgrade_info['save_creds'],
                                        system.MONGO_ADMIN_CREDS_FILENAME),
                           os.path.expanduser('~'),
                           preserve=True)
     for save_dir in [upgrade_info['save_confs'],
                      upgrade_info['save_creds']]:
         operating_system.remove(save_dir, force=True, as_root=True)
     self.status.set_ready()
     self.configuration_manager.refresh_cache()
Exemplo n.º 22
0
 def restore_files_post_upgrade(self, upgrade_info):
     LOG.debug('Restoring files post-upgrade.')
     if self.OS not in [operating_system.REDHAT]:
         # No need to restore the config files for Redhat because
         # they are already in the data volume.
         operating_system.copy('%s/.' % upgrade_info['save_etc'],
                               self.pgsql_config_dir,
                               preserve=True,
                               recursive=True,
                               force=True,
                               as_root=True)
         operating_system.remove(upgrade_info['save_etc'],
                                 force=True,
                                 as_root=True)
Exemplo n.º 23
0
 def restore_files_post_upgrade(self, upgrade_info):
     operating_system.copy('%s/.' % upgrade_info['save_confs'],
                           system.CONFIG_DIR,
                           preserve=True,
                           recursive=True,
                           force=True,
                           as_root=True)
     operating_system.copy('%s/.' % upgrade_info['save_creds'],
                           os.path.expanduser('~'),
                           preserve=True,
                           recursive=True,
                           force=True,
                           as_root=True)
     for save_dir in [
             upgrade_info['save_confs'], upgrade_info['save_creds']
     ]:
         operating_system.remove(save_dir, force=True, as_root=True)
Exemplo n.º 24
0
 def save_files_pre_upgrade(self, mount_point):
     LOG.debug('Saving files pre-upgrade.')
     mnt_opt_etc = os.path.join(mount_point, 'save_opt_etc')
     mnt_etc = os.path.join(mount_point, 'save_etc')
     for save_dir in [mnt_opt_etc, mnt_etc]:
         operating_system.remove(save_dir, force=True, as_root=True)
     operating_system.copy(self.couchbase_opt_etc_dir,
                           mnt_opt_etc,
                           preserve=True,
                           recursive=True,
                           as_root=True)
     operating_system.copy(self.couchbase_conf_dir,
                           mnt_etc,
                           preserve=True,
                           recursive=True,
                           as_root=True)
     return {'save_opt_etc': mnt_opt_etc, 'save_etc': mnt_etc}
Exemplo n.º 25
0
 def restore_files_post_upgrade(self, upgrade_info):
     LOG.debug('Restoring files post-upgrade.')
     operating_system.copy('%s/.' % upgrade_info['save_opt_etc'],
                           self.couchbase_opt_etc_dir,
                           preserve=True,
                           recursive=True,
                           force=True,
                           as_root=True)
     operating_system.copy(upgrade_info['save_etc'],
                           self.couchbase_conf_dir,
                           preserve=True,
                           force=True,
                           as_root=True)
     for save_dir in [
             upgrade_info['save_opt_etc'], upgrade_info['save_etc']
     ]:
         operating_system.remove(save_dir, force=True, as_root=True)
Exemplo n.º 26
0
 def save_files_pre_upgrade(self, mount_point):
     save_dir = path.join(mount_point, 'saves')
     saves = {
         'oratab': self.paths.oratab_file,
         'dbs': self.paths.dbs_dir,
         'oranet': self.paths.oranet_dir,
         'admin': self.paths.admin_dir,
         'conf_file': CONF.get(MANAGER).conf_file
     }
     if not operating_system.exists(save_dir,
                                    is_directory=True, as_root=True):
         operating_system.create_directory(save_dir,
                                           force=True, as_root=True)
     for item in saves.keys():
         operating_system.copy(saves[item], path.join(save_dir, item),
                               recursive=True, preserve=True, as_root=True)
     return {'save_dir': save_dir,
             'saves': saves}
Exemplo n.º 27
0
    def _run_restore(self):
        metadata = self.storage.load_metadata(self.location, self.checksum)
        self.db_name = metadata['db_name']
        self.app.paths.update_db_name(self.db_name)

        new_dirs = [
            self.app.paths.audit_dir, self.app.paths.db_fast_recovery_logs_dir,
            self.app.paths.db_fast_recovery_dir, self.app.paths.db_data_dir
        ]
        for new_dir in new_dirs:
            operating_system.create_directory(
                new_dir,
                user=self.app.instance_owner,
                group=self.app.instance_owner_group,
                force=True,
                as_root=True)

        # the backup set will restore directly to ORADATA/backupset_files
        self._unpack_backup_files(self.location, self.checksum)

        if operating_system.exists(self.app.paths.base_spfile, as_root=True):
            operating_system.copy(self.app.paths.base_spfile,
                                  self.app.paths.spfile,
                                  preserve=True,
                                  as_root=True)

        # the conf file was just restored by the unpack so sync now
        self.app.admin.delete_conf_cache()
        self.app.admin.ora_config.db_name = self.db_name

        chown_dirs = [
            self.app.paths.backup_dir, self.app.paths.fast_recovery_area
        ]
        for chown_dir in chown_dirs:
            operating_system.chown(chown_dir,
                                   self.app.instance_owner,
                                   self.app.instance_owner_group,
                                   recursive=True,
                                   force=True,
                                   as_root=True)

        self._perform_restore()
        self._perform_recover()
        self._open_database()
Exemplo n.º 28
0
    def _regenerate_base_configuration(self):
        """Gather all configuration changes and apply them in order on the base
        revision. Write the results to the configuration file.
        """

        if not os.path.exists(self._base_revision_file):
            # Initialize the file with the current configuration contents if it
            # does not exist.
            operating_system.copy(
                self._base_config_path, self._base_revision_file,
                force=True, preserve=True, as_root=self._requires_root)

        base_revision = operating_system.read_file(
            self._base_revision_file, codec=self._codec)
        changes = self._import_strategy.parse_updates()
        updated_revision = guestagent_utils.update_dict(changes, base_revision)
        operating_system.write_file(
            self._base_config_path, updated_revision, codec=self._codec,
            as_root=self._requires_root)
Exemplo n.º 29
0
    def _regenerate_base_configuration(self):
        """Gather all configuration changes and apply them in order on the base
        revision. Write the results to the configuration file.
        """

        if not os.path.exists(self._base_revision_file):
            # Initialize the file with the current configuration contents if it
            # does not exist.
            operating_system.copy(
                self._base_config_path, self._base_revision_file,
                force=True, preserve=True, as_root=self._requires_root)

        base_revision = operating_system.read_file(
            self._base_revision_file, codec=self._codec,
            as_root=self._requires_root)
        changes = self._import_strategy.parse_updates()
        updated_revision = guestagent_utils.update_dict(changes, base_revision)
        operating_system.write_file(
            self._base_config_path, updated_revision, codec=self._codec,
            as_root=self._requires_root)
Exemplo n.º 30
0
    def _run_restore(self):
        metadata = self.storage.load_metadata(self.location, self.checksum)
        self.db_name = metadata["db_name"]
        self.app.paths.update_db_name(self.db_name)

        new_dirs = [
            self.app.paths.audit_dir,
            self.app.paths.db_fast_recovery_logs_dir,
            self.app.paths.db_fast_recovery_dir,
            self.app.paths.db_data_dir,
        ]
        for new_dir in new_dirs:
            operating_system.create_directory(
                new_dir, user=self.app.instance_owner, group=self.app.instance_owner_group, force=True, as_root=True
            )

        # the backup set will restore directly to ORADATA/backupset_files
        self._unpack_backup_files(self.location, self.checksum)

        if operating_system.exists(self.app.paths.base_spfile, as_root=True):
            operating_system.copy(self.app.paths.base_spfile, self.app.paths.spfile, preserve=True, as_root=True)

        # the conf file was just restored by the unpack so sync now
        self.app.admin.delete_conf_cache()
        self.app.admin.ora_config.db_name = self.db_name

        chown_dirs = [self.app.paths.backup_dir, self.app.paths.fast_recovery_area]
        for chown_dir in chown_dirs:
            operating_system.chown(
                chown_dir,
                self.app.instance_owner,
                self.app.instance_owner_group,
                recursive=True,
                force=True,
                as_root=True,
            )

        self._perform_restore()
        self._perform_recover()
        self._open_database()
Exemplo n.º 31
0
    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
        }
Exemplo n.º 32
0
    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'])

        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)
        app.start_mysql()
Exemplo n.º 33
0
    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
        }
Exemplo n.º 34
0
 def restore_files_post_upgrade(self, upgrade_info):
     saves = upgrade_info.get('saves')
     save_dir = upgrade_info.get('save_dir')
     if not (saves and save_dir):
         raise exception.GuestError(_(
             "Missing upgrade saves and/or save directory info: %s")
             % upgrade_info)
     for item in saves.keys():
         if item == 'conf_file':
             operating_system.copy(path.join(save_dir, item),
                                   CONF.get(MANAGER).conf_file,
                                   force=True, preserve=True, as_root=True)
             continue
         if operating_system.exists(saves[item],
                                    is_directory=True, as_root=True):
             operating_system.remove(saves[item], force=True,
                                     recursive=True, as_root=True)
         operating_system.copy(path.join(save_dir, item), saves[item],
                               recursive=True, preserve=True, as_root=True)
     operating_system.remove(save_dir, force=True, as_root=True)
     self._init_configuration_manager()
     self.configuration_manager.refresh_cache()
     self.status.set_ready()
Exemplo n.º 35
0
    def enable_as_master(self, service, master_config, for_failover=False):
        """For a server to be a master in postgres, we need to enable
        the replication user in pg_hba and ensure that WAL logging is
        at the appropriate level (use the same settings as backups)
        """
        LOG.debug("Enabling as master, with cfg: %s " % master_config)
        self._get_or_create_replication_user(service)
        hba_entry = "host   replication   replicator    0.0.0.0/0   md5 \n"

        tmp_hba = '/tmp/pg_hba'
        operating_system.copy(service.pgsql_hba_config, tmp_hba,
                              force=True, as_root=True)
        operating_system.chmod(tmp_hba, FileMode.SET_ALL_RWX(),
                               as_root=True)
        with open(tmp_hba, 'a+') as hba_file:
            hba_file.write(hba_entry)

        operating_system.copy(tmp_hba, service.pgsql_hba_config,
                              force=True, as_root=True)
        operating_system.chmod(service.pgsql_hba_config,
                               FileMode.SET_USR_RWX(),
                               as_root=True)
        operating_system.remove(tmp_hba, as_root=True)
        service.reload_configuration()
Exemplo n.º 36
0
 def apply_next(self, options):
     revision_num = self.count_revisions() + 1
     old_revision_backup = guestagent_utils.build_file_path(
         self._revision_backup_dir, self._base_config_name,
         str(revision_num), self._BACKUP_EXT)
     operating_system.copy(self._base_config_path,
                           old_revision_backup,
                           force=True,
                           preserve=True,
                           as_root=self._requires_root)
     current = operating_system.read_file(self._base_config_path,
                                          codec=self._codec)
     guestagent_utils.update_dict(options, current)
     operating_system.write_file(self._base_config_path,
                                 current,
                                 codec=self._codec,
                                 as_root=self._requires_root)
     operating_system.chown(self._base_config_path,
                            self._owner,
                            self._group,
                            as_root=self._requires_root)
     operating_system.chmod(self._base_config_path,
                            FileMode.ADD_READ_ALL,
                            as_root=self._requires_root)
Exemplo n.º 37
0
    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'])

        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)
        app.start_mysql()
Exemplo n.º 38
0
 def save_files_pre_upgrade(self, mount_point):
     mnt_confs_dir = os.path.join(mount_point, 'save_confs/')
     mnt_creds_dir = os.path.join(mount_point, 'save_creds/')
     for save_dir in [mnt_confs_dir, mnt_creds_dir]:
         if not operating_system.exists(save_dir,
                                        is_directory=True,
                                        as_root=True):
             operating_system.create_directory(save_dir,
                                               force=True,
                                               as_root=True)
     operating_system.copy(system.MONGOD_CONFIG_FILE, mnt_confs_dir,
                           preserve=True, as_root=True)
     operating_system.copy(system.MONGOD_CONFIG_OVERRIDES_DIR,
                           mnt_confs_dir,
                           preserve=True, recursive=True, as_root=True)
     operating_system.copy(system.MONGO_ADMIN_CREDS_FILE, mnt_creds_dir,
                           preserve=True, as_root=True)
     return {'save_confs': mnt_confs_dir,
             'save_creds': mnt_creds_dir}
Exemplo n.º 39
0
 def save_files_pre_upgrade(self, mount_point):
     mnt_confs_dir = os.path.join(mount_point, 'save_confs/')
     mnt_creds_dir = os.path.join(mount_point, 'save_creds/')
     for save_dir in [mnt_confs_dir, mnt_creds_dir]:
         if not operating_system.exists(
                 save_dir, is_directory=True, as_root=True):
             operating_system.create_directory(save_dir,
                                               force=True,
                                               as_root=True)
     operating_system.copy(system.MONGOD_CONFIG_FILE,
                           mnt_confs_dir,
                           preserve=True,
                           as_root=True)
     operating_system.copy(system.MONGOD_CONFIG_OVERRIDES_DIR,
                           mnt_confs_dir,
                           preserve=True,
                           recursive=True,
                           as_root=True)
     operating_system.copy(system.MONGO_ADMIN_CREDS_FILE,
                           mnt_creds_dir,
                           preserve=True,
                           as_root=True)
     return {'save_confs': mnt_confs_dir, 'save_creds': mnt_creds_dir}
Exemplo n.º 40
0
    def prepare_slave(self, service, snapshot):
        """Prepare the environment needed for starting the slave Oracle
        processes.
        """
        master_info = snapshot['master']
        db_name = master_info['db_name']
        db_unique_name = ('%(db_name)s_%(replica_label)s' %
                          {'db_name': db_name,
                           'replica_label': utils.generate_random_string(6)})
        service.paths.update_db_name(db_name)

        # Create necessary directories and set necessary permissions
        new_dirs = [service.paths.db_data_dir,
                    service.paths.db_fast_recovery_logs_dir,
                    service.paths.db_fast_recovery_dir,
                    service.paths.audit_dir]
        for directory in new_dirs:
            operating_system.create_directory(directory,
                                              service.instance_owner,
                                              service.instance_owner_group,
                                              as_root=True)

        chown_dirs = [service.paths.fast_recovery_area,
                      service.paths.admin_dir]
        for directory in chown_dirs:
            operating_system.chown(directory,
                                   service.instance_owner,
                                   service.instance_owner_group,
                                   as_root=True)

        # Install on the slave files extracted from the master
        # (e.g. the control, pfile, password, oracle.cnf file ... etc)
        oradata_encoded = master_info['oradata']
        tmp_data_path = path.join(TMP_DIR, 'oradata.tar.gz')
        operating_system.write_file(tmp_data_path, oradata_encoded,
                                    codec=stream_codecs.Base64Codec(),
                                    encode=False)
        utils.execute_with_timeout('tar', '-Pxzvf', tmp_data_path,
                                   run_as_root=True, root_helper='sudo')

        # Put the control file in place
        tmp_ctlfile_path = sorted(
            operating_system.list_files_in_directory(TMP_DIR,
                                                     pattern='*.ctl.bak$',
                                                     recursive=True,
                                                     as_root=True))[0]
        ctlfile_name = path.basename(tmp_ctlfile_path)[:-4]
        ctlfile1_path = path.join(service.paths.ctlfile1_dir, ctlfile_name)
        operating_system.create_directory(service.paths.ctlfile1_dir,
                                          force=True, user='******',
                                          group='oinstall', as_root=True)
        operating_system.create_directory(service.paths.ctlfile2_dir,
                                          force=True, user='******',
                                          group='oinstall', as_root=True)
        operating_system.move(
            tmp_ctlfile_path, ctlfile1_path, as_root=True)
        operating_system.copy(
            ctlfile1_path,
            service.paths.ctlfile2_dir, preserve=True, as_root=True)

        # Set the db_name and db_unique_name via the PFILE which will be
        # removed later
        operating_system.write_file(service.paths.pfile,
                                    "*.db_unique_name='%s'\n"
                                    "*.db_name='%s'\n"
                                    % (db_unique_name, db_name),
                                    as_root=True)
        operating_system.chown(service.paths.pfile,
                               service.instance_owner,
                               service.instance_owner_group,
                               as_root=True, force=True)

        service.admin.delete_conf_cache()
        service.admin.ora_config.db_name = db_name
        service.admin.ora_config.db_unique_name = db_unique_name

        # Set proper permissions on the oratab file
        operating_system.chown(service.paths.oratab_file,
                               service.instance_owner,
                               service.instance_owner_group,
                               as_root=True, force=True)

        # Create the listener.ora file and restart
        service.configure_listener()
Exemplo n.º 41
0
    def prepare_slave(self, service, snapshot):
        """Prepare the environment needed for starting the slave Oracle
        processes.
        """
        master_info = snapshot['master']
        db_name = master_info['db_name']
        db_unique_name = ('%(db_name)s_%(replica_label)s' % {
            'db_name': db_name,
            'replica_label': utils.generate_random_string(6)
        })
        service.paths.update_db_name(db_name)

        # Create necessary directories and set necessary permissions
        new_dirs = [
            service.paths.db_data_dir, service.paths.db_fast_recovery_logs_dir,
            service.paths.db_fast_recovery_dir, service.paths.audit_dir
        ]
        for directory in new_dirs:
            operating_system.create_directory(directory,
                                              service.instance_owner,
                                              service.instance_owner_group,
                                              as_root=True)

        chown_dirs = [
            service.paths.fast_recovery_area, service.paths.admin_dir
        ]
        for directory in chown_dirs:
            operating_system.chown(directory,
                                   service.instance_owner,
                                   service.instance_owner_group,
                                   as_root=True)

        # Install on the slave files extracted from the master
        # (e.g. the control, pfile, password, oracle.cnf file ... etc)
        oradata_encoded = master_info['oradata']
        tmp_data_path = path.join(TMP_DIR, 'oradata.tar.gz')
        operating_system.write_file(tmp_data_path,
                                    oradata_encoded,
                                    codec=stream_codecs.Base64Codec(),
                                    encode=False)
        utils.execute_with_timeout('tar',
                                   '-Pxzvf',
                                   tmp_data_path,
                                   run_as_root=True,
                                   root_helper='sudo')

        # Put the control file in place
        tmp_ctlfile_path = path.join(TMP_DIR, '%s_stby.ctl' % db_name)
        operating_system.move(tmp_ctlfile_path,
                              service.paths.ctlfile1_file,
                              as_root=True)
        operating_system.copy(service.paths.ctlfile1_file,
                              service.paths.ctlfile2_file,
                              preserve=True,
                              as_root=True)

        # Set the db_name and db_unique_name via the PFILE which will be
        # removed later
        operating_system.write_file(service.paths.pfile,
                                    "*.db_unique_name='%s'\n"
                                    "*.db_name='%s'\n" %
                                    (db_unique_name, db_name),
                                    as_root=True)
        operating_system.chown(service.paths.pfile,
                               service.instance_owner,
                               service.instance_owner_group,
                               as_root=True,
                               force=True)

        service.admin.delete_conf_cache()
        service.admin.ora_config.db_name = db_name
        service.admin.ora_config.db_unique_name = db_unique_name

        # Set proper permissions on the oratab file
        operating_system.chown(service.paths.oratab_file,
                               service.instance_owner,
                               service.instance_owner_group,
                               as_root=True,
                               force=True)

        # Create the listener.ora file and restart
        service.configure_listener()
Exemplo n.º 42
0
    def prepare_slave(self, snapshot):
        """Prepare the environment needed for starting the slave Oracle
        processes.
        """
        master_info = snapshot['master']
        db_name = master_info['db_name']

        tmp_dir = '/tmp'
        tmp_data_path = path.join(tmp_dir, 'oradata.tar.gz')
        orabase_path = CONF.get(MANAGER).oracle_base
        orahome_path = CONF.get(MANAGER).oracle_home
        db_data_path = path.join(orabase_path, 'oradata', db_name)
        fast_recovery_path = path.join(orabase_path, 'fast_recovery_area')
        db_fast_recovery_path = path.join(fast_recovery_path, db_name)
        audit_path = path.join(orabase_path, 'admin', db_name, 'adump')
        admin_path = path.join(orabase_path, 'admin')

        # Create necessary directories and set permissions
        directories = [db_data_path, db_fast_recovery_path, audit_path]
        for directory in directories:
            operating_system.create_directory(directory,
                                              system.ORACLE_INSTANCE_OWNER,
                                              system.ORACLE_GROUP_OWNER,
                                              as_root=True)
        operating_system.chown(fast_recovery_path,
                               system.ORACLE_INSTANCE_OWNER,
                               system.ORACLE_GROUP_OWNER,
                               as_root=True)
        operating_system.chown(admin_path,
                               system.ORACLE_INSTANCE_OWNER,
                               system.ORACLE_GROUP_OWNER,
                               as_root=True)

        # Install on the slave files extracted from the master
        # (e.g. the control, pfile, password, oracle.cnf file ... etc)
        oradata = master_info['oradata']
        operating_system.write_file(tmp_data_path,
                                    oradata,
                                    codec=stream_codecs.Base64Codec())
        utils.execute_with_timeout('tar',
                                   '-Pxzvf',
                                   tmp_data_path,
                                   run_as_root=True,
                                   root_helper='sudo')

        # Put the control file in place
        tmp_ctlfile_path = path.join(tmp_dir, '%s_stby.ctl' % db_name)
        ctlfile1_path = path.join(db_data_path, 'control01.ctl')
        ctlfile2_path = path.join(db_fast_recovery_path, 'control02.ctl')
        operating_system.move(tmp_ctlfile_path, ctlfile1_path, as_root=True)
        operating_system.copy(ctlfile1_path,
                              ctlfile2_path,
                              preserve=True,
                              as_root=True)

        db_unique_name = ('%(db_name)s_%(replica_label)s' % {
            'db_name': db_name,
            'replica_label': utils.generate_random_string(6)
        })

        # Customize the pfile for slave and put it in the right place.
        # The pfile that came from master is owned by the 'oracle' user,
        # so we need to change ownership first before editing it.
        tmp_pfile_path = path.join(tmp_dir, 'init%s_stby.ora' % db_name)
        pfile_path = path.join(orahome_path, 'dbs', 'init%s.ora' % db_name)
        operating_system.chown(tmp_pfile_path,
                               getpass.getuser(),
                               None,
                               as_root=True)
        with open(tmp_pfile_path, 'a') as pfile:
            pfile.write("*.db_unique_name='%s'\n" % db_unique_name)

        # Finished editing pfile, put it in the proper directory and chown
        # back to oracle user and group
        operating_system.move(tmp_pfile_path,
                              pfile_path,
                              force=True,
                              as_root=True)
        operating_system.chown(pfile_path,
                               system.ORACLE_INSTANCE_OWNER,
                               system.ORACLE_GROUP_OWNER,
                               as_root=True)

        self.ORA_CONF.db_name = db_name
        self.ORA_CONF.db_unique_name = db_unique_name

        # Set proper permissions on the oratab file
        operating_system.chown('/etc/oratab',
                               system.ORACLE_INSTANCE_OWNER,
                               system.ORACLE_GROUP_OWNER,
                               as_root=True)

        # Create the listener.ora file
        self._create_lsnr_file()

        # Restart the listener
        utils.execute_with_timeout("sudo",
                                   "su",
                                   "-",
                                   "oracle",
                                   "-c",
                                   "lsnrctl reload",
                                   timeout=CONF.usage_timeout)
Exemplo n.º 43
0
    def prepare_slave(self, snapshot):
        """Prepare the environment needed for starting the slave Oracle
        processes.
        """
        master_info = snapshot['master']
        db_name = master_info['db_name']

        tmp_dir = '/tmp'
        tmp_data_path = path.join(tmp_dir, 'oradata.tar.gz')
        orabase_path = CONF.get(MANAGER).oracle_base
        orahome_path = CONF.get(MANAGER).oracle_home
        db_data_path = path.join(orabase_path, 'oradata', db_name)
        fast_recovery_path = path.join(orabase_path, 'fast_recovery_area')
        db_fast_recovery_path = path.join(fast_recovery_path, db_name)
        audit_path = path.join(orabase_path, 'admin', db_name, 'adump')
        admin_path = path.join(orabase_path, 'admin')

        # Create necessary directories and set permissions
        directories = [db_data_path, db_fast_recovery_path, audit_path]
        for directory in directories:
            operating_system.create_directory(directory,
                                              system.ORACLE_INSTANCE_OWNER,
                                              system.ORACLE_GROUP_OWNER,
                                              as_root=True)
        operating_system.chown(fast_recovery_path,
                               system.ORACLE_INSTANCE_OWNER,
                               system.ORACLE_GROUP_OWNER, as_root=True)
        operating_system.chown(admin_path, system.ORACLE_INSTANCE_OWNER,
                               system.ORACLE_GROUP_OWNER, as_root=True)

        # Install on the slave files extracted from the master
        # (e.g. the control, pfile, password, oracle.cnf file ... etc)
        oradata = master_info['oradata']
        operating_system.write_file(tmp_data_path, oradata,
                                    codec=stream_codecs.Base64Codec())
        utils.execute_with_timeout('tar', '-Pxzvf', tmp_data_path,
                                   run_as_root=True, root_helper='sudo')

        # Put the control file in place
        tmp_ctlfile_path = path.join(tmp_dir, '%s_stby.ctl' % db_name)
        ctlfile1_path = path.join(db_data_path, 'control01.ctl')
        ctlfile2_path = path.join(db_fast_recovery_path, 'control02.ctl')
        operating_system.move(tmp_ctlfile_path, ctlfile1_path, as_root=True)
        operating_system.copy(ctlfile1_path, ctlfile2_path, preserve=True,
                              as_root=True)

        db_unique_name = ('%(db_name)s_%(replica_label)s' %
                          {'db_name': db_name,
                           'replica_label': utils.generate_random_string(6)})

        # Customize the pfile for slave and put it in the right place.
        # The pfile that came from master is owned by the 'oracle' user,
        # so we need to change ownership first before editing it.
        tmp_pfile_path = path.join(tmp_dir, 'init%s_stby.ora' % db_name)
        pfile_path = path.join(orahome_path, 'dbs', 'init%s.ora' % db_name)
        operating_system.chown(tmp_pfile_path, getpass.getuser(), None,
                               as_root=True)
        with open(tmp_pfile_path, 'a') as pfile:
            pfile.write("*.db_unique_name='%s'\n" % db_unique_name)

        # Finished editing pfile, put it in the proper directory and chown
        # back to oracle user and group
        operating_system.move(tmp_pfile_path, pfile_path, force=True,
                              as_root=True)
        operating_system.chown(pfile_path, system.ORACLE_INSTANCE_OWNER,
                               system.ORACLE_GROUP_OWNER, as_root=True)

        self.ORA_CONF.db_name = db_name
        self.ORA_CONF.db_unique_name = db_unique_name

        # Set proper permissions on the oratab file
        operating_system.chown('/etc/oratab', system.ORACLE_INSTANCE_OWNER,
                               system.ORACLE_GROUP_OWNER, as_root=True)

        # Create the listener.ora file
        self._create_lsnr_file()

        # Restart the listener
        utils.execute_with_timeout("sudo", "su", "-", "oracle", "-c",
                                   "lsnrctl reload",
                                   timeout=CONF.usage_timeout)