R.A. Epigonos et al.

[SystemRescueCd] dd を使ったパーティションのバックアップ

パーティション自体のバックアップというよりも、パーティションに含まれる要素をバックアップしたいケース。

バックアップを取りたいマシンを SystemRescurCD で起動し、ssh の鍵ペアを作る。

root@sysresccd /root % ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:******************************************* root@sysresccd
The key's randomart image is:
+---[RSA 2048]----+
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
+----[SHA256]-----+

作った鍵ペアの公開鍵をバックアップファイルの送信先マシンの ~/.ssh/authorized_keys に追加。sshfs で送信先マシンのディレクトリをバックアップを撮りたいマシンにマウント

root@sysresccd /root % sshfs root@192.168.22.1:/home/disk_image /mnt/backup

ディスクのパーティションとセクタサイズを確認。

root@sysresccd /root % fdisk --list /dev/sda
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 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: 0x5290bfbf

Device     Boot    Start       End   Sectors   Size Id Type
/dev/sda1  *          63   2023423   2023361   988M 83 Linux
/dev/sda2        2024190  27647864  25623675  12.2G  5 Extended
/dev/sda3       27648000 976773167 949125168 452.6G 83 Linux
/dev/sda5        2040255  11261564   9221310   4.4G 83 Linux
/dev/sda6       11261628  15358139   4096512     2G 83 Linux
/dev/sda7       15360000  17403903   2043904   998M 82 Linux swap / Solaris
/dev/sda8       17405952  19451903   2045952   999M 83 Linux
/dev/sda9       19453952  27645951   8192000   3.9G 83 Linux

Partition table entries are not in disk order.

それぞれのパーティションのマウント先は以下の様な感じ。

/dev/sda1 /
/dev/sda9 /home
/dev/sda5 /usr
/dev/sda6 /var
/dev/sda8 /tmp
/dev/sda7 swap

ということで、今回は /, /home, /usr, /var をバックアップする方針。/tmp と swap にバックアップする価値のある情報は含まれないのでバックアップしない。適宜 dmesg を見て、エラーが起きていないことを確認。dd が転送したセクタ数と fdisk の言うパーティションのセクタ数が一致することを確認。

root@sysresccd /root % dd if=/dev/sda1 of=/mnt/backup/sda1.root.img
2023361+0 records in
2023361+0 records out
1035960832 bytes (1.0 GB) copied, 277.748 s, 3.7 MB/s
root@sysresccd /root % dd if=/dev/sda9 of=/mnt/backup/sda9.root-home.img
8192000+0 records in
8192000+0 records out
4194304000 bytes (4.2 GB) copied, 1125.3 s, 3.7 MB/s
root@sysresccd /root % dd if=/dev/sda5 of=/mnt/backup/sda5.root-usr.img
9221310+0 records in
9221310+0 records out
4721310720 bytes (4.7 GB) copied, 1268.05 s, 3.7 MB/s
root@sysresccd /root % dd if=/dev/sda6 of=/mnt/backup/sda5.root-var.img
4096512+0 records in
4096512+0 records out
2097414144 bytes (2.1 GB) copied, 567.263 s, 3.7 MB/s

バックアップファイルの転送先でパーティションイメージを読み込み専用マウントするには、以下のコマンドを使う。

# mount --options ro sda1.root.img /mnt/
# umount /mnt/

dd から作られたパーティションイメージファイルのサイズはパーティションのサイズと同じになる。そのまま保存しておくにはちょっと大きすぎるので適宜圧縮する。

$ /usr/bin/time --verbose xz --verbose --best sda1.root.img
sda1.root.img (1/1)
  100 %       286.1 MiB / 988.0 MiB = 0.290   1.0 MiB/s      16:12
        Command being timed: "xz --verbose --best sda1.root.img"
        User time (seconds): 962.23
        System time (seconds): 5.44
        Percent of CPU this job got: 99%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 16:13.05
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 691356
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 172403
        Voluntary context switches: 38
        Involuntary context switches: 102708
        Swaps: 0
        File system inputs: 2023200
        File system outputs: 585904
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

読み込み専用パーティションで圧縮させたいなら、SquashFS などを使うほうがいいかも

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2007-12-02T16:33:50+09:00
  2. Modified: 2007-12-02T16:33:50+09:00
  3. Generated: 2023-08-27T23:09:12+09:00