Documentation
¶
Overview ¶
Package storage provides an abstraction layer for backup archive storage.
The package supports two storage backends:
- Local filesystem (localstorage)
- AWS S3 (s3storage)
Storage Interface:
type Storage interface {
SaveFile(ctx context.Context, srcFilename, dstFilename string) error
Get(ctx context.Context, archiveName string) (string, error)
CreateBucket(ctx context.Context) error
}
Archive operations:
- ValidateArchive: Verify tar.gz format
- ExtractArchive: Extract archive to temporary directory (with path traversal protection)
Archives created by gitlab-backup contain:
- project.tar.gz - GitLab native export (includes repo, wiki, issues, MRs, labels)
Backward compatibility:
- Old archives with labels.json/issues.json are silently ignored
- Migration to GitLab native export completed in v2.0.0
Example usage:
// Local storage
storage, err := localstorage.New("/backup/path")
// S3 storage
storage, err := s3storage.New("my-bucket", "us-east-1", cfg)
// Validate and extract
if err := ValidateArchive(archivePath); err != nil {
log.Fatal(err)
}
contents, err := ExtractArchive(archivePath)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrArchiveNotFound is returned when archive file doesn't exist. ErrArchiveNotFound = errors.New("archive not found") // ErrArchiveIsDirectory is returned when archive path points to a directory. ErrArchiveIsDirectory = errors.New("archive path is a directory") // ErrArchiveEmpty is returned when archive file is empty. ErrArchiveEmpty = errors.New("archive is empty") )
Functions ¶
func ValidateArchive ¶ added in v1.16.0
ValidateArchive validates that a file is a valid tar.gz archive. It checks the file exists, is readable, and has valid gzip/tar format. It does NOT extract the archive.
Types ¶
type Archive ¶ added in v1.16.0
type Archive struct {
// Path is the local filesystem path or S3 key.
Path string
// StorageType indicates where the archive is stored (local or s3).
StorageType string
// Size is the archive file size in bytes.
Size int64
// ChecksumMD5 is the archive integrity checksum.
ChecksumMD5 string
// Contents is the extracted archive structure.
Contents *ArchiveContents
}
Archive represents a backup archive created by gitlab-backup.
type ArchiveContents ¶ added in v1.16.0
type ArchiveContents struct {
// ProjectExportPath is the path to GitLab native export archive.
ProjectExportPath string
// ExtractionDir is the temporary directory (unused but kept for API compatibility).
ExtractionDir string
}
ArchiveContents represents the contents of a backup archive.
func ExtractArchive ¶ added in v1.16.0
func ExtractArchive(ctx context.Context, archivePath string, destDir string) (*ArchiveContents, error)
ExtractArchive validates and returns the archive path for GitLab import. All archives created by gitlab-backup are direct GitLab exports and require no extraction.
Returns ArchiveContents with the archive path. The context is checked for cancellation before validation for consistency with other operations.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package localstorage provides local file system storage implementation.
|
Package localstorage provides local file system storage implementation. |
|
Package s3storage provides AWS S3 storage implementation.
|
Package s3storage provides AWS S3 storage implementation. |