ウェブサイト検索

Rclone - 異なるクラウドストレージからファイルディレクトリを同期


Rclone は Go 言語で書かれたコマンド ライン プログラムで、Amazon Drive、Amazon S3、Backblaze B2、Box、Ceph、DigitalOcean Spaces、Dropbox、 FTP、Googleクラウドストレージ、Googleドライブなど

ご覧のとおり、これは複数のプラットフォームをサポートしているため、サーバー間でデータを同期したり、プライベート ストレージにデータを同期したりするのに便利なツールになります。

Rcloneには以下の機能が搭載されています

  • MD5/SHA1 ハッシュ チェックは常にファイルの整合性を確保するために行われます。
  • タイムスタンプはファイルに保存されます。
  • ファイル全体ベースで部分的な同期がサポートされています。
  • 新しいファイルまたは変更されたファイルのコピー モード。
  • 一方向同期によりディレクトリを同一にします。
  • チェックモード - ハッシュ等価性チェック。
  • 2 つの異なるクラウド アカウントなど、ネットワークとの間で同期できます。
  • (暗号化) バックエンド。
  • (キャッシュ) バックエンド。
  • (ユニオン) バックエンド。
  • オプションの FUSE マウント (rclone マウント)。

Linux システムに rclone をインストールする方法

rclone のインストールは 2 つの異なる方法で完了できます。より簡単な方法は、次のコマンドを発行してインストール スクリプトを使用することです。

curl https://rclone.org/install.sh | sudo bash

このスクリプトは、実行されている OS の種類を確認し、その OS に関連するアーカイブをダウンロードします。次に、アーカイブを抽出し、rclone バイナリを /usr/bin/rclone にコピーし、 ファイルに 755 のアクセス許可を与えます。

最終的に、インストールが完了すると、次の行が表示されるはずです。

Rclone v1.44 has successfully installed.
Now run “rclone config” for setup, Check https://rclone.org/docs/ for  more details.

rclone をインストールする 2 番目の方法は、次のコマンドを実行することです。

curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64

次に、バイナリ ファイルをコピーし、実行権限を与えます。

cp rclone /usr/bin/
chown root:root /usr/bin/rclone
chmod 755 /usr/bin/rclone

rclone マンページをインストールします。

mkdir -p /usr/local/share/man/man1
cp rclone.1 /usr/local/share/man/man1/
mandb 

Linux システムで rclone を構成する方法

次に行う必要があるのは、rclone config を実行して構成ファイルを作成することです。これは、 今後のrclone の使用のための認証に使用されます。構成セットアップを実行するには、次のコマンドを実行します。

rclone config

次のプロンプトが表示されます。

2018/11/13 11:39:58 NOTICE: Config file “/home/user/.config/rclone/rclone.conf” not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q>

オプションは次のとおりです。

  • n) – 新しいリモート接続を作成します
  • s) – 構成にパスワード保護を設定します
  • q) – 設定を終了します。

このチュートリアルでは、"n" を押して新しい接続を作成します。新しい接続に名前を付けるように求められます。その後、構成するストレージのタイプを選択するように求められます。

接続名を「Google 」 とし、番号12 の下にある「Google ドライブ 」 を選択しました。残りの質問は、デフォルトの回答である空の「 」 のままにするだけで回答できます。

要求されたら、「autoconfig」 を選択すると、Google ドライブ に接続するために必要な情報がすべて生成され、rclone にアクセス許可が与えられます。 Google ドライブのデータを使用します。

プロセスは次のようになります。

Google Application Client Secret - leave blank normally.
client_secret>
Scope that rclone should use when requesting access from drive.
Choose a number from below, or type in your own value
 1 / Full access all files, excluding Application Data Folder.
   \ "drive"
 2 / Read-only access to file metadata and file contents.
   \ "drive.readonly"
   / Access to files created by rclone only.
 3 | These are visible in the drive website.
   | File authorization is revoked when the user deauthorizes the app.
   \ "drive.file"
   / Allows read and write access to the Application Data folder.
 4 | This is not visible in the drive website.
   \ "drive.appfolder"
   / Allows read-only access to file metadata but
 5 | does not allow any access to read or download file content.
   \ "drive.metadata.readonly"
scope> 1
ID of the root folder - leave blank normally.  Fill in to access "Computers" folders. (see docs).
root_folder_id> 
Service Account Credentials JSON file path - needed only if you want use SA instead of interactive login.
service_account_file>
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine or Y didn't work
y) Yes
n) No
y/n> y
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
Log in and authorize rclone for access
Waiting for code...
Got code
Configure this as a team drive?
y) Yes
n) No
y/n> n
--------------------
[remote]
client_id = 
client_secret = 
scope = drive
root_folder_id = 
service_account_file =
token = {"access_token":"XXX","token_type":"Bearer","refresh_token":"XXX","expiry":"2018-11-13T11:57:58.955387075Z"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

Linux システムで rclone を使用する方法

Rclone には、使用可能なオプションとコマンドの非常に長いリストがあります。より重要なものをいくつか取り上げていきます。

リモートディレクトリの一覧表示

rclone lsd <remote-dir-name>:

rclone を使用してデータをコピーする

rclone copy source:sourcepath dest:destpath

rclone が重複を見つけた場合、それらは無視されることに注意してください。

rclone とデータを同期する

ディレクトリ間でデータを同期したい場合は、rclonesync コマンドを使用する必要があります。

コマンドは次のようになります。

rclone sync source:path dest:path [flags]

この場合、ソースは宛先に同期され、宛先のみが変更されます。このメソッドは、変更されていないファイルをスキップします。このコマンドはデータ損失を引き起こす可能性があるため、「–dry-run」 と組み合わせて使用すると、正確に何がコピーおよび削除されるかを確認できます。

rclone を使用してデータを移動する

データを移動するには、rclonemove コマンドを使用します。コマンドは次のようになります。

rclone move source:path dest:path [flags]

ソースのコンテンツが移動 (削除) され、選択した宛先に配置されます。

その他の便利な rclone コマンド

宛先にディレクトリを作成します。

rclone mkdir remote:path

ディレクトリを削除するには。

rclone rmdir remote:path

ソースと宛先のファイルが一致するかどうかを確認します。

rclone check source:path dest:path

ファイルを削除します:

rclone delete remote:path

各 rclone コマンドはさまざまなフラグとともに使用でき、独自のヘルプ メニューが含まれています。たとえば、削除オプションを使用して選択的な削除を実行できます。 100M を超えるファイルを削除したい場合、コマンドは次のようになります。

rclone --min-size 100M delete remote:path

rclone を最大限に活用するために、各コマンドのマニュアルとヘルプを確認することを強くお勧めします。 rclone の完全なドキュメントは、https://rclone.org/ で入手できます。

結論

rclone は、異なるクラウド ストレージ プロバイダ間のデータ管理に役立つ強力なコマンド ライン ユーティリティです。この記事ではrclone 機能のほんの一部を紹介しましたが、特に cron サービスと組み合わせて使用すると、さらに多くのことが実現できます (たとえば)。