SSブログ

Linux(CentOS5.9)のバックアップ/リストア(dump/restore)をやってみた[dump] [CentOS]


Linux(CentOS5.9)のバックアップ/リストア(dump/restore)をやってみました。
間違っている部分があるかもしれませんが。

パーティションの環境です。ディスクは128GB。
/dev/sda1 : start= 63, size= 208782, Id=83, bootable
/dev/sda2 : start= 208845, size=130110435, Id=83
/dev/sda3 : start=130319280, size= 4096575, Id=82
/dev/sda4 : start=134415855, size=134014230, Id=83

Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda1 ext3 101086 18366 77501 20% /boot
/dev/sda2 ext3 63017256 2699228 57065268 5% /
/dev/sda4 ext3 64907652 1017228 60540072 2% /backup

/dev/sda3はswapです。

/bootと/を/backupにdumpします。

まず、rootになります。
[assimane@cent59x64 ~]$ su -
パスワード:********



バックアップのための準備。binにバックアップシェル、dataにバックアップデータ、logsにバックアップログを格納。
[root@cent59x64 ~]# cd /backup
[root@cent59x64 backup]# mkdir bin
[root@cent59x64 backup]# mkdir data
[root@cent59x64 backup]# mkdir logs



バックアップシェルの作成
[root@cent59x64 backup]# cd bin
[root@cent59x64 bin]# vi backup-boot.sh
[root@cent59x64 bin]# chmod 755 backup-boot.sh
[root@cent59x64 bin]# cat backup-boot.sh
#!/bin/sh
LOG_FILE=/backup/logs/backup-boot.log
echo "`date +'%Y/%m/%d %H:%M:%S'` BACKUP /boot START"
echo "`date +'%Y/%m/%d %H:%M:%S'` BACKUP /boot START" > $LOG_FILE
BACKUP_FILE=/backup/data/backup-boot_`date +%Y%m%d%H%M%S`
/sbin/dump -0f $BACKUP_FILE /dev/sda1 2>> $LOG_FILE
RESULT=$?
echo "dump result:$RESULT"
echo "dump result:$RESULT" >> $LOG_FILE
if [ "$RESULT" == 0 ] ; then
    /bin/gzip $BACKUP_FILE 2>> $LOG_FILE
    RESULT=$?
    echo "gzip result:$RESULT"
    echo "gzip result:$RESULT" >> $LOG_FILE
else
    echo "gzip skip"
    echo "gzip skip" >> $LOG_FILE
fi
echo "`date +'%Y/%m/%d %H:%M:%S'` BACKUP /boot END"
echo "`date +'%Y/%m/%d %H:%M:%S'` BACKUP /boot END" >> $LOG_FILE

[root@cent59x64 bin]# vi backup-root.sh
[root@cent59x64 bin]# chmod 755 backup-root.sh
[root@cent59x64 bin]# cat backup-root.sh
#!/bin/sh
LOG_FILE=/backup/logs/backup-root.log
echo "`date +'%Y/%m/%d %H:%M:%S'` BACKUP /root START"
echo "`date +'%Y/%m/%d %H:%M:%S'` BACKUP /root START" > $LOG_FILE
BACKUP_FILE=/backup/data/backup-root_`date +%Y%m%d%H%M%S`
/sbin/dump -0f $BACKUP_FILE /dev/sda2 2>> $LOG_FILE
RESULT=$?
echo "dump result:$RESULT"
echo "dump result:$RESULT" >> $LOG_FILE
if [ "$RESULT" == 0 ] ; then
    /bin/gzip $BACKUP_FILE 2>> $LOG_FILE
    RESULT=$?
    echo "gzip result:$RESULT"
    echo "gzip result:$RESULT" >> $LOG_FILE
else
    echo "gzip skip"
    echo "gzip skip" >> $LOG_FILE
fi
echo "`date +'%Y/%m/%d %H:%M:%S'` BACKUP /root END"
echo "`date +'%Y/%m/%d %H:%M:%S'` BACKUP /root END" >> $LOG_FILE

