Esempio n. 1
0
    def start_backup(self, backup_info):
        """
        Start of the backup.

        The method performs all the preliminary operations required for a
        backup to start.

        :param barman.infofile.BackupInfo backup_info: backup information
        """
        self.current_action = "connecting to database (%s)" % \
                              self.executor.config.conninfo
        output.debug(self.current_action)
        # with self.executor.server.pg_connect():
        # Retrieve PostgreSQL server metadata
        self._pg_get_metadata(backup_info)

        # Issue _pg_start_backup on the PostgreSQL server
        self.current_action = "issuing start backup command"
        _logger.debug(self.current_action)
        label = "Barman backup %s %s" % (
            backup_info.server_name, backup_info.backup_id)

        # Concurrent backup: issue a pgespresso_start_Backup() command

        postgres = self.executor.server.postgres
        start_row = postgres.pgespresso_start_backup(label)
        backup_data, start_time = start_row
        wal_re = re.compile(
            '^START WAL LOCATION: (.*) \(file (.*)\)',
            re.MULTILINE)
        wal_info = wal_re.search(backup_data)
        backup_info.set_attribute('status', "STARTED")
        backup_info.set_attribute('timeline',
                                  int(wal_info.group(2)[0:8], 16))
        backup_info.set_attribute('begin_xlog', wal_info.group(1))
        backup_info.set_attribute('begin_wal', wal_info.group(2))
        backup_info.set_attribute('begin_offset',
                                  xlog.get_offset_from_location(
                                      wal_info.group(1)))
        backup_info.set_attribute('backup_label', backup_data)
        backup_info.set_attribute('begin_time', start_time)
Esempio n. 2
0
 def test_get_offset_from_location(self):
     assert xlog.get_offset_from_location('0/1B0C7A0') == 11585440
     assert xlog.get_offset_from_location('9AFB/5B13FD70') == 1310064
     assert xlog.get_offset_from_location('9B02/29883178') == 8925560
     assert xlog.get_offset_from_location('BLAH') is None
Esempio n. 3
0
 def test_get_offset_from_location(self):
     assert xlog.get_offset_from_location('0/1B0C7A0') == 11585440
     assert xlog.get_offset_from_location('9AFB/5B13FD70') == 1310064
     assert xlog.get_offset_from_location('9B02/29883178') == 8925560
     assert xlog.get_offset_from_location('BLAH') is None
Esempio n. 4
0
    def start_backup(self, backup_info):
        """
        Start of the backup.

        The method performs all the preliminary operations required for a
        backup to start.

        :param barman.infofile.BackupInfo backup_info: the backup information
        """
        self.current_action = "connecting to database (%s)" % \
                              self.config.conninfo
        output.debug(self.current_action)
        with self.server.pg_connect():

            # Get the PostgreSQL data directory location
            self.current_action = 'detecting data directory'
            output.debug(self.current_action)
            data_directory = self.server.get_pg_setting('data_directory')
            backup_info.set_attribute('pgdata', data_directory)

            # Set server version
            backup_info.set_attribute('version', self.server.server_version)

            # Set configuration files location
            cf = self.server.get_pg_configuration_files()
            if cf:
                for key in sorted(cf.keys()):
                    backup_info.set_attribute(key, cf[key])

            # Get tablespaces information
            self.current_action = 'detecting tablespaces'
            output.debug(self.current_action)
            tablespaces = self.server.get_pg_tablespaces()
            if tablespaces and len(tablespaces) > 0:
                backup_info.set_attribute('tablespaces', tablespaces)
                for item in tablespaces:
                    msg = "\t%s, %s, %s" % (item.oid, item.name, item.location)
                    _logger.info(msg)

            # Issue pg_start_backup on the PostgreSQL server
            self.current_action = "issuing start backup command"
            _logger.debug(self.current_action)
            label = "Barman backup %s %s" % (
                backup_info.server_name, backup_info.backup_id)

            # Exclusive backup: issue a pg_start_Backup() command
            if BackupOptions.CONCURRENT_BACKUP not in \
                    self.config.backup_options:
                start_row = self.pg_start_backup(label)
                start_xlog, start_file_name, start_file_offset, start_time = \
                    start_row
                backup_info.set_attribute('status', "STARTED")
                backup_info.set_attribute('timeline',
                                          int(start_file_name[0:8], 16))
                backup_info.set_attribute('begin_xlog', start_xlog)
                backup_info.set_attribute('begin_wal', start_file_name)
                backup_info.set_attribute('begin_offset', start_file_offset)
                backup_info.set_attribute('begin_time', start_time)

            # Concurrent backup: use pgespresso extension to start a the backup
            else:
                start_row = self.pgespresso_start_backup(label)
                backup_data, start_time = start_row
                wal_re = re.compile(
                    '^START WAL LOCATION: (.*) \(file (.*)\)',
                    re.MULTILINE)
                wal_info = wal_re.search(backup_data)
                backup_info.set_attribute('status', "STARTED")
                backup_info.set_attribute('timeline',
                                          int(wal_info.group(2)[0:8], 16))
                backup_info.set_attribute('begin_xlog', wal_info.group(1))
                backup_info.set_attribute('begin_wal', wal_info.group(2))
                backup_info.set_attribute('begin_offset',
                                          xlog.get_offset_from_location(
                                              wal_info.group(1)))
                backup_info.set_attribute('backup_label', backup_data)
                backup_info.set_attribute('begin_time', start_time)