Oihana PHP Arango

ArangoRestoreAction uses trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, \oihana\commands\traits\EncryptTrait

The command to manage an ArangoDB database.

Table of Contents

Constants

ARANGO_RESTORE  : string = 'arangorestore'
The arango restore command.
ARCHIVE_REGEXP  : string = \oihana\arango\commands\enums\ArchivePattern::R...
The regexp to find the archive file.
PARTIAL_MARKER  : string = 'partial'
Marker appended to the archive name when the dump targets a subset of collections (either `--collection` or `--ignore-collection`).

Properties

$directory  : string|null
The dump/restore directory.
$exit  : string
The exit message.
$dumpConfig  : array<string|int, mixed>
The `[arango.dump]` config defaults (option name => value).
$profiles  : array<string|int, mixed>
The declared named profiles, from the `[arango.profiles]` config section.
$restoreConfig  : array<string|int, mixed>
The `[arango.restore]` config defaults (option name => value).

Methods

arangoRestore()  : int
Run the 'arangorestore' command to restore the ArangoDB database.
getArangoRestoreArguments()  : array<int, string>
Builds the `arangorestore` argument vector (argv[0] = binary name).
initializeArangoOptions()  : static
Captures the `[arango.dump]` / `[arango.restore]` config sections from the init array. Non-array values are ignored, leaving the defaults empty.
initializeArangoProfiles()  : static
Captures the `[arango.profiles]` config section from the init array.
initializeDirectory()  : static
Initializes the dump/restore directory from an init array.
profileConnection()  : array<string|int, mixed>
The optional **source** connection carried by a profile (dump only).
profileDirectory()  : string|null
The optional output **directory** carried by a profile (dump only).
profileExclude()  : array<string|int, mixed>
The `exclude` list of a profile.
profilePositive()  : array<string|int, mixed>
The positive selection of a profile — `collections` + `edges` merged.
profileSelection()  : array<string|int, mixed>
The effective collection list of a profile.
resolveProfile()  : array<string|int, mixed>|null
Resolves the `--profile` value to a profile array.
restore()  : int
Restore the ArangoDB database.
assertCollectionTargeting()  : void
Asserts that `--collection` and `--ignore-collection` are not used together — `arangodump` rejects that combination.
excludeCollections()  : array<int, string>
Returns the available collection names minus the excluded ones, order-preserving (case-sensitive).
getArchiveFileSuffix()  : string
Builds the archive file name suffix used to locate a dump by date.
getArchiveNameSuffix()  : string
Builds the archive name suffix (without file extension) shared by the dump output name and the restore-by-date lookup.
isSystemCollection()  : bool
Returns true when the given name is an ArangoDB system collection (its name starts with an underscore, e.g. `_jobs`, `_apps`).
listDumps()  : int
List the dump files of the database.
missingCollections()  : array<int, string>
Returns the requested collection names that are NOT present in the available set (case-sensitive, as ArangoDB collection names are).
normalizeCollections()  : array<int, string>
Normalizes a raw collection option into a clean, de-duplicated, order-preserving list of collection names.
resolveDumpOptions()  : array<string|int, mixed>
Layers the explicit dump options over the `[arango.dump]` config defaults, then lets the curated CLI flags override everything.
resolveRestoreOptions()  : array<string|int, mixed>
Layers the explicit restore options over the `[arango.restore]` config defaults, then lets the curated CLI flags override everything.
restoreProtectedCollections()  : array<int, string>
The collection names the `restore` action refuses to overwrite unless `--force` is passed, read from the `protected` key of the `[arango.restore]` config section ({@see ArangoCommandParam::PROTECTED}).
sanitizeLabel()  : string|null
Validates and normalizes the optional archive label.
archiveCollections()  : array<int, string>
The collection names declared by the `*.structure.json` files of an untarred dump — the universe used by an exclude-only profile on restore.
isLocalEndpoint()  : bool
True when an ArangoDB endpoint targets the local machine.
looksLikePath()  : bool
True when a `--profile` value designates an external `.toml` file rather than a named section.
normalizeProfileList()  : array<string|int, mixed>
Flattens a profile list value: arrays and comma-separated strings → a clean, de-duplicated list of trimmed names.
restoreSelectionLabel()  : string
A human-readable description of the restore selection, for `--dry-run` (the exact exclude-only list is only known once the archive is untarred).

