本格的に初期設定する前に一度バックアップを取ることにする。
1.バックアップの前準備
root@obsa7:~# aptitude install dump
root@obsa7:~# aptitude install bzip2
root@obsa7:~# mkdir -p /dsk/sda2
root@obsa7:~# mount /dev/sda2 /dsk/sda2
root@obsa7:~# df -h|grep sda2
/dev/sda2 11G 155M 9.7G 2% /dsk/sda2
oot@obsa7:~# mkdir -p /dsk/sda2/Backup/OBSA7/RootBz
root@obsa7:~# useradd -m a7user
root@obsa7:~# passwd a7user
root@obsa7:~# vigr
root@obsa7:~# grep a7user /etc/group
disk:x:6:a7user
staff:x:50:a7user
a7user:x:1000:
root@obsa7:~# chown -R a7user /dsk/sda2/Backup/
2.バックアップスクリプト
今後もちょくちょくバックアップするのにスクリプトを用意した。
$ cat /usr/local/bin/b_sda1_local.sh
#! /bin/bash
# $Id: b_sda1_local.sh,v 1.1 2013-12-24 14:49:56+09 a7user $
#
HDEV=sda1
if [ `whoami` != "a7user" ]; then
ERRMSG="User not a7user."
echo $ERRMSG
logger $ERRMSG
exit 1
fi
MYCMD=$0
MYNM=`basename $0`
BODY=${MYNM%.sh}
RDIR=/dsk/sda2/Backup/OBSA7/RootBz
if [ ! -d ${RDIR} ]; then
ERRMSG="Not Mounted $RDIR."
echo $ERRMSG
logger $ERRMSG
exit 1
fi
cd $RDIR
if [ $? != 0 ]; then
ERRMSG="CANNOT cd $RDIR."
echo $ERRMSG
logger $ERRMSG
exit 1
fi
YMD=`date "+%Y_%m%d"`
BDIR=${BODY}_${YMD}
if [ ! -d ${BDIR} ]; then
mkdir -p ${BDIR}
if [ $? != 0 ]; then
ERRMSG="Cannot mkdir $BDIR."
echo $ERRMSG
logger $ERRMSG
exit 1
fi
fi
CLOG="${BDIR}/${HDEV}_${YMD}.log"
echo "START=`date`" | tee $CLOG
echo "----------------------------------------" | tee -a $CLOG
echo "% /sbin/fdisk -l /dev/sda" | tee -a $CLOG
/sbin/fdisk -l /dev/sda | sed -n -e "/^Disk/,//p" | tee -a $CLOG
echo "----------------------------------------" | tee -a $CLOG
echo "% df" | tee -a $CLOG
df | tee -a $CLOG
echo "" | tee -a $CLOG
echo "" | tee -a $CLOG
echo "****************************************" | tee -a $CLOG
date | tee -a $CLOG
pwd | tee -a $CLOG
set -x
(/sbin/dump 0usf 99999 - /dev/${HDEV} | \
bzip2 -c > ${BDIR}/${HDEV}_${YMD}.dump.bz2 ) 2>&1 | tee -a $CLOG
date | tee -a $CLOG
ls -l ${BDIR} | tee -a $CLOG
md5sum ${BDIR}/${HDEV}_${YMD}.dump.bz2 | tee -a $CLOG
set +x
echo "****************************************" | tee -a $CLOG
echo "END=`date`" | tee -a $CLOG
logger "$MYNM FINISH." "$CLOG"
exit 0
# end of b_sda1_local.sh
3.バックアップスクリプトの実行
$ /usr/local/bin/b_sda1_local.sh
START=Tue Dec 24 14:14:26 JST 2013
----------------------------------------
% /sbin/fdisk -l /dev/sda
Disk /dev/sda: 20 GB, 20012106240 bytes
255 heads, 63 sectors/track, 2433 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 997 8008371 83 Linux
/dev/sda2 998 2366 10988460 83 Linux
/dev/sda3 2367 2433 530145 82 Linux swap
----------------------------------------
% df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 142799 110248 25179 82% /
/dev/root 142799 110248 25179 82% /
tmpfs 103392 132 103260 1% /run
tmpfs 5120 0 5120 0% /run/lock
tmpfs 10240 0 10240 0% /dev
tmpfs 206780 0 206780 0% /run/shm
/dev/sda1 7882560 420692 7061452 6% /.rw
aufs 7882560 420692 7061452 6% /etc
aufs 7882560 420692 7061452 6% /bin
aufs 7882560 420692 7061452 6% /home
aufs 7882560 420692 7061452 6% /lib
aufs 7882560 420692 7061452 6% /sbin
aufs 7882560 420692 7061452 6% /usr
aufs 7882560 420692 7061452 6% /var
aufs 7882560 420692 7061452 6% /root
aufs 7882560 420692 7061452 6% /opt
aufs 7882560 420692 7061452 6% /srv
aufs 7882560 420692 7061452 6% /media
/dev/sda2 10823708 158088 10115796 2% /dsk/sda2
****************************************
Tue Dec 24 14:14:27 JST 2013
/dsk/sda2/Backup/OBSA7/RootBz
+ tee -a b_sda1_local_2013_1224/sda1_2013_1224.log
+ bzip2 -c
+ /sbin/dump 0usf 99999 - /dev/sda1
DUMP: Date of this level 0 dump: Tue Dec 24 14:14:27 2013
DUMP: Dumping /dev/sda1 (/.rw) to standard output
DUMP: Label: DEBIAN
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 275498 blocks.
DUMP: Volume 1 started with block 1 at: Tue Dec 24 14:14:28 2013
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: 38.74% done at 353 kB/s, finished in 0:07
DUMP: 65.60% done at 299 kB/s, finished in 0:05
DUMP: 98.06% done at 298 kB/s, finished in 0:00
DUMP: Volume 1 completed at: Tue Dec 24 14:29:39 2013
DUMP: Volume 1 275750 blocks (269.29MB)
DUMP: Volume 1 took 0:15:11
DUMP: Volume 1 transfer rate: 302 kB/s
DUMP: 275750 blocks (269.29MB)
DUMP: finished in 911 seconds, throughput 302 kBytes/sec
DUMP: Date of this level 0 dump: Tue Dec 24 14:14:27 2013
DUMP: Date this dump completed: Tue Dec 24 14:29:39 2013
DUMP: Average transfer rate: 302 kB/s
DUMP: DUMP IS DONE
+ tee -a b_sda1_local_2013_1224/sda1_2013_1224.log
+ date
Tue Dec 24 14:29:44 JST 2013
+ tee -a b_sda1_local_2013_1224/sda1_2013_1224.log
+ ls -l b_sda1_local_2013_1224
total 136456
-rw-r--r-- 1 a7user a7user 139580414 Dec 24 14:29 sda1_2013_1224.dump.bz2
-rw-r--r-- 1 a7user a7user 2800 Dec 24 14:29 sda1_2013_1224.log
+ tee -a b_sda1_local_2013_1224/sda1_2013_1224.log
+ md5sum b_sda1_local_2013_1224/sda1_2013_1224.dump.bz2
b35db86c1a8631524be462db1f241262 b_sda1_local_2013_1224/sda1_2013_1224.dump.bz2
+ set +x
****************************************
END=Tue Dec 24 14:29:47 JST 2013
4.バックアップを念のため展開してみる
# PS1="\W# "
# cd /dsk/sda2/Backup/OBSA7/RootBz/b_sda1_local_2013_1224
# mkdir RestoreDir
# cd RestoreDir/
# bzip2 -dc ../sda1_2013_1224.dump.bz2|restore rf -
RestoreDir# pwd
/dsk/sda2/Backup/OBSA7/RootBz/b_sda1_local_2013_1224/RestoreDir
RestoreDir# ls -F
bin/ home/ lost+found/ opt/ root/ srv/ var/
etc/ lib/ media/ restoresymtable sbin/ usr/
RestoreDir# du -s .
272440 .
RestoreDir# du -s /.rw
271928 /.rw
RestoreDir# du -sh .
267M .
RestoreDir# du -sh /.rw
266M /.rw
RestoreDir#
restoreしてみると、ちゃんとバックアップできてそうだ。
0 件のコメント:
コメントを投稿