1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TimeMachineのバックアップ先をRaspberry Pi 5で構築する

1
Posted at

はじめに

個人で使っているM1 MacBook Pro (2021)のTimeMachineのバックアップ先として、USB接続のSSDを利用してきました。
会社と個人のMacBook Proとで周辺機器を共用している関係で、切り替える度にUSBの挿抜が発生して面倒でした。
デスクを見渡すとRaspberry Pi 5があったので、これをTimeMachineのバックアップ先として構築することにしました。

環境情報

Component Version
Server Raspberry Pi 5
OS Debian GNU/Linux 12 (bookworm)
Storage (Main) KIOXIA KLMEA128G
Storage (Backup) BUFFALO SSD-PUT1.0U3-B/N

手順

SSDのフォーマットと自動マウントの設定

接続しているSSDのデバイス名を確認します。

lsblk

/dev/sda1 として認識されていました。

SSDをext4でフォーマットします。

sudo mkfs.ext4 /dev/sda1

マウントポイントを作成して、手動でマウントします。

sudo mkdir -p /mnt/timemachine
sudo mount /dev/sda1 /mnt/timemachine

UUIDを確認します。

sudo blkid /dev/sda1

/dev/fstab で自動マウントの設定をします。

sudo vi /etc/fstab

末尾に以下を追記します

UUID=xxxx-xxxx-xxxx-xxxx  /mnt/timemachine  ext4  defaults,noatime  0  2

Raspberry Pi 5を再起動して、df コマンドで自動マウントできているか確認します。

必要なパッケージのインストール

sambaとavahiをインストールします。

sudo apt update
sudo apt install -y samba avahi-daemon

ユーザーの作成

timemachineユーザーを作成します。
ログインできる必要はないので無効にしておきます。

sudo adduser --disabled-login --gecos "" timemachine

samba専用のパスワードを設定しておきます。

sudo smbpasswd -a timemachine

ディレクトリの作成

backups というディレクトリ名で、マウントしたSSDにバックアップ先を作成します。

sudo mkdir -p /mnt/timemachine/backups
sudo chown -R timemachine:timemachine /mnt/timemachine/backups
sudo chmod 700 /mnt/timemachine/backups

sambaの設定

Smabaの設定ファイルを開きます。

sudo vi /etc/samba/smb.conf

globalセクションに以下を追記します。

[global]
(snip)
   vfs objects = catia fruit streams_xattr
   fruit:aapl = yes
   fruit:model = Macpro
   fruit:attribute_info = stream
   fruit:metadata = stream
   fruit:posix_rename = yes
   fruit:zero_file_id = yes
   fruit:nfc_aces = no

以下のTimeMachineセクションを追記します。

[TimeMachine]
   comment = Time Machine Backup
   path = /mnt/timemachine/backups
   valid users = %U
   read only = no
   browsable = yes
   writable = yes
   fruit:time machine = yes
   fruit:time machine max size = 500G

sambaの設定ファイルの構文チェックをします。

testparm

OKそうであれば、smbd, nmbdを再起動します。

sudo systemctl restart smbd nmbd

avahiの自動検出設定

MacでRaspberry Piを自動表示させるための設定です。

sudo vi /etc/avahi/services/samba.service

以下の内容を貼り付けて保存します。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">%h</name>
  <service>
    <type>_smb._tcp</type>
    <port>445</port>
  </service>
  <service>
    <type>_device-info._tcp</type>
    <port>0</port>
    <txt-record>model=Macpro</txt-record>
  </service>
  <service>
    <type>_adisk._tcp</type>
    <port>0</port>
    <txt-record>sys=waMa=0,adVF=0x100</txt-record>
    <txt-record>dk0=adVN=TimeMachine,adVF=0x82</txt-record>
  </service>
</service-group>

avahiを再起動します。

sudo systemctl restart avahi-daemon

macOS側での設定

  1. Mac を Raspberry Pi と同じローカルネットワークに接続します
  2. システム設定 > 一般 > Time Machine を開きます
  3. 「バックアップディスクを追加...」(または + ボタン)をクリックします
  4. 利用可能なディスクの一覧に TimeMachineが表示されるので選択し、「ディスクを設定」をクリックします。
  5. 認証情報を求められたら、登録ユーザー を選択し、設定したtimemachine (ユーザー名) と Samba パスワードを入力して接続します

その後、正常にバックアップが開始されれば、設定が完了です。

最後に

無事、Raspberry Pi 5をTimeMachineのバックアップ先として構築することができました。
これでUSB経由ではなくネットワーク経由でMacをバックアップすることができるようになったので、挿抜するケーブルを1本減らすことができました。

10年以上前に、LPICの勉強を兼ねてSambaでファイルサーバーを構築しました。
時を経て、TimeMachineのバックアップ先としてSambaを構築するとは思いませんでした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?