Constants

ARANGO_RESTORE

The arango restore command.

public string ARANGO_RESTORE = 'arangorestore'

ARCHIVE_REGEXP

The regexp to find the archive file.

public string ARCHIVE_REGEXP = \oihana\arango\commands\enums\ArchivePattern::REGEXP

PARTIAL_MARKER

Marker appended to the archive name when the dump targets a subset of collections (either `--collection` or `--ignore-collection`).

public string PARTIAL_MARKER = 'partial'

Properties

$directory

The dump/restore directory.

public string|null $directory = null

$dumpConfig

The `[arango.dump]` config defaults (option name => value).

protected array<string|int, mixed> $dumpConfig = []

$profiles

The declared named profiles, from the `[arango.profiles]` config section.

protected array<string|int, mixed> $profiles = []

$restoreConfig

The `[arango.restore]` config defaults (option name => value).

protected array<string|int, mixed> $restoreConfig = []

Methods

arangoRestore()

Run the 'arangorestore' command to restore the ArangoDB database.

public arangoRestore([array<string|int, mixed>|ArangoRestoreOptions|null $options = null ][, bool $silent = false ]) : int
Parameters
$options : array<string|int, mixed>|ArangoRestoreOptions|null = null

The arangorestore options definition.

$silent : bool = false

Indicates if the command is invoked silently.

Tags
throws
ReflectionException
Return values
int

getArangoRestoreArguments()

Builds the `arangorestore` argument vector (argv[0] = binary name).

public getArangoRestoreArguments([array<string|int, mixed>|ArangoRestoreOptions|null $options = null ]) : array<int, string>

The vector is executed without a shell (see ArangoProcessTrait::runProcess()), so option values are passed verbatim and never re-interpreted.

Parameters
$options : array<string|int, mixed>|ArangoRestoreOptions|null = null
Tags
throws
ReflectionException
Return values
array<int, string>

initializeArangoOptions()

Captures the `[arango.dump]` / `[arango.restore]` config sections from the init array. Non-array values are ignored, leaving the defaults empty.

