withaspark/backblaze-sync

用于同步文件到 Backblaze B2 的脚本。

v1.0.2 2019-05-09 15:09 UTC

This package is auto-updated.

Last update: 2024-09-10 03:47:15 UTC


README

安装

  1. 按照这些说明安装 B2 CLI。
  2. 授权 B2 CLI。
    1. 登录 Backblaze UI。
    2. 访问存储桶页面并创建新的应用程序密钥(或使用现有的)。
    3. keyId 和显示的值中获取 applicationKeyIdapplicationKey 的值。
    4. 在终端中,通过替换 applicationKeyIdapplicationKey 来授权账户。
      b2 authorize-account <applicationKeyId> <applicationKey>
  3. 安装包。
    composer require withaspark/BackblazeSync

使用方法

命令行界面

path/to/backblaze_sync.php [-d|--dir <directory1> [-d|--dir <directory2> [...]]] <bucket>

代码

require __DIR__ . '/vendor/autoload.php';

$b2 = new withaspark\BackblazeSync\BackblazeSync($bucket, $local_dirs);

$existing = $b2->getExistingFiles(); // Get all files currently in bucket
$files = $b2->getFilesInDir(); // Get all files in local directory

$b2->deleteDuplicateRemoteFiles(); // Delete duplicate files in bucket

foreach ($files as $file) {
    $b2->upload($file); // Upload files if new
}

$b2->getUploadedCount(); // Get number of local files uploaded to B2 this run
$b2->getDeletedCount(); // Get number of remote files deleted from B2 this run