PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Leonardo Di Sarli   Nomad PHP ElasticSearch Backup and Restore   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Nomad PHP ElasticSearch Backup and Restore
Execute backup and restore on ElasticSearch to S3
Author: By
Last change:
Date: 4 months ago
Size: 976 bytes
 

Contents

Class file image Download
<?php

use ElasticNomad\Nomad;

require_once
'vendor/autoload.php';

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$validOperations = [
   
'backup',
   
'restore',
];
$operationsParams = [
   
'backup' => [
       
'index',
    ],
   
'restore' => [
       
'file_name',
    ],
];

$operation = $argv[1] ?? '';

if (!
in_array($operation, $validOperations)) {
    echo
'Please, use a valid operation: ' . implode(', ', $validOperations);
    die;
}

$params = array_slice(
   
$argv,
   
2
);

if (
    isset(
$operationsParams[$operation]) &&
   
count($params) < count($operationsParams[$operation])
) {
    echo
'Please, provide all the parameters: ' . implode(', ', $operationsParams[$operation]);
    die;
}

$options = [];
if (isset(
$operationsParams[$operation])) {
    foreach (
$operationsParams[$operation] as $index => $paramName) {
       
$options[$paramName] = $params[$index];
    }
}

$nomad = new Nomad();
$nomad->{$operation}($options);