public initializeArangoOptions([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []
Return values
static

initializeArangoProfiles()

Captures the `[arango.profiles]` config section from the init array.

public initializeArangoProfiles([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []
Return values
static

initializeDirectory()

Initializes the dump/restore directory from an init array.

public initializeDirectory([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []

The init definition, possibly containing ArangoCommandParam::DIRECTORY.

Return values
static

profileConnection()

The optional **source** connection carried by a profile (dump only).

public profileConnection(array<string|int, mixed> $profile) : array<string|int, mixed>
Parameters
$profile : array<string|int, mixed>
Return values
array<string|int, mixed>

The present connection keys among endpoint/database/user/password.

profileDirectory()

The optional output **directory** carried by a profile (dump only).

public profileDirectory(array<string|int, mixed> $profile) : string|null

When set, a dump using this profile writes its archive here unless the --directory CLI flag overrides it. The restore action ignores this key — it always writes to the local target.

Parameters
$profile : array<string|int, mixed>
Return values
string|null

The directory, or null when absent or not a string.

profileExclude()

The `exclude` list of a profile.

public profileExclude(array<string|int, mixed> $profile) : array<string|int, mixed>
Parameters
$profile : array<string|int, mixed>
Return values
array<string|int, mixed>

profilePositive()

The positive selection of a profile — `collections` + `edges` merged.

public profilePositive(array<string|int, mixed> $profile) : array<string|int, mixed>
Parameters
$profile : array<string|int, mixed>
Return values
array<string|int, mixed>

profileSelection()

The effective collection list of a profile.

public profileSelection(array<string|int, mixed> $profile[, array<string|int, mixed> $allCollections = [] ]) : array<string|int, mixed>

A positive selection minus exclude; when the positive list is empty, $allCollections (the universe) minus exclude.

Parameters
$profile : array<string|int, mixed>
$allCollections : array<string|int, mixed> = []

The universe used for an exclude-only profile.

Return values
array<string|int, mixed>

resolveProfile()

Resolves the `--profile` value to a profile array.

public resolveProfile(string|null $profile) : array<string|int, mixed>|null

A path-like value (absolute, containing a separator, or ending in .toml) is loaded as an external file; otherwise it is looked up among the declared named profiles.

Parameters
$profile : string|null
Return values
array<string|int, mixed>|null

Null when no profile is requested.

restore()

Restore the ArangoDB database.

public restore(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Tags
throws
DirectoryException
ExitException
FileException
MissingPassphraseException
Return values
int

assertCollectionTargeting()

Asserts that `--collection` and `--ignore-collection` are not used together — `arangodump` rejects that combination.

protected static assertCollectionTargeting(array<int, string> $collection, array<int, string> $ignore) : void
Parameters
$collection : array<int, string>
$ignore : array<int, string>
Tags
throws
InvalidArgumentException

When both lists are non-empty.

excludeCollections()

Returns the available collection names minus the excluded ones, order-preserving (case-sensitive).

protected static excludeCollections(array<int, string> $available, array<int, string> $exclude) : array<int, string>

Used to resolve --ignore-collection client-side: arangodump has no exclusion option, so the complement is computed here and passed back as an explicit --collection list.

Parameters
$available : array<int, string>

The collections that exist.

$exclude : array<int, string>

The collections to drop.

Return values
array<int, string>

getArchiveFileSuffix()

Builds the archive file name suffix used to locate a dump by date.

protected static getArchiveFileSuffix(string $database[, bool $encrypt = false ][, bool $partial = false ][, string|null $label = null ]) : string

The dump action always produces a gzip-compressed tarball ({date}-{database}[-partial][-{label}].tar.gz), optionally AES-encrypted (….tar.gz.enc). This helper mirrors that naming so a targeted dump can be located by --date (the caller must pass the same --collection/--ignore-collection and --label it dumped with). The name part is delegated to getArchiveNameSuffix().

Parameters
$database : string

The database name embedded in the suffix.

$encrypt : bool = false

Whether the archive is encrypted.

$partial : bool = false

Whether the dump targets a subset of collections.

$label : string|null = null

Optional label appended to the name.

Return values
string

e.g. -mydb.tar.gz, -mydb-partial.tar.gz or -mydb-partial-pre-migration.tar.gz.enc.

getArchiveNameSuffix()

Builds the archive name suffix (without file extension) shared by the dump output name and the restore-by-date lookup.

protected static getArchiveNameSuffix(string $database[, bool $partial = false ][, string|null $label = null ]) : string

Shape: -{database}[-partial][-{label}], e.g.

  • -mydb (full dump)
  • -mydb-partial (targeted dump, no label)
  • -mydb-partial-pre-migration (targeted dump with a label)
Parameters
$database : string

The database name.

$partial : bool = false

Whether the dump targets a subset of collections.

$label : string|null = null

Optional label (validated via sanitizeLabel()).

Tags
throws
InvalidArgumentException

When the label is invalid.

Return values
string

isSystemCollection()

Returns true when the given name is an ArangoDB system collection (its name starts with an underscore, e.g. `_jobs`, `_apps`).

protected static isSystemCollection(string $name) : bool
Parameters
$name : string
Return values
bool

listDumps()

List the dump files of the database.

protected listDumps(InputInterface $input, OutputInterface $output[, string|null $directory = null ]) : int

The listed directory follows the same precedence as the dump and the prune: the --directory CLI flag wins, then the optional $directory (e.g. a profile output directory resolved by the caller), then the global $this->directory.

Parameters
$input : InputInterface
$output : OutputInterface
$directory : string|null = null

An optional directory override (the profile output directory), below the --directory CLI flag and above the global directory.

Tags
throws
DirectoryException
Return values
int

missingCollections()

Returns the requested collection names that are NOT present in the available set (case-sensitive, as ArangoDB collection names are).

protected static missingCollections(array<int, string> $requested, array<int, string> $available) : array<int, string>

Order-preserving and de-duplicated.

Parameters
$requested : array<int, string>

The collections asked for on the CLI.

$available : array<int, string>

The collections that actually exist.

Return values
array<int, string>

The unknown collection names (empty when all exist).

normalizeCollections()

Normalizes a raw collection option into a clean, de-duplicated, order-preserving list of collection names.

protected static normalizeCollections(array<int|string, mixed> $raw) : array<int, string>

Accepts both syntaxes (and any mix):

  • repeated flags : ['users', 'products']
  • comma-separated : ['users,products']
  • mixed/with spaces : [' users , products ', 'customers']

Empty fragments are dropped; the first occurrence order is kept.

Parameters
$raw : array<int|string, mixed>
Return values
array<int, string>

resolveDumpOptions()

Layers the explicit dump options over the `[arango.dump]` config defaults, then lets the curated CLI flags override everything.

protected resolveDumpOptions(array<string|int, mixed> $explicit, InputInterface $input) : array<string|int, mixed>
Parameters
$explicit : array<string|int, mixed>

The options resolved by the action (connection, output directory, collection targeting).

$input : InputInterface

The current console input.

Return values
array<string|int, mixed>

resolveRestoreOptions()

Layers the explicit restore options over the `[arango.restore]` config defaults, then lets the curated CLI flags override everything.

protected resolveRestoreOptions(array<string|int, mixed> $explicit, InputInterface $input) : array<string|int, mixed>
Parameters
$explicit : array<string|int, mixed>

The options resolved by the action (connection, input directory, create flags, collection targeting).

$input : InputInterface

The current console input.

Return values
array<string|int, mixed>

restoreProtectedCollections()

The collection names the `restore` action refuses to overwrite unless `--force` is passed, read from the `protected` key of the `[arango.restore]` config section ({@see ArangoCommandParam::PROTECTED}).

protected restoreProtectedCollections() : array<int, string>

Non-array values and non-string entries are ignored.

Return values
array<int, string>

sanitizeLabel()

Validates and normalizes the optional archive label.

protected static sanitizeLabel(string|null $label) : string|null

Returns null for a null/empty value. Otherwise the label must only contain letters, digits, dot, underscore and hyphen so it stays safe inside a filename.

Parameters
$label : string|null
Tags
throws
InvalidArgumentException

When the label contains unsafe characters.

Return values
string|null

archiveCollections()

The collection names declared by the `*.structure.json` files of an untarred dump — the universe used by an exclude-only profile on restore.

private archiveCollections(string $directory) : array<int, string>
Parameters
$directory : string

The untarred dump directory.

Return values
array<int, string>

isLocalEndpoint()

True when an ArangoDB endpoint targets the local machine.

private isLocalEndpoint(string|null $endpoint) : bool

The host is extracted from the endpoint (e.g. tcp://127.0.0.1:8529, ssl://localhost:8529, http+tcp://[::1]:8529) and matched against the loopback names. Anything else — a remote host or an unparsable value — is treated as non-local, so the restore warns rather than staying silent.

Parameters
$endpoint : string|null
Return values
bool

looksLikePath()

True when a `--profile` value designates an external `.toml` file rather than a named section.

private looksLikePath(string $value) : bool
Parameters
$value : string
Return values
bool

normalizeProfileList()

Flattens a profile list value: arrays and comma-separated strings → a clean, de-duplicated list of trimmed names.

private normalizeProfileList(mixed $raw) : array<string|int, mixed>
Parameters
$raw : mixed
Return values
array<string|int, mixed>

restoreSelectionLabel()

A human-readable description of the restore selection, for `--dry-run` (the exact exclude-only list is only known once the archive is untarred).

private restoreSelectionLabel(array<string|int, mixed>|null $profile, array<string|int, mixed> $collection) : string
Parameters
$profile : array<string|int, mixed>|null
$collection : array<string|int, mixed>

The CLI --collection selection.

Return values
string
On this page

Search results