How to use the freezer.utils.utils.create_subprocess function in freezer

To help you get started, we’ve selected a few freezer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / freezer / freezer / scheduler / win_daemon.py View on Github external
def stop(self):
        """Stop the windows service by using sc queryex command, if we use
        win32serviceutil.StoptService(self.service_name) it never gets stopped
        because freezer_scheduler.start() blocks the windows service and
        prevents any new signal to reach the service.
        """
        query = 'sc queryex {0}'.format(self.service_name)
        out = utils.create_subprocess(query)[0]
        pid = None
        for line in out.split('\n'):
            if 'PID' in line:
                pid = line.split(':')[1].strip()

        command = 'taskkill /f /pid {0}'.format(pid)
        utils.create_subprocess(command)
        print('Freezer Service has stopped')
github openstack / freezer / freezer / snapshot / vss.py View on Github external
Freezer create a shadow copy for each time the client runs it's been
    removed after the backup is complete.

    :param volume: The letter of the windows volume e.g. c:\\
    :return: shadow_id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
    :return: shadow_path: shadow copy path
    """
    shadow_path = None
    shadow_id = None

    vss_delete_symlink(windows_volume)

    with winutils.DisableFileSystemRedirection():
        path = os.path.dirname(os.path.abspath(__file__))
        script = '{0}\\scripts\\vss.ps1'.format(path)
        (out, err) = utils.create_subprocess(
            ['powershell.exe', '-executionpolicy', 'unrestricted',
             '-command', script, '-volume', windows_volume])
        if err != '':
            raise Exception('[*] Error creating a new shadow copy on {0}'
                            ', error {1}' .format(windows_volume, err))

        for line in out.split('\n'):
            if 'symbolic' in line:
                shadow_path = line.split('>>')[1].strip()
            if '__RELPATH' in line:
                shadow_id = line.split('=')[1].strip().lower() + '}'
                shadow_id = shadow_id[1:]

        logging.info('[*] Created shadow copy {0}'.
                     format(shadow_id))
github openstack / freezer / freezer / job.py View on Github external
def execute(self):
        LOG.info('Backup job started. '
                 'backup_name: {0}, container: {1}, hostname: {2}, mode: {3},'
                 ' Storage: {4}, compression: {5}'
                 .format(self.conf.backup_name, self.conf.container,
                         self.conf.hostname, self.conf.mode, self.conf.storage,
                         self.conf.compression))
        try:
            if self.conf.mode is 'fs' and self.conf.sync:
                LOG.info('Executing sync to flush the file system buffer.')
                (out, err) = utils.create_subprocess('sync')
                if err:
                    LOG.error('Error while sync exec: {0}'.format(err))
        except Exception as error:
            LOG.error('Error while sync exec: {0}'.format(error))

        mod_name = 'freezer.mode.{0}.{1}'.format(
            self.conf.mode, self.conf.mode.capitalize() + 'Mode')
        app_mode = importutils.import_object(mod_name, self.conf)
        backup_level = self.backup(app_mode)
        level = backup_level or 0

        metadata = {
            'curr_backup_level': level,
            'fs_real_path': self.conf.path_to_backup,
            'vol_snap_path': self.conf.path_to_backup,
            'client_os': sys.platform,
github openstack / freezer / freezer / mode / sqlserver.py View on Github external
def start_sql_server(self):
        """ Start the SQL Server instance after the backup is completed """

        with winutils.DisableFileSystemRedirection():
            cmd = 'net start "SQL Server ({0})"'.format(
                self.sql_server_instance)
            (out, err) = utils.create_subprocess(cmd)
            if err != '':
                raise Exception('Error while starting SQL Server'
                                ', error {0}'.format(err))
            LOG.info('SQL Server back to normal')
github openstack / freezer / freezer / mode / sqlserver.py View on Github external
def stop_sql_server(self):
        """ Stop a SQL Server instance to
        perform the backup of the db files """

        LOG.info('Stopping SQL Server for backup')
        with winutils.DisableFileSystemRedirection():
            cmd = 'net stop "SQL Server ({0})"'\
                .format(self.sql_server_instance)
            (out, err) = utils.create_subprocess(cmd)
            if err != '':
                raise Exception('Error while stopping SQL Server,'
                                ', error {0}'.format(err))
github openstack / freezer / freezer / snapshot / vss.py View on Github external
def vss_delete_shadow_copy(shadow_id, windows_volume):
    """
    Delete a shadow copy from the volume with the given shadow_id
    :param shadow_id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
    :return: bool
    """

    with winutils.DisableFileSystemRedirection():
        cmd = ['vssadmin', 'delete', 'shadows',
               '/shadow={0}'.format(shadow_id), '/quiet']
        (out, err) = utils.create_subprocess(cmd)
        if err != '':
            raise Exception('[*] Error deleting shadow copy with id {0}'
                            ', error {1}' .format(shadow_id, err))

        vss_delete_symlink(windows_volume)

        logging.info('[*] Deleting shadow copy {0}'.
                     format(shadow_id))

        return True