[root@cent59x64 bin]# vi backup.sh
[root@cent59x64 bin]# chmod 755 backup.sh
[root@cent59x64 bin]# cat backup.sh
#!/bin/sh
./backup-boot.sh
./backup-root.sh
/bin/df -T > /backup/data/dfinfo.txt
/sbin/fdisk -l > /backup/data/fdiskinfo.txt
/sbin/sfdisk -d /dev/sda > /backup/data/sfdiskinfo.txt
/sbin/swapon -s > /backup/data/swapinfo.txt



作成したシェルのバックアップ
[root@cent59x64 bin]# cd /backup
[root@cent59x64 backup]# tar cvf /backup/data/backup_bin.tar bin
bin/
bin/backup-root.sh
bin/backup-boot.sh
bin/backup.sh
[root@cent59x64 backup]# gzip /backup/data/backup_bin.tar
[root@cent59x64 backup]# cd data
[root@cent59x64 data]# ls -l
合計 4
-rw-r--r-- 1 root root 566  2月 11 00:27 backup_bin.tar.gz



シングルユーザーモードで起動
[root@cent59x64 data]# shutdown now



backup.shを実行
bk01.png

バックアップの確認
[assimane@cent59x64 ~]$ su -
パスワード:********
[root@cent59x64 ~]# cd /backup/data
[root@cent59x64 data]# ls -l
合計 832940
-rw-r--r-- 1 root root  10647251  2月 11 00:29 backup-boot_20130211002918.gz
-rw-r--r-- 1 root root 841414166  2月 11 00:37 backup-root_20130211002921.gz
-rw-r--r-- 1 root root       566  2月 11 00:27 backup_bin.tar.gz
-rw-r--r-- 1 root root       316  2月 11 00:42 dfinfo.txt
-rw-r--r-- 1 root root       466  2月 11 00:42 fdiskinfo.txt
-rw-r--r-- 1 root root       259  2月 11 00:42 sfdiskinfo.txt
-rw-r--r-- 1 root root       102  2月 11 00:42 swapinfo.txt
[root@cent59x64 data]# cd /backup/logs
[root@cent59x64 logs]# ls -l
合計 8
-rw-r--r-- 1 root root 1074  2月 11 00:29 backup-boot.log
-rw-r--r-- 1 root root 1126  2月 11 00:42 backup-root.log
[root@cent59x64 logs]# cat backup-boot.log
2013/02/11 00:29:18 BACKUP /boot START
  DUMP: Date of this level 0 dump: Mon Feb 11 00:29:19 2013
  DUMP: Dumping /dev/sda1 (/boot) to /backup/data/backup-boot_20130211002918
  DUMP: Label: /boot
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 12731 blocks.
  DUMP: Volume 1 started with block 1 at: Mon Feb 11 00:29:19 2013
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /backup/data/backup-boot_20130211002918
  DUMP: Volume 1 completed at: Mon Feb 11 00:29:20 2013
  DUMP: Volume 1 12790 blocks (12.49MB)
  DUMP: Volume 1 took 0:00:01
  DUMP: Volume 1 transfer rate: 12790 kB/s
  DUMP: 12790 blocks (12.49MB) on 1 volume(s)
  DUMP: finished in 1 seconds, throughput 12790 kBytes/sec
  DUMP: Date of this level 0 dump: Mon Feb 11 00:29:19 2013
  DUMP: Date this dump completed:  Mon Feb 11 00:29:20 2013
  DUMP: Average transfer rate: 12790 kB/s
  DUMP: DUMP IS DONE
