Categorygithub.com/aerospike/backup-go
modulepackage
0.3.1
Repository: https://github.com/aerospike/backup-go.git
Documentation: pkg.go.dev

# README

backup-go

Tests PkgGoDev codecov

A Go library for backing up and restoring Aerospike data.

Design

This Aerospike backup package is built around the Aerospike Go client. The package uses a client structure to start backup and restore jobs. The client structure is thread safe, backup and restore jobs can be started in multiple goroutines. When the client is used to start backup and restore jobs, a handler is immediately returned that is used to check the job's status, errors, and wait for it to finish. Here is how to use the package at a high level.

  • Wrap Aerospike Go clients with the backup package Client object.
  • Start backup and restore jobs using that backup client. These client methods return a handler which is used to monitor the started job. Started jobs run in parallel.
  • Use the returned handlers to monitor the started jobs.

Usage

The following is a simple example using a backup client to start backup and restore jobs. Errors should be properly handled in production code.

package main

import (
	"context"
	"log"

	"github.com/aerospike/aerospike-client-go/v7"
	"github.com/aerospike/backup-go"
	"github.com/aerospike/backup-go/io/encoding/asb"
	"github.com/aerospike/backup-go/io/local"
)

func main() {
	aerospikeClient, aerr := aerospike.NewClient("127.0.0.1", 3000)
	if aerr != nil {
		panic(aerr)
	}

	backupClient, err := backup.NewClient(aerospikeClient, backup.WithID("client_id"))
	if err != nil {
		panic(err)
	}

	// For backup to single file use local.WithFile(fileName)
	writers, err := local.NewWriter(
		context.Background(),
		local.WithRemoveFiles(),
		local.WithDir("backups_folder"),
	)
	if err != nil {
		panic(err)
	}

	backupCfg := backup.NewDefaultBackupConfig()
	backupCfg.Namespace = "test"
	backupCfg.ParallelRead = 10
	backupCfg.ParallelWrite = 10
	ctx := context.Background()

	backupHandler, err := backupClient.Backup(ctx, backupCfg, writers, nil)
	if err != nil {
		panic(err)
	}

	// Use backupHandler.Wait(ctx) to wait for the job to finish or fail.
	// You can use different context here, and if it is canceled
	// backupClient.Backup(ctx, backupCfg, writers) context will be cancelled too.
	err = backupHandler.Wait(ctx)
	if err != nil {
		log.Printf("Backup failed: %v", err)
	}

	restoreCfg := backup.NewDefaultRestoreConfig()
	restoreCfg.Parallel = 5

	// For restore from single file use local.WithFile(fileName)
	reader, err := local.NewReader(
		local.WithValidator(asb.NewValidator()),
		local.WithDir("backups_folder"),
	)
	if err != nil {
		panic(err)
	}

	restoreHandler, err := backupClient.Restore(ctx, restoreCfg, reader)
	if err != nil {
		panic(err)
	}

	// Use restoreHandler.Wait(ctx) to wait for the job to finish or fail.
	// You can use different context here, and if it is canceled
	// backupClient.Restore(ctx, restoreCfg, streamingReader) context will be cancelled too.
	err = restoreHandler.Wait(ctx)
	if err != nil {
		log.Printf("Restore failed: %v", err)
	}

	// optionally check the stats of the restore job
	_ = restoreHandler.GetStats()
}

More examples can be found under the examples folder.

Prerequisites

Requirements

Testing Requirements

Installation

  1. Install requirements.
  2. Use go get https://github.com/aerospike/backup-go

License

The Aerospike Backup package is made available under the terms of the Apache License, Version 2, as stated in the file LICENSE.

Individual files may be made available under their own specific license, all compatible with Apache License, Version 2. Please see individual files for details.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

NewClient creates a new backup client.
NewCompressionPolicy returns new compression policy for backup/restore operations.
NewDecoder returns a new Decoder according to `EncoderType`.
NewDefaultBackupConfig returns a new BackupConfig with default values.
NewDefaultRestoreConfig returns a new RestoreConfig with default values.
NewEncoder returns a new Encoder according to `EncoderType`.
NewPartitionFilterAfterDigest returns partition filter to scan call records after digest.
NewPartitionFilterAll returns a partition range containing all partitions.
NewPartitionFilterByDigest returns a partition filter by digest with specified value.
NewPartitionFilterByID returns a partition filter by id with specified id.
NewPartitionFilterByRange returns a partition range with boundaries specified by the provided values.
NewState returns new state instance depending on config.
ParseSecret check if string contains secret and tries to load secret from secret agent.
ReadPrivateKey parses and loads a private key according to the EncryptionPolicy configuration.
WithID sets the ID for the [Client].
WithLogger sets the logger for the [Client].
WithScanLimiter sets the scan limiter for the [Client].

# Constants

CompressNone no compression.
CompressZSTD compression using ZSTD.
EncoderTypeASB matches ASB Encoder with id 0.
EncryptAES128 encryption using AES128 algorithm.
EncryptAES256 encryption using AES256 algorithm.
EncryptNone no encryption.
MaxParallel is the maximum number of workers to use during an operation.
MaxPartitions is the maximum number of partitions in an Aerospike cluster.
MinParallel is the minimum number of workers to use during an operation.

# Structs

BackupConfig contains configuration for the backup operation.
BackupHandler handles a backup job.
Client is the main entry point for the backup package.
CompressionPolicy contains backup compression information.
EncryptionPolicy contains backup encryption information.
RestoreConfig contains configuration for the restore operation.
RestoreHandler handles a restore job using the given reader.
RestoreNamespaceConfig specifies an alternative namespace name for the restore operation, where Source is the original namespace name and Destination is the namespace name to which the backup data is to be restored.
SecretAgentConfig contains Secret Agent connection information.
State contains current backups status data.

# Interfaces

AerospikeClient describes aerospike client interface for easy mocking.
Decoder is an interface for reading backup data as tokens.
Encoder is an interface for encoding the types from the models package.
StreamingReader provides access to data that should be restored.
Writer provides access to backup storage.

# Type aliases

ClientOpt is a functional option that allows configuring the [Client].
EncoderType custom type for Encoder types enum.