젠투 시스템 백업 스크립트
젠투 시스템을 통째로 묶어서 압축하는 방법으로 백업하는 스크립트이다.
환상경님의 소개로 알게 되었고 내 시스템에 맞추어 약간의 수정을 가했다. 자세한 사용법은 아래 첨가했다.
이글은 젠투포럼의
http://forums.gentoo.org/viewtopic-t-312817-highlight-backup+minimal+interactive.html
이 쓰레드를 참조하고 있다. 더 자세한 사항을 알고 싶으면 저 곳을 찾아보면 된다.
또한 이글은 http://blog.kashel.net/tt/index.php?pl=37 여기에서도 볼 수 있다.
luark@KasheL:~$ cat /home/luark/Desktop/down/backup.sh
#!/bin/bash
# Backup script for Gentoo Linux
# Copyright Reto Glauser aka Blinkeye
# Distributed under the terms of the GNU General Public License v2
# Mailto: stage4 at blinkeye dot ch
# Forum post: http://forums.gentoo.org/viewtopic-t-312817.html
# Date: 20.04.2005version=v1.4.2
# these are the commands we actually need for the backup
command_list="echo tar hostname date split gzip bzip2"# verify that each command we use exists
for command in $command_list; do
path=`which $command | grep "no $command in"`if [ ! -x `which $command` -a "$path" ]; then
echo -e "\n\nERROR: $command not found! Check your \$command_list and/or your \$PATH"
exit -1
fi
done# options for the tar command
tarOptions="--absolute-names --preserve-permissions --totals --ignore-failed-read --verbose --file"# 백업본을 어디에 둘 것인가?
stage4Location=/data/backup/localbackup# 백업파일이름결정
stage4prefix=$(hostname)-stage4-`date +\%d.\%m.\%Y`# 백업하지 않을 형식, 여기서는 공란으로 모두 백업하는 것을 말한다.
#exclude_pattern="--exclude=*.iso --exclude="*.bz2""
exclude_pattern=""# these files/directories are always excluded
#백업하지 않을 디렉토리들의 목록이다. 나의 경우에는 /data를 제거하는 것을 추가했다.
default_exclude_list="
--exclude=/tmp/*
--exclude=/var/tmp/*
--exclude=/lost+found/*
--exclude=/dev/*
--exclude=/proc/*
--exclude=/mnt/*
--exclude=/sys/*
--exclude=/usr/portage/*
--exclude=/var/log/*
--exclude=$stage4Location
--exclude=/data/*"
# depending on your choice these files or directories will additionally be excluded
#인터랙티브 백업을 선택했을 때 백업할 것인지를 물어보는 목록
custom_exclude_list="
--exclude=/usr/src/*
--exclude=/home/*"# files/folder which are children of a folder in an exclude_list
default_include_list="
/var/log/emerge.log
/dev/null
/dev/console"function verify()
{
for i in $1; do
if [ ! -e "`echo "$i" | cut -d'=' -f2 | cut -d'*' -f1`" ]; then echo "ERROR: `echo "$i" | cut -d'=' -f2` not found! Check your "$2
fi
done
}echo ""
# check the folder/files stored in $custom_exclude_list exist
verify "$default_exclude_list" "\$default_exclude_list"# check the folder/files stored in $default_exclude_list exist
verify "$custom_exclude_list" "\$custom_exclude_list"# check the folder/files stored in $custom_exclude_list exist
verify "$default_include_list" "\$default_include_list"# print out the version
echo -e "\nBackup script $version"
echo -e "===================="# how do you want to backup?
echo -e "\nWhat do you want to do? (Use CONTROL-C to abort)\n
Fast (tar.gz):
(1) Minimal backup
(2) Interactive backupBest (tar.bz2):
(3) Minimal backup
(4) Interactive backup\n"while [ "$option" != '1' -a "$option" != '2' -a "$option" != '3' -a "$option" != '4' ]; do
echo -en "Please enter your option: "
read option
donecase $option in
[1,3])
stage4Name=$stage4Location/$stage4prefix-minimal.tardefault_exclude_list="$default_exclude_list $custom_exclude_list"
case $option in
1) stage4postfix="gz"
zip="gzip ";;
*) stage4postfix="bz2"
zip="bzip2 ";;
esac
;;[2,4])
stage4Name=$stage4Location/$stage4prefix-custom.tarfor folder in $custom_exclude_list; do
echo -en "\nDo you want to backup" `echo "$folder" | cut -d'=' -f2`"? (y/n) "
read answer
while [ "$answer" != 'y' -a "$answer" != 'n' ]; do
echo -en "Do you want to backup" `echo "$folder" | cut -d'=' -f2`"? (y/n) "
read answer
done
if [ "$answer" == 'n' ]; then
default_exclude_list="$default_exclude_list $folder"
fi
donecase $option in
2) stage4postfix="gz"
zip="gzip";;
*) stage4postfix="bz2"
zip="bzip2";;
esac
;;
esactar_command="tar --create $tarOptions $stage4Name $default_include_list $exclude_pattern"
tar_command_append="tar $default_exclude_list $exclude_pattern $tarOptions $stage4Name -r /"
zip_command="$zip -f $stage4Name"# show what will be done
echo -ne "\ncreating the stage4 at $stage4Location with the following command:\n\n"$tar_command
echo -n " && "$tar_command_append
echo -n " && "$zip_command# everything is set, are you sure to continue?
echo -ne "\n\nDo you want to continue? (y/n) "
read answer
while [ "$answer" != 'y' ] && [ "$answer" != 'n' ]; do
echo -ne "Do you want to continue? (y/n) "
read answer
doneif [ "$answer" == 'y' ]; then
# check whether the file already exists (do that before the *.tar files have been created)
if [ -a "$stage4Name.$stage4postfix" ]; then
echo -en "\nDo you want to overwrite $stage4Name.$stage4postfix? (y/n) "
read answer
while [ "$answer" != 'y' ] && [ "$answer" != 'n' ]; do
echo -en "Do you want to overwrite $stage4Name.$stage4postfix? (y/n) "
read answer
done
if [ "$answer" == 'n' ]; then
echo -e "\n* There's nothing to do ... Exiting"
exit 0;
fi
fi# if necessary, create the stage4Location
if [ ! -d "$stage4Location" ] ; then
echo "* creating directory $stage4Location"
mkdir -p $stage4Location
fi# mount boot
echo -e "\n* mount boot\n"
mount /boot >/dev/null 2>&1# do the backup
$tar_command
$tar_command_append
echo -e "\n* $zip $stage4Name"
$zip_command# copy the current world file to the stage4 location
#echo -e "\n* creating stage4 overview $stage4Name.txt"
#cp /var/lib/portage/world $stage4Name.txt >/dev/null 2>&1# finished, clean up
echo -e "* stage4 is done"
echo "* umounting boot"
umount /bootelse
echo -e "\n* There's nothing to do ... Exiting"
fi# Split the archive into chunks (uncomment the 3 lines if you want to split the stage4)
#echo -e "* split $stage4Name.$stage4postfix"
#split --suffix-length=1 --bytes=690m $stage4Name.$stage4postfix "$stage4Name.$stage4postfix"_
#echo "* splitting is done"
으음.. 사용방법을 추가하면;
1.스크립트의 목적.
이 스크립트가 하는 일은 간단합니다. 젠투의 필수적인 디렉토리들만 뽑아서 tar묶은후에 압축하는 것이죠. 필수적인 디렉토리는 모두 체크되어 있으니 위에 주석달린 부분을 살펴보고 자신에게 필요한 디렉토리를 추가하거나 빼면 됩니다.
미니멀과 인터랙티브의 차이는 /usr/src 와 /home 을 백업 목록에 추가할 것인지 말것인지입니다. fast와 best의 차이는 gz냐 bz2냐 의 차이죠. 압축률의 차이입니다.
3~4기가정도의 젠투파티션을 통째로 백업했을 경우 best옵션으로 했을 때 600~700메가정도의 용량이 나왔습니다.
2. 백업의 준비절차
우선 백업하기전에 불필요한 마운트드라이브들은 마운트를 해제합니다. 그리고 젠투파티션에는 충분한 용량이 남아있어야 합니다. 압축을 할경우 일단 압축을 완료한 후 tar파일을 지우므로 용량을 생각해 봐서 적당히 줄여줄 필요가 있습니다.
저의 경우에는 /data파티션을 마운트한 후 백업제외목록에 /data를 추가해 준 후에 /data파티션으로 백업이 되도록 했습니다. 기본적으로는 /mnt/backup을 만들어서 스테이지2 파일을 만들어 줍니다. 주의할 점은 백업본이 만들어질 디렉토리는 절대 백업 목록에 들어가면 안됩니다.
3. 백업의 수행.
간단하게 위 스크립트에 실행권한을 준 후 루트권한으로 실행하면 목적한 디렉토리에 백업파일이 만들어집니다. 이 파일을 젠투가 날아가도 복사해올 수 있는 곳에 담아 두면 됩니다. 날짜별로 파일명이 만들어 지므로 특정한 이름으로 파일명을 변경하여 여러개의 백업본을 유지할 수도 있습니다.
4.복구방법.
복구는 젠투의 설치시와 유사하게 진행됩니다. 라이브cd로 부팅을 한 후 mkfs.ext3등으로 젠투가 설치될 디렉토리를 깨끗하게 지운다음 마운트하고 백업해 놓은 파일을 담은 장치를 임의의 디렉토리를 생성하여 마운트하여 백업파일을 /mnt/gentoo에 복사한 후 압축을 풀어줍니다.
그리고 proc디렉토리는 백업되지 않았으므로 proc디렉토리를 /mnt/gentoo/proc에 만들어 준후 mount -t proc proc /mnt/gentoo/proc 로 마운트합니다.
마지막으로 chroot로 /mnt/gentoo 로 루트디렉토리를 바꿉니다. /etc/make.conf등의 옵션파일이 그대로 남아있으므로 네트웍 설정을 확인한 후 emerge sync를 수행합니다. (이과정에서 시간이 좀 걸립니다.)
커널 이미지를 받아와서 컴파일 하여 /boot에 복사해 주고 그럽을 설치합니다. (저는 /boot를 /dev/hda1에 따로 만들어 주었더니 이 과정이 필요 없었습니다.)
이제 exit로 chroot를 빠져나가서 마운트한것들을 다 풀고 재부팅합니다.
5. Great!!!
백업한 상태 그대로 복구가 완료되었습니다.
오오.. 한번 실험해 봐야겠당..
오오.. 한번 실험해 봐야겠당..
ㅡ_ㅡ;
젠투 사용자에겐 유용한 팁이겠군요~tar 로 묶어둬야지 둬야지 .
젠투 사용자에겐 유용한 팁이겠군요~
tar 로 묶어둬야지 둬야지 ... 생각만 하고 보통 귀찮아서 stage3 로 묶어둘 생각만 했었거든요
자료 감사드립니다.
http://kkanari.egloos.com/
[quote="tinywolf"]오오.. 한번 실험해 봐야겠당..[/qu
이 스크립트를 알게 되고 나서 삽질 후 재설치의 공포에서 벗어나게 되었죠 ㅜㅜ
그 얼마나 많은 재설치를 했었던지....
^^ 별말씀을요 저도 다 배운 것들인데요.
---
---
키체의 힘으로 당신에게 평안을...
댓글 달기