#!/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.2005 # Modify Date : 12.06.2005 by kkanari.org version=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=/backup/gentoo/stage4/ # 백업파일이름결정 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=/backup/*" # 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 backup Best (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 done case $option in [1,3]) stage4Name=$stage4Location/$stage4prefix-minimal.tar default_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.tar for 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 done case $option in 2) stage4postfix="gz" zip="gzip";; *) stage4postfix="bz2" zip="bzip2";; esac ;; esac tar_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 done if [ "$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 /boot else 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"