Skip to content
A script for syncing files to Backblaze B2.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
backblaze_sync.php
composer.json

README.md

withaspark/BackblazeSync

Install

  1. Install B2 CLI following these instructions.
  2. Authorize B2 CLI.
    1. Login to Backblaze UI.
    2. Visit buckets page and create new application key (or use existing).
    3. Get values of applicationKeyId and applicationKey from the keyId and displayed value, respectively.
    4. In terminal, authorize account by substituting for applicationKeyId and applicationKey.
      b2 authorize-account <applicationKeyId> <applicationKey>
  3. Install package.
    composer require withaspark/BackblazeSync

Usage

CLI

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

Code

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
You can’t perform that action at this time.