¿ù°£ Àα⠰Խù°

°Ô½Ã¹° 56°Ç
   
¹é¾÷½ºÅ©¸³Æ® (SAMBA) rsync + mysqldump + mysql tar + home tar
±Û¾´ÀÌ : ÃÖ°í°ü¸®ÀÚ ³¯Â¥ : 2011-02-28 (¿ù) 21:53 Á¶È¸ : 10893
±ÛÁÖ¼Ò :
                          

SAMBA ¸¶¿îÆ® µð½ºÅ©·Î ¹é¾÷
 [root@chonnom root]# df -Th
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda1     ext3     71G  6.0G   61G   9% /
tmpfs        tmpfs    947M     0  947M   0% /dev/shm
//KB2.SMILESERV.COM/KB212308
              cifs    100G  1.5G   99G   2% /SMILESERV_100G_BACKUP
 
backup_info (¹é¾÷ÇÒ µ¥ÀÌŸÁ¤º¸)
#!/bin/bash
today=`date +%Y-%m%d`;
sysdtime=`date +%Y-%m%d-%H%M`;
Mount_DIR=/SMILESERV_100G_BACKUP
 
# Rsync Clon Backup
rsync_src=/home
rsync_dst=$Mount_DIR/rsync

# MYSQL Backup
mysql_rootpasswd="root";
mysql_host="localhost"
mysql_backup_period=5;
reportmailto="";
mysql_data_src=/usr/local/mysql/var;
mysql_dst="$Mount_DIR/tar/mysql";
mysql_dump="/usr/local/mysql/bin/mysqldump";
mysql_show="/usr/local/mysql/bin/mysqlshow";

# Directory Backup
home_backup_period=30
full_backup_week="Sun|ÀÏ"
home_src="/home"
home_dst="$Mount_DIR/tar/home"
home_dst_full="$Mount_DIR/tar/home/full";
home_dst_difference="$Mount_DIR/tar/home/difference";
 
 
config (SAMBA ¸¶¿îÆ®µÈ°÷ÀÇ Á¢¼ÓÁ¤º¸)
 #!/bin/bash
username="mojily";
password="********";
backup_serverip="KB2.SMILESERV.COM";
 
 
home_tar.sh (Ȩ¹é¾÷ : 1ÁÖÀÏ¿¡ 1¹ø Àüü¹é¾÷, ³ª¸ÓÁö Â÷µî¹é¾÷)
#!/bin/sh
source $(dirname $0)/config
source $(dirname $0)/backup_info
 
if [ ! -d $Mount_DIR ]; then
        mkdir -p $Mount_DIR;
fi
 
if [ ! -d "$home_dst_full" ]; then
        mkdir -p $home_dst_full;
fi;
 
if [ ! -d "$home_dst_difference/$today" ]; then
        mkdir -p $home_dst_difference/$today;
fi;
 
# Áö³­ µ¥ÀÌŸ »èÁ¦
find $home_dst_full -ctime +$home_backup_period \-exec rm -rf {} \;
find $home_dst_difference -ctime +$home_backup_period \-exec rm -rf {} \;
 
# ¹é¾÷½ÃÀÛ
cd $home_src;
 
for home_name in $(ls);
do
if [ $home_name = "lost+found" ]; then
continue;
fi;
 
if [ $home_name = "$(echo $Mount_DIR |cut -d"/" -f3)" ]; then
continue;
fi;
 
if [ -d "$home_src/$home_name" ] ; then
        full_backup_date=`echo $(date +%a) |egrep $full_backup_week`
        if [ ! -z $full_backup_date ]; then
        tar -pczf "$home_dst_full/$home_name-$sysdtime.tar.gz" "$home_name";
        else
        tar -N "`cat $home_dst/last`" -pczf "$home_dst_difference/$today/$home_name-$sysdtime.tar.gz" "$home_name";
        fi;
fi;
done;
date +"%Y-%m-%d %T" > $home_dst/last;
 
 
mysql_backup.sh (dump ¹é¾÷ ¹× tar ¾ÐÃà¹é¾÷)
#!/bin/bash
source $(dirname $0)/config
source $(dirname $0)/backup_info
 
if [ ! -d "$mysql_dst" ]; then
        mkdir -p $mysql_dst;
fi;

mysql_backupdir="${mysql_dst}/$today";
find $mysql_dst -ctime +$mysql_backup_period \-exec rm -rf {} \;
 
db_compress="0"
not_dump_db="test|test2"
mysql_connect="-h $mysql_host -u root -p$mysql_rootpasswd";
mysql_DBs=`$mysql_show $mysql_connect 2>/dev/null | egrep -v "(${not_dump_db}|Databases|\+)" | awk '{print $2}'`
mysql_dump_work() {
        mysql_each_DB="$1"
        mysql_dump_file="${mysql_backupdir}/${mysql_each_DB}-${sysdtime}.sql"
        $mysql_dump $mysql_connect $mysql_each_DB > $mysql_dump_file
        if [ "$db_compress" = "1" ] ; then
                gzip -f9 $mysql_dump_file
        fi
}
 
if [ "$mysql_DBs" != "" ] ; then
        if [ ! -d "$mysql_backupdir" ] ; then
                mkdir -p "$mysql_backupdir"
                chmod 700 "$mysql_backupdir"
        fi
        for mysql_DB in $mysql_DBs ; do
                mysql_dump_work $mysql_DB
        done
 
else
        ## MySQLÀÌ °¡µ¿ÁßÀÌÁö ¾ÊÀ» °æ¿ì
        ## ÁÖ) ¾Æ·¡¿¡¼­ ${IFS}=$IFS HTML¿¡¼­ <BR>°ú °°À½.
        ##
        if [ "$reportmailto" != "" ] ; then
                mailsubject="dailydump.cron report [${HOSTNAME}]"
                mailmessages="MySQLÀÌ °¡µ¿ÇÏÁö ¾Ê°Å³ª DB°¡ ¾ø½À´Ï´Ù.${IFS}
MySQL ¼­¹ö(${mysql_host}) È®ÀÎÇϼ¼¿ä!!!"
                echo "$mailmessages" | mail -s "$mailsubject" "$reportmailto" >/dev/null 2>&1
        fi
fi
 
# ¾ÐÃà ¹é¾÷
tar jcvfp "$mysql_backupdir/All_Database_${sysdtime}.tar.bz2" "$mysql_data_src";
 
 
rsync_backup.sh (µ¿±âÈ­ ¹é¾÷)
 #!/bin/bash
source $(dirname $0)/config
source $(dirname $0)/backup_info

if [ ! -d $rsync_dst ] ; then
        mkdir -p $rsync_dst;
fi
rsync -tripD --exclude-from=$(dirname $0)/exclude_list --delete $rsync_src $rsync_dst
 
¡Ø exclude_list (µ¿±âÈ­ÇÒ Æú´õ¿¡¼­ Á¦¿ÜÇÒ ÆÐÅÏ)
2011-0227
 

À̸§ Æнº¿öµå
ºñ¹Ð±Û (üũÇÏ¸é ±Û¾´À̸¸ ³»¿ëÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.)
¿ÞÂÊÀÇ ±ÛÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä.
   

 



 
»çÀÌÆ®¸í : ¸ðÁö¸®³× | ´ëÇ¥ : ÀÌ°æÇö | °³ÀÎÄ¿¹Â´ÏƼ : ·©Å°´åÄÄ ¿î¿µÃ¼Á¦(OS) | °æ±âµµ ¼º³²½Ã ºÐ´ç±¸ | ÀüÀÚ¿ìÆí : mojily°ñ¹ðÀÌchonnom.com Copyright ¨Ï www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.