Respberry PiからAzCopy 10.xを利用する

目次

はじめに

数年前に入手した「Raspberry Pi 2 Model B」が用途未定のままずっと放置していたので、自宅のNAS(LinkStation 1TB Single)のファイルをAzure File Storageにスケジュールコピーするサービスを設定しました。

背景としては、上記のとおり自作NASには子供の写真とか動画が山程保存されているにも関わらず、NASがシングルHDD構成となっているため、いざというときのHDD故障が心配だからです。

かといって、QNAPとかSynologyとかのRAID+クラウド転送機能があるNASを購入する財源も無いため知恵と時間で解決させます。

img

Raspberry Piの初期設定

Az Copyが動くだけで良いので、Raspberry PiにインストールするOSは「Raspbian Buster Lite」という最も軽量なGUIなどが入っていないやつを選択しました。

以下サイトからimgをダウンロードしてきます。

https://www.raspberrypi.org/downloads/raspbian/

私が作業した時にダウンロードしたイメージファイルは「2019-07-10-raspbian-buster-lite.img」となっていました。

適当なWindows PCで「SD Formatter」(https://www.sdcard.org/jp/downloads/formatter/)を使ってフォーマットします。手順は省略してもいいのですが、SDカードが変に論理分割されていると後々面倒臭いので最初にクイックフォーマットしておきます。

img

つづいて「Win32 Disk Imager」 (https://sourceforge.net/projects/win32diskimager/ )でRaspbianのイメージをSDカードに書き込みます。

img

Raspbianの起動

初回のみHDMIと有線LAN、USBキーボードを接続して起動します。

初期パスワードは pi/raspberry です。

img

sshログインが初期状態では無効になっているので以下のコマンドで有効化します。

$ sudo touch /boot/ssh

以下のコマンドでIPアドレスをメモしておいてから、shutdownします。

$ ifconfig eth0 $ shutdown -h now

あとはもうキーボードもディスプレイも不要になるので、 電源とLANだけの構成で起動すれば、ssh接続が可能になっています。

Tera Termなど適当なsshクライアントを使ってこの後は作業します。

OSアップデート

以下のサイトを参考に一通り最新版にアップデートしておきます。

https://qiita.com/akiraichi5430/items/6b9855f59fb3a3f9de35

$ sudo rpi-update $ sudo reboot $ sudo apt update $ sudo apt dist-upgrade -y $ sudo apt-get autoremove -y $ sudo apt-get autoclean $ sudo reboot

パスワード変更とユーザ作成

デフォルト状態のパスワードはよろしくないので変更して、更に作業用のユーザも作成します。

$ sudo passwd pi $ sudo adduser (任意の名前) $ sudo usermod -G pi,adm,dialout,cdrom,sudo,audio,video,plugde v,games,users,input,netdev,spi,i2c,gpio (任意の名前)

一度ログアウトして、これからは新しく作成したユーザで作業します。

AzCopyのインストール

Raspberry PI(ARM)向けのAzCopyの実行ファイルはまだ公開されていないため、自分でビルドする必要があります。

まずはGO言語、gitをインストールします。

参考資料 : https://github.com/Azure/azure-storage-azcopy/issues/415

$ sudo apt install golang -y $ sudo apt install git -y

AzCopyのソースを取得してインストールします。

# cd ~ $ go get github.com/Azure/azure-storage-azcopy $ cd go/src/github.com/Azure/azure-storage-azcopy $ go install

~/go/bin 配下に「azure-storage-azcopy」 が作成されました。

img

Versionは10.2.1でした。

img

Azure Storageの作成

任意のAzureリソースグループを作成して、Storage Accountを作成します。

テストなので、Standard LRSで東日本に立てました。

img

SASトークンの取得

Storageのメニューから「Shared Access Signature」を選び、「使用できるサービス」はとりあえずBLOBとファイルのみチェック。終了期限はとりあえず100年後にして、「SASと接続文字列を生成する」をクリックします。

img

画面下部に表示される「接続文字列」内から「BlobEndpoint=」の内容と「FileEndpoint=」の内容をメモします。

「SASトークン」の内容もメモします。

とりあえず環境変数に突っ込んでおきましょう。

SASTOKEN="?sv=2018-03-28&ss=bf&srt=sco&sp=rwdlac&se=2119-07-22T13:50:49Z&st=2019-07-22T05:50:49Z&spr=https&sig=HR**********8M%3D"
DSTURLFILE="https://xxxxxxxx.file.core.windows.net/"
DSTURLBLOB="https://xxxxxxxx.blob.core.windows.net/"

ローカルファイル→Azure Storageへのコピー

2019/07/22時点のARM版のAzCopyは少し微妙な感じで以下のIssueが出ていますが、私の環境でも同種のエラーが出てしまいます。

https://github.com/Azure/azure-storage-azcopy/issues/427

ただし、以下のCloseしたIssueを見るとARM32/64でも動作させられるよってなっているので続行しましょう。

https://github.com/Azure/azure-storage-azcopy/issues/415

まずはローカルファイル→Azure Fileに対してコピーを行っています。

共有フォルダの作成

Azureポータルから作成してもいいのですが、AzCopyコマンドでも作成できます。

$ DSTSHARE=“testshare01” $ ./go/bin/azure-storage-azcopy make ${DSTURLFILE}${DSTSHARE}${SASTOKEN} Successfully created the resource.

Azureポータルから見ても共有フォルダが作成されました。

img

ファイルのコピー

コピー元のローカルファイルの構成は以下の通り。

$ ls -Rl srcdir
srcdir:
total 16
drwxr-xr-x 2 yotan yotan 4096 Jul 22 07:28 dir01
-rw-r--r-- 1 yotan yotan    7 Jul 22 06:57 hoehoehoe.txt
-rw-r--r-- 1 yotan yotan    7 Jul 22 05:54 hoe.txt
-rw-r--r-- 1 yotan yotan   13 Jul 22 03:59 readme.txt

srcdir/dir01:
total 4
-rw-r--r-- 1 yotan yotan 4 Jul 22 07:28 dirtest.txt

以下のコマンドでAzure Fileにコピーします。

$ go/bin/azure-storage-azcopy cp ./srcdir/ ${DSTURLFILE}${DSTSHARE}${SASTOKEN} --recursive=true
INFO: Scanning...

Job 4fbfefcf-be69-c04a-677d-204f190939ca has started
Log file is located at: /home/yotan/.azcopy/4fbfefcf-be69-c04a-677d-204f190939ca.log

0 Done, 0 Failed, 4 Pending, 0 Skipped, 4 Total,


Job 4fbfefcf-be69-c04a-677d-204f190939ca summary
Elapsed Time (Minutes): 0.0334
Total Number Of Transfers: 4
Number of Transfers Completed: 4
Number of Transfers Failed: 0
Number of Transfers Skipped: 0
TotalBytesTransferred: 31
Final Job Status: Completed

無事コマンドは正常に完了して、Azureポータルからもコピーされたことが確認できました。

img

残念なお知らせ

Azure Fileに対してraspbianのローカルファイル(ディレクトリ)からの単純コピーは上記でうまくいくのですが、本来やりたい「sync」が動きません。

実行例は以下の通り。

$ go/bin/azure-storage-azcopy sync ./srcdir/ ${DSTURLFILE}${DSTSHARE}${SASTOKEN} --recursive=true

error parsing the input given by the user. Failed with error source './srcdir/' / destination 'https://ktkraztestst01.file.core.windows.net/testshare01?sv=2018-03-28&ss=bf&srt=sco&sp=rwdlac&se=2119-07-22T13:50:49Z&st=2019-07-22T05:50:49Z&spr=https&sig=-REDACTED- combination 'LocalFile' not supported for sync command

LocalFileが対応していないって。。。

Issueを調べると、今はLocal to Azure Fileは未サポートだそうです。 https://github.com/Azure/azure-storage-azcopy/issues/75
残念。

次にAzure BLOBへのsyncですが、エラーが沢山でますが、一応同期はされた模様。

$ DSTSHARE="testcontainer01"
$ ./go/bin/azure-storage-azcopy make ${DSTURLBLOB}${DSTSHARE}${SASTOKEN}

Successfully created the resource.

$ go/bin/azure-storage-azcopy sync ./srcdir/ ${DSTURLBLOB}${DSTSHARE}${SASTOKEN} --recursive=true

Job 11e2cdaa-06b5-0f4a-678e-bf6df925d8c6 has started
Log file is located at: /home/yotan/.azcopy/11e2cdaa-06b5-0f4a-678e-bf6df925d8c6.log

0 Files Scanned at Source, 0 Files Scanned at Destinationunexpected fault address 0x0
fatal error: fault
[signal SIGBUS: bus error code=0x1 addr=0x0 pc=0xffff0fc8]

goroutine 70 [running]:
runtime.throw(0x73b5e5, 0x5)
        /usr/lib/go-1.11/src/runtime/panic.go:608 +0x5c fp=0x1711d38 sp=0x1711d24 pc=0x3d39c

(snip)

img

新たにファイルを追加してもちゃんと追加されますね。

$ echo HOGEHOGE > srcdir/dir01/payapaya.txt
$ go/bin/azure-storage-azcopy sync ./srcdir/ ${DSTURLBLOB}${DSTSHARE}${SASTOKEN} --recursive=true

Job a5db04b4-d894-a346-539d-eb3595e2a186 has started
Log file is located at: /home/yotan/.azcopy/a5db04b4-d894-a346-539d-eb3595e2a186.log

0 Files Scanned at Source, 0 Files Scanned at Destinationunexpected fault address 0x0
fatal error: fault
[signal SIGBUS: bus error code=0x1 addr=0x0 pc=0xffff0fc8]

goroutine 7 [running]:
runtime.throw(0x73b5e5, 0x5)
        /usr/lib/go-1.11/src/runtime/panic.go:608 +0x5c fp=0x2bfbd38 sp=0x2bfbd24 pc=0x3d39c

(snip)

img

更新ファイルが無いと、特にエラー無く正常終了します。

$ go/bin/azure-storage-azcopy sync ./srcdir/ ${DSTURLBLOB}${DSTSHARE}${SASTOKEN} --recursive=true

Job d84ceb80-f65f-fc4b-5a6c-d71ba366c85d has started
Log file is located at: /home/yotan/.azcopy/d84ceb80-f65f-fc4b-5a6c-d71ba366c85d.log

5 Files Scanned at Source, 5 Files Scanned at Destination
The source and destination are already in sync.

おわりに

Azure Fileに対してローカルから丸ごとコピーであればとりあえずエラーなしで動いたっぽいです。

結構リアルタイムに絶賛改修中なところがあるAzCopy 10.xなのでまた変化があったら追記します。

最後しりつぼみのエントリですみませんでした。