Browse Source

Added the ability to set the directory name on remote

morgan_chester 4 năm trước cách đây
mục cha
commit
57efdc1c83

+ 2 - 1
examples/yandex.php

@@ -8,7 +8,7 @@ require_once "vendor/autoload.php";
 
 /** Configuration */
 
-$directoryWithFilesMaskToScan = "/home/bitrix/www/bitrix/backup/*.tar.*";
+$directoryWithFilesMaskToScan = "www/files-to/backup/*.file.tar.*";
 $baseRemoteDirectoryPath = "/backups/";
 $token = "";
 
@@ -28,6 +28,7 @@ $options = new ProviderOptions\Yandex();
 $options->token = $token;
 $options->remoteDirectoryPath = $baseRemoteDirectoryPath;
 $options->fileWebPath = "https://your.site.there/backups/there/";
+$options->backupVersionDirName = date("Y-m-d");
 
 $yandexProvider = new Yandex($options);
 

+ 5 - 0
src/AutoBackup/ProviderOptions/Yandex.php

@@ -49,4 +49,9 @@ class Yandex extends ProviderOptions
      */
     public string $proxyPass;
 
+    /**
+     * @var string
+     */
+    public string $backupVersionDirName;
+
 }

+ 5 - 6
src/AutoBackup/Providers/Yandex.php

@@ -17,14 +17,12 @@ class Yandex extends BaseConnect
     private string $proxyServer;
     private int $proxyPort;
     private bool $consoleOutput;
-    /**
-     * @var string
-     */
     private string $fileWebPath;
     private array $logOutput;
     private bool $useProxy;
     private string $proxyUser;
     private string $proxyPass;
+    private string $backupVersionDirName;
 
     function __construct(ProviderOptions\Yandex $options)
     {
@@ -44,6 +42,8 @@ class Yandex extends BaseConnect
                 $this->proxyPass = $options->proxyPass;
             }
         }
+
+        $this->backupVersionDirName = isset($options->backupVersionDirName) ? $options->backupVersionDirName : date('Y-m-d');
     }
 
     private function stdOutput($stage, $message)
@@ -89,14 +89,13 @@ class Yandex extends BaseConnect
      */
     public function proceedBackup(array $resultFiles)
     {
-
-
         $baseRemoteDirectoryPath = $this->remoteDirectoryPath;
         $fileWebPath = rtrim($this->fileWebPath, '/');
+        $backupVersionDirName = $this->backupVersionDirName;
 
         if (!empty($resultFiles)) {
 
-            $dirName = $baseRemoteDirectoryPath . date('Y-m-d');
+            $dirName = $baseRemoteDirectoryPath . $backupVersionDirName;
 
             $createRemoteDirRequest = Request::put("https://cloud-api.yandex.net/v1/disk/resources?path=$dirName");
             $this->setCommonRequestParams($createRemoteDirRequest);