クラウドストレージとrcloneを活用してうまいことバックアップを取る¶
実験データのバックアップは必ず取るようにしないといけない
けど毎度Finderとかでコピー&ペーストしたり、ブラウザ上でクラウドにアップロードなんてのはめんどくさい
かと言って大容量の外付けディスクを用意するのもめんどくさい
コマンドライン上で1クリックでクラウドと同期が取れればいいが、認証の問題とかでそう簡単にできそうにない
そんな時rclone
というライブラリがあったので使ってみることにした
ここは導入から安定同期までの記録を書き留める
使えるクラウドストレージ¶
rclone
はだいたいのクラウドサービスに対応している。
対応するクラウドはOfficial Documentationに書いてある
対して、自分の所属する研究室ではOneDrive
とNextCloud
が利用可能
いずれもrclone
で利用できる(NextCloud
はWebDAV
経由)からまずは問題なさそう
rclone
の導入と初期設定¶
macOSの場合、brew
でインストール可能
brew install rclone
でインストール
rclone config
で設定ファイルを編集できる、まずはOneDriveで設定したいため、このドキュメント通りに進める。
途中、ブラウザ経由で認証を求められるため、ブラウザ側で予め自分のアカウントにログインしている必要がある(かはわからないが、その方がスムーズ)
最後までいったら動作確認でrclone config show
と打ってみると、さっき設定したクラウドの変数たちが見える
一番上のかっこで囲われた[name]の部分がサービスの名前
これを用いてrclone about name:
やrclone lsd name:
と打つとクラウド上のファイルが確認できる
同期する¶
使い方はbashコマンドとほぼ一緒
rclone sync -P 同期元 [name]:同期先
同期元のディレクトリ(ファイル)を同期先に一致させる。
この時、同期先のファイルは同期元のファイルで上書きされてしまうことに注意
rclone bisync -P 同期元 [name]:同期先
同期元と同期先のディレクトリ(ファイル)を一致させる。
同期先での変更が同期元に反映される。
必要であれば--dry-run
などをつけて動作確認、双方間同期コマンドのrclone bisync
などを使うこと
rclone copy -P 同期元 [name]:同期先
同期元と同期先で同じファイルはスキップするようコピーする。
この時、同期元で削除したファイルは同期先で削除されないため、同期先の容量はどんどん膨らんでいることに注意
rclone copy -P --max-age 24h --no-traverse 同期元 [name]:同期先
同期元に多くのファイルがあり、毎日変更されるのはそのうちの数個だけなら、以下のように最近変更されたファイルをすべてコピーすると非常に効率的
差分を取る¶
差分を取らないのであればブラウザ経由でアップロードすればいい、そっちの方が楽
ファイルがあるかどうか確認する際は
rclone check source:path dest:path --size-only --combined -
ファイルの中身まで確認したい場合は
rclone check source:path dest:path --downroad --combined -
OneDrive の設定手順詳細¶
初期の設定は以下のとおり
$rclone config
Current remotes:
Name Type
==== ====
NextCloud webdav
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> n
name> OneDrive
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
*** 略 ***
28 / Microsoft OneDrive
\ (onedrive)
*** 略 ***
Storage> 28
Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_id> **空欄**
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret> **空欄**
Option region.
Choose national cloud region for OneDrive.
Choose a number from below, or type in your own string value.
Press Enter for the default (global).
***
1 / Microsoft Cloud Global
\ (global)
***
region> 1
Edit advanced config?
y) Yes
n) No (default)
y/n> n
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> y
***
ここでyesを選択すると勝手にwebpageが開いて認証画面に進める
***
2022/11/02 15:21:09 NOTICE: If your browser doesn't open automatically go to the following link: http://hogehoge
2022/11/02 15:21:09 NOTICE: Log in and authorize rclone for access
2022/11/02 15:21:09 NOTICE: Waiting for code...
2022/11/02 15:21:12 NOTICE: Got code
Option config_type.
Type of connection
Choose a number from below, or type in an existing string value.
Press Enter for the default (onedrive).
*** 略 ***
1 / OneDrive Personal or Business
\ (onedrive)
*** 略 ***
config_type> 1
Drive OK?
Found drive "root" of type "business"
URL: https://hogehoge
y) Yes (default)
n) No
y/n>
--------------------
[OneDrive]
type = onedrive
token = {"access_token":"hogehoge"}
drive_id = hogehoge
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:
Name Type
==== ====
NextCloud webdav
OneDrive onedrive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q
NextCloudの設定手順詳細¶
nextcloudはWebDAV経由で接続するからOneDriveよりちょっと手間がかかる
name
rcloneで接続するときに使う識別子、好きな文字列を書き込むType of storage
ストレージの種類を選択、ここではWebDAVを選択URL of http host
WebDAV のURL、φ研のアカウントでNextCloudにログイン後、左下の設定を押すとアドレスが表示される。User name & Password NextCloudのアカウントにログインする、ブラウザ上のφ研のNexCloudにて、
- 右上のアイコン
- 設定
- セキュリティ
- デバイスとセッション
- 新しいアプリパスワードを生成、ここでアプリ名は適当にrcloneとでも入れておくといい
- 生成されたIDとパスワードをrcloneの設定に打ち込む
bearer_token
空欄
設定が完了してCurrent Remotesに今設定した接続があればよし
% rclone lsd NextCloud:
コマンド等で接続を確認する
以下にrclone
設定の画面をそのまま残す
% rclone config
Current remotes:
Name Type
==== ====
OneDrive onedrive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> n
name> NextCloud
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
...[略]...
41 / Webdav
\ (webdav)
...[略]...
Storage> 41
Option url.
URL of http host to connect to.
E.g. https://example.com.
Enter a value.
url> https://nuss.phi.phys.nagoya-u.ac.jp/nuss/remote.php/dav/files/fujiie/
Option vendor.
Name of the Webdav site/service/software you are using.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
1 / Nextcloud
\ (nextcloud)
2 / Owncloud
\ (owncloud)
3 / Sharepoint Online, authenticated by Microsoft account
\ (sharepoint)
4 / Sharepoint with NTLM authentication, usually self-hosted or on-premises
\ (sharepoint-ntlm)
5 / Other site/service or software
\ (other)
vendor> 1
Option user.
User name.
In case NTLM authentication is used, the username should be in the format 'Domain\User'.
Enter a value. Press Enter to leave empty.
user> fujiie
Option pass.
Password.
Choose an alternative below. Press Enter for the default (n).
y) Yes, type in my own password
g) Generate random password
n) No, leave this optional password blank (default)
y/g/n> y
Enter the password:
password:
Confirm the password:
password:
Option bearer_token.
Bearer token instead of user/pass (e.g. a Macaroon).
Enter a value. Press Enter to leave empty.
bearer_token>
Edit advanced config?
y) Yes
n) No (default)
y/n> n
--------------------
[NextCloud]
type = webdav
url = https://nuss.phi.phys.nagoya-u.ac.jp/nuss/remote.php/dav/files/fujiie/
vendor = nextcloud
user = fujiie
pass = *** ENCRYPTED ***
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:
Name Type
==== ====
NextCloud webdav
OneDrive onedrive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q
その他よく使うコマンド¶
詳しくはOfficial Documentationをみるべし
rclone config
接続一覧が出てくる、Nameの列にある名前を使って接続する
rclone lsd [name]:path/to/dir
接続先[name]におけるディレクトリを表示
rclone ls [name]:path/to/dir
接続先[name]ファイルが全部表示される、上層ディレクトリですると鬱陶しいから基本使わない
rclone sync -P 同期元 [name]:同期先
同期元のファイルを同期先にコピーする、-P
はshow progress(だったはず)
rclone bisync -P 同期元 [name]:同期先
双方間同期、同期元を[name]:path/to/origin/dir
にするとクラウド間で同期可能
rclone check source:path dest:path [flags]
ファイルが一致しているかチェックする、ファイルは変更されないらしい
--exclude=XXX
特定のファイル等の同期を除外する
#final update
!echo final update
!date '+%b %d %Y (%a)'
final update 12 26 2022 (月)