【Ubuntu 18.04/16.04 LTS Server】USBメモリをext4フォーマットしてバックアップ用に使う

スポンサーリンク

大容量のUSBメモリが手頃に買えるようになってきているので、USBメモリ(256Gbyteを準備)をGitリポジトリやWordPressデータなどのバックアップ用に、Ubuntu Serverに接続して使う。

USBメモリのデバイス名を確認

USBメモリをUbuntu Serverパソコンに挿して、dmesgでUSBのデバイス名を調べると、私の環境では/dev/sdb1に割り当てられていた。

更に、ls -l /dev/sdb*コマンドで確認

$ ls -l /dev/sdb*
brw-rw---- 1 root disk 8, 16  3月  2 22:21 /dev/sdb
brw-rw---- 1 root disk 8, 17  3月  2 22:21 /dev/sdb1

領域確保

fdiskコマンドを使って、既存のDOS領域を削除しLinux領域を確保。

$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

コマンド (m でヘルプ): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

コマンド (m でヘルプ): p
Disk /dev/sdb: 238.5 GiB, 256063307776 bytes, 500123648 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

デバイス   起動 Start 最後から セクタ   Size Id タイプ
/dev/sdb1          64 500123647 500123584 238.5G  c W95 FAT32 (LBA)

コマンド (m でヘルプ): d
Selected partition 1
Partition 1 has been deleted.

コマンド (m でヘルプ): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
パーティション番号 (1-4, default 1): 1
First sector (2048-500123647, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-500123647, default 500123647):

Created a new partition 1 of type 'Linux' and of size 238.5 GiB.

コマンド (m でヘルプ): p
Disk /dev/sdb: 238.5 GiB, 256063307776 bytes, 500123648 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

デバイス   起動 Start 最後から セクタ   Size Id タイプ
/dev/sdb1        2048 500123647 500121600 238.5G 83 Linux

コマンド (m でヘルプ): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

ext4形式でフォーマット

mkfs.ext4コマンド実行(完了まで多少時間かかる)

$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 62515200 4k blocks and 15630336 inodes
Filesystem UUID: 736add05-abd0-437b-a1ef-d74729392ecb
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

自動マウント

マウントポイントの作成

$ sudo mkdir /mnt/usbmem

/etc/fstabに下記行を追加し自動マウントさせる。

/dev/sdb1 /mnt/usbmem ext4 auto,rw,user 0 0

手動でマウント

何らかの都合でマウントしたい時は下記。

$ sudo mount -t ext4 /dev/sdb1 /mnt/usbmem

手動でアンマウント

何らかの都合でアンマウントしたい時は下記。

$ sudo umount /mnt/usbmem

再起動してdfコマンドで確認

$ df -h
Filesystem                     Size  Used Avail Use% Mounted on
udev                           1.9G     0  1.9G   0% /dev
tmpfs                          385M  5.8M  379M   2% /run
/dev/mapper/server--vg-root    230G  3.1G  216G   2% /
tmpfs                          1.9G     0  1.9G   0% /dev/shm
tmpfs                          5.0M     0  5.0M   0% /run/lock
tmpfs                          1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sdb1                      235G   60M  223G   1% /mnt/usbmem
/dev/sda2                      473M  105M  344M  24% /boot
/dev/sda1                      511M  3.6M  508M   1% /boot/efi
tmpfs                          385M     0  385M   0% /run/user/1000

GitLabのバックアップ先をUSBメモリに変更

関連記事のように、/etc/gitlab/gitlab.rbの下記設定を変更。

gitlab_rails['backup_path'] = "/mnt/usbmem/gitlab/backups"
gitlab_rails['backup_keep_time'] = 2419200

※28日間(2419200秒)バックアップを保持

関連記事

【GitLab】GitLabのデータをバックアップ
以前の記事でGitLabサーバを構築した。Gitサーバのデータは重要なので、外付けのUSBメモリーを準備して、そこに定期的にバックアップする。GitLabにはバックアップする仕組みがあるので、それを利用する。 外付けUSBメモリの準備 少し...
【Ubuntu 18.04 LTS Server】インストールする
Ubuntu 18.04 LTS が、2018年4月26日(日本時間27日)にリリースされた。 そこで、新規に「Ubuntu 18.04 LTS Server」をインストールしたので備忘録を残す。 インストール媒体の入手 下記URLから、イ...

参考

  1. USB外付けHDDをext4にフォーマットする手順
  2. Ubuntu server 11.10 USBメモリのマウント | MT Systems

コメント

タイトルとURLをコピーしました