adachsoft / data-backup-filesystem
Filesystem-backed archive storage for AdachSoft Data Backup.
Package info
gitlab.com/a.adach/data-backup-filesystem
pkg:composer/adachsoft/data-backup-filesystem
Requires
- php: ^8.3
- adachsoft/data-backup: ^0.2 || ^0.3
- adachsoft/data-backup-contracts: ^0.2
- psr/http-factory: ^1.1
- psr/log: ^3.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- nyholm/psr7: ^1.8.2
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/data-backup-filesystem provides a local-filesystem implementation of ArchiveStorageInterface for adachsoft/data-backup. It stores archive data and manifests separately, supports listing, reading, and deleting archives, validates path segments, and requires no framework integration.
Requirements
- PHP 8.3 or later.
- Composer.
- A PSR-17 stream factory implementation.
Installation
Install this package with Composer:
composer require adachsoft/data-backup-filesystem
The example below uses Nyholm PSR-7. Applications may instead provide any compatible PSR-17 implementation:
composer require nyholm/psr7
Usage with BackupService
Replace ApplicationDataSourceRegistry with the registry used by your application. The example follows the core package's in-process backup wiring and supplies this package's filesystem storage to BackupService::backup().
use AdachSoft\DataBackup\InMemory\JsonArchiveFormat;
use AdachSoft\DataBackup\Serialization\ArchiveManifestCodec;
use AdachSoft\DataBackup\Service\BackupService;
use AdachSoft\DataBackup\Target\LocalBackupTarget;
use AdachSoft\DataBackupContracts\Collection\DataSourceIdCollection;
use AdachSoft\DataBackupContracts\Dto\ExportRequest;
use AdachSoft\DataBackupContracts\ValueObject\LabelMap;
use AdachSoft\DataBackupFilesystem\FilesystemArchiveStorage;
use DateTimeImmutable;
use DateTimeZone;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Clock\ClockInterface;
$streamFactory = new Psr17Factory();
$clock = new class implements ClockInterface {
public function now(): DateTimeImmutable
{
return new DateTimeImmutable('now', new DateTimeZone('UTC'));
}
};
$registry = new ApplicationDataSourceRegistry();
$format = new JsonArchiveFormat($streamFactory, $clock);
$target = new LocalBackupTarget(
$registry,
$format,
$streamFactory,
'my-application',
'production-eu-1',
'2.4.0',
);
$storage = new FilesystemArchiveStorage(
'filesystem',
'/var/lib/my-application/backups',
$streamFactory,
new ArchiveManifestCodec(),
);
$backupService = new BackupService($format, $streamFactory, null, null, $clock);
$archiveRef = $backupService->backup(
$target,
$storage,
new ExportRequest(new DataSourceIdCollection(), new LabelMap()),
);
An empty DataSourceIdCollection requests all registered sources. The returned ArchiveRef can be used to open or delete the archive through the same storage instance.
Storage layout and permissions
The storage root is created on the first save with mode 0700. Archive and manifest files are written with mode 0600 on platforms that support POSIX permissions.
{root}/{systemId}/{instanceId}/{archiveId}.archive
{root}/{systemId}/{instanceId}/{archiveId}.manifest.json
Archive, system, and instance identifiers used as path segments must match ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$. The manifest is committed after the archive data; listing ignores incomplete archives without a manifest, temporary files, and corrupt manifests (which are logged as warnings).
Logging
An optional PSR-3 logger can be passed as the fifth constructor argument. When omitted, the storage uses NullLogger.