dump result:0
gzip result:0
2013/02/11 00:29:21 BACKUP /boot END
[root@cent59x64 logs]# cat backup-root.log
2013/02/11 00:29:21 BACKUP /root START
  DUMP: Date of this level 0 dump: Mon Feb 11 00:29:21 2013
  DUMP: Dumping /dev/sda2 (/) to /backup/data/backup-root_20130211002921
  DUMP: Label: /
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 2625436 blocks.
  DUMP: Volume 1 started with block 1 at: Mon Feb 11 00:29:35 2013
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: 67.61% done at 5916 kB/s, finished in 0:02
  DUMP: Closing /backup/data/backup-root_20130211002921
  DUMP: Volume 1 completed at: Mon Feb 11 00:37:42 2013
  DUMP: Volume 1 3030600 blocks (2959.57MB)
  DUMP: Volume 1 took 0:08:07
  DUMP: Volume 1 transfer rate: 6222 kB/s
  DUMP: 3030600 blocks (2959.57MB) on 1 volume(s)
  DUMP: finished in 487 seconds, throughput 6222 kBytes/sec
  DUMP: Date of this level 0 dump: Mon Feb 11 00:29:21 2013
  DUMP: Date this dump completed:  Mon Feb 11 00:37:42 2013
  DUMP: Average transfer rate: 6222 kB/s
  DUMP: DUMP IS DONE
dump result:0
gzip result:0
2013/02/11 00:42:41 BACKUP /root END



バックアップファイルの転送
[root@cent59x64 logs]# cd /backup/data
[root@cent59x64 data]# ftp 192.168.0.4
Connected to 192.168.0.4.
220 welcome!
502 GSSAPI authentication not implemented
504 Auth type not supported
KERBEROS_V4 rejected as an authentication type
Name (192.168.0.4:root): assimane
331 Password required for assimane
Password:********
230 Logged on
Remote system type is UNIX.
ftp> bin
200 Type set to I
ftp> put backup-boot_20130211002918.gz
local: backup-boot_20130211002918.gz remote: backup-boot_20130211002918.gz
227 Entering Passive Mode (192,168,0,4,199,166)
150 Connection accepted
226 Transfer OK
10647251 bytes sent in 0.6 seconds (1.7e+04 Kbytes/s)
ftp> put backup-root_20130211002921.gz
local: backup-root_20130211002921.gz remote: backup-root_20130211002921.gz
227 Entering Passive Mode (192,168,0,4,199,167)
150 Connection accepted
226 Transfer OK
841414166 bytes sent in 34 seconds (2.5e+04 Kbytes/s)
ftp> put backup_bin.tar.gz
local: backup_bin.tar.gz remote: backup_bin.tar.gz
227 Entering Passive Mode (192,168,0,4,199,168)
150 Connection accepted
226 Transfer OK
566 bytes sent in 0.0097 seconds (57 Kbytes/s)
ftp> put dfinfo.txt
local: dfinfo.txt remote: dfinfo.txt
227 Entering Passive Mode (192,168,0,4,199,169)
150 Connection accepted
226 Transfer OK
316 bytes sent in 0.0046 seconds (68 Kbytes/s)
ftp> put fdiskinfo.txt
local: fdiskinfo.txt remote: fdiskinfo.txt
227 Entering Passive Mode (192,168,0,4,199,170)
150 Connection accepted
226 Transfer OK
466 bytes sent in 0.00088 seconds (5.2e+02 Kbytes/s)
ftp> put sfdiskinfo.txt
local: sfdiskinfo.txt remote: sfdiskinfo.txt
227 Entering Passive Mode (192,168,0,4,199,171)
150 Connection accepted
226 Transfer OK
259 bytes sent in 0.014 seconds (19 Kbytes/s)
ftp> put swapinfo.txt
local: swapinfo.txt remote: swapinfo.txt
227 Entering Passive Mode (192,168,0,4,199,172)
150 Connection accepted
226 Transfer OK
102 bytes sent in 0.011 seconds (8.8 Kbytes/s)
ftp> bye
221 Goodbye



これでバックアップは完了です。次回はrestoreについて書きます。

次回もお楽しみに!!


nice!(1)  コメント(0)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 1

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

※ブログオーナーが承認したコメントのみ表示されます。

Facebook コメント

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。