コード例 #1
0
def main(args=None):
    """
    The main script entry point

    :param list[str] args: the raw arguments list. When not provided
        it defaults to sys.args[1:]
    """
    config = parse_arguments(args)
    configure_logging(config)
    try:
        conninfo = build_conninfo(config)
        postgres = PostgreSQLConnection(conninfo,
                                        config.immediate_checkpoint,
                                        application_name='barman_cloud_backup')
        try:
            postgres.connect()
        except PostgresConnectionError as exc:
            logging.error("Cannot connect to postgres: %s", force_str(exc))
            logging.debug('Exception details:', exc_info=exc)
            raise SystemExit(1)

        with closing(postgres):
            cloud_interface = CloudInterface(
                destination_url=config.destination_url,
                encryption=config.encryption,
                jobs=config.jobs,
                profile_name=config.profile)

            if not cloud_interface.test_connectivity():
                raise SystemExit(1)
            # If test is requested, just exit after connectivity test
            elif config.test:
                raise SystemExit(0)

            with closing(cloud_interface):

                # TODO: Should the setup be optional?
                cloud_interface.setup_bucket()

                uploader = S3BackupUploader(server_name=config.server_name,
                                            compression=config.compression,
                                            postgres=postgres,
                                            cloud_interface=cloud_interface)

                # Perform the backup
                uploader.backup()
    except KeyboardInterrupt as exc:
        logging.error("Barman cloud backup was interrupted by the user")
        logging.debug('Exception details:', exc_info=exc)
        raise SystemExit(1)
    except Exception as exc:
        logging.error("Barman cloud backup exception: %s", force_str(exc))
        logging.debug('Exception details:', exc_info=exc)
        raise SystemExit(1)
コード例 #2
0
ファイル: test_cloud.py プロジェクト: zombig/barman
 def test_setup_bucket(self, boto_mock):
     """
     Test if a bucket already exists
     """
     cloud_interface = CloudInterface('s3://bucket/path/to/dir',
                                      encryption=None)
     cloud_interface.setup_bucket()
     session_mock = boto_mock.Session.return_value
     s3_mock = session_mock.resource.return_value
     s3_client = s3_mock.meta.client
     # Expect a call on the head_bucket method of the s3 client.
     s3_client.head_bucket.assert_called_once_with(
         Bucket=cloud_interface.bucket_name)
コード例 #3
0
ファイル: cloud_backup.py プロジェクト: msonawane/barman
def main(args=None):
    """
    The main script entry point

    :param list[str] args: the raw arguments list. When not provided
        it defaults to sys.args[1:]
    """
    config = parse_arguments(args)
    configure_logging(config)
    postgres = None
    try:
        conninfo = build_conninfo(config)
        postgres = PostgreSQLConnection(conninfo, config.immediate_checkpoint)

        cloud_interface = CloudInterface(
            destination_url=config.destination_url,
            encryption=config.encryption,
            profile_name=config.profile)

        uploader = S3BackupUploader(server_name=config.server_name,
                                    compression=config.compression,
                                    postgres=postgres,
                                    cloud_interface=cloud_interface)

        # If test is requested just test connectivity and exit
        # TODO: add postgresql connectivity test
        if config.test:
            if cloud_interface.test_connectivity():
                raise SystemExit(0)
            raise SystemExit(1)

        # TODO: Should the setup be optional?
        cloud_interface.setup_bucket()

        # Perform the backup
        uploader.backup()
    except Exception as exc:
        logging.exception("Barman cloud backup exception: %s", exc)
        raise SystemExit(1)
    finally:
        if postgres:
            postgres.close()
コード例 #4
0
ファイル: cloud_walarchive.py プロジェクト: wenguoxing/barman
def main(args=None):
    """
    The main script entry point

    :param list[str] args: the raw arguments list. When not provided
        it defaults to sys.args[1:]
    """
    config = parse_arguments(args)
    configure_logging()

    # Validate the WAL file name before uploading it
    if not is_any_xlog_file(config.wal_path):
        logging.error('%s is an invalid name for a WAL file' % config.wal_path)
        raise SystemExit(1)

    try:
        cloud_interface = CloudInterface(
            destination_url=config.destination_url,
            encryption=config.encryption,
            profile_name=config.profile)

        with closing(cloud_interface):
            uploader = S3WalUploader(
                cloud_interface=cloud_interface,
                server_name=config.server_name,
                compression=config.compression)

            if not cloud_interface.test_connectivity():
                raise SystemExit(1)
            # If test is requested, just exit after connectivity test
            elif config.test:
                raise SystemExit(0)

            # TODO: Should the setup be optional?
            cloud_interface.setup_bucket()

            uploader.upload_wal(config.wal_path)
    except Exception as exc:
        logging.error("Barman cloud WAL archiver exception: %s",
                      force_str(exc))
        logging.debug('Exception details:', exc_info=exc)
        raise SystemExit(1)
コード例 #5
0
ファイル: test_cloud.py プロジェクト: zombig/barman
 def test_setup_bucket_create(self, boto_mock):
     """
     Test auto-creation of a bucket if it not exists
     """
     cloud_interface = CloudInterface('s3://bucket/path/to/dir',
                                      encryption=None)
     session_mock = boto_mock.Session.return_value
     s3_mock = session_mock.resource.return_value
     s3_client = s3_mock.meta.client
     # Simulate a 404 error from amazon for 'bucket not found'
     s3_client.head_bucket.side_effect = ClientError(
         error_response={'Error': {
             'Code': '404'
         }}, operation_name='load')
     cloud_interface.setup_bucket()
     bucket_mock = s3_mock.Bucket
     # Expect a call for bucket obj creation
     bucket_mock.assert_called_once_with(cloud_interface.bucket_name)
     # Expect the create() metod of the bucket object to be called
     bucket_mock.return_value.create.assert_called_once()
コード例 #6
0
def main(args=None):
    """
    The main script entry point

    :param list[str] args: the raw arguments list. When not provided
        it defaults to sys.args[1:]
    """
    config = parse_arguments(args)
    configure_logging()

    # Validate the WAL file name before uploading it
    file_name = os.path.basename(config.wal_path)
    if not is_any_xlog_file(os.path.splitext(file_name)[0]):
        logging.error('%s is an invalid name for a WAL file' % config.wal_path)
        raise SystemExit(1)

    try:
        cloud_interface = CloudInterface(
            destination_url=config.destination_url,
            encryption=config.encryption,
            profile_name=config.profile)

        uploader = S3WalUploader(cloud_interface=cloud_interface,
                                 server_name=config.server_name,
                                 compression=config.compression)

        # If test is requested just test connectivity and exit
        if config.test:
            if cloud_interface.test_connectivity():
                raise SystemExit(0)
            raise SystemExit(1)

        cloud_interface.setup_bucket()
        uploader.upload_wal(config.wal_path)
    except Exception as ex:
        logging.error("Barman cloud WAL archiver exception: %s", ex)
        raise SystemExit(1)
コード例 #7
0
def main(args=None):
    """
    The main script entry point

    :param list[str] args: the raw arguments list. When not provided
        it defaults to sys.args[1:]
    """
    config = parse_arguments(args)
    configure_logging(config)
    tempdir = tempfile.mkdtemp(prefix='barman-cloud-backup-')
    try:
        # Create any temporary file in the `tempdir` subdirectory
        tempfile.tempdir = tempdir

        conninfo = build_conninfo(config)
        postgres = PostgreSQLConnection(conninfo, config.immediate_checkpoint,
                                        application_name='barman_cloud_backup')
        try:
            postgres.connect()
        except PostgresConnectionError as exc:
            logging.error("Cannot connect to postgres: %s", force_str(exc))
            logging.debug('Exception details:', exc_info=exc)
            raise SystemExit(1)

        with closing(postgres):
            cloud_interface = CloudInterface(
                url=config.destination_url,
                encryption=config.encryption,
                jobs=config.jobs,
                profile_name=config.profile,
                endpoint_url=config.endpoint_url)

            if not cloud_interface.test_connectivity():
                raise SystemExit(1)
            # If test is requested, just exit after connectivity test
            elif config.test:
                raise SystemExit(0)

            with closing(cloud_interface):

                # TODO: Should the setup be optional?
                cloud_interface.setup_bucket()

                uploader = S3BackupUploader(
                    server_name=config.server_name,
                    compression=config.compression,
                    postgres=postgres,
                    max_archive_size=config.max_archive_size,
                    cloud_interface=cloud_interface)

                # Perform the backup
                uploader.backup()
    except KeyboardInterrupt as exc:
        logging.error("Barman cloud backup was interrupted by the user")
        logging.debug('Exception details:', exc_info=exc)
        raise SystemExit(1)
    except Exception as exc:
        logging.error("Barman cloud backup exception: %s", force_str(exc))
        logging.debug('Exception details:', exc_info=exc)
        raise SystemExit(1)
    finally:
        # Remove the temporary directory and all the contained files
        rmtree(tempdir, ignore_errors=True)