B / Y / U / S
HOME À¥ È£½ºÆà µµ¸ÞÀÎ ¸Å´º¾ó °í°´Áö¿ø ¼³Á¤Á¤º¸ °èÁ¤½Åû 2024-12-23 Monday 
À¥ È£½ºÆÃ
# °øÁö »çÇ×
# ÀÚÁÖ ¹¯´Â Áú¹®
# Áú¹®°ú ´äº¯
# °¡ÀÔ ¹®ÀÇ
Ä¿¹Â´ÏƼ
# ÀÚÀ¯°Ô½ÃÆÇ
# ¸®´ª½ºÆÁ
# ¾ÆÀÌÅ¥ Å×½ºÆ®
# ³»È¨ ¼Ò°³
# °Ö·¯¸®
# ÀÚ·á½Ç

  ¸®´ª½ºÆÁ  Go Unix Power Tools Online Book Go Bash Guide
Read No. 25 article 2001-08-13 23:40:23
NickName   Ç®ºñ´©
Subject   Cron À¸·Î MySQL- ¹é¾÷¹Þ±â..


#!/bin/bash 
BACKUP_DIR=/var/backup 
FILE_PFX =MY_DB 

DATE=$(date +%Y%m%d) 
OF = $FILE_PFX-$DATE.sql 
rm -rf $BACKUP_DIR/$FILE_PFX-*.sql 

mysqldump -uUSER -pPASS DB_NAME > $BACKUP_DIR/$OF 


°£´ÜÈ÷ ¸¸µé¾î º¸¾Ò½À´Ï´Ù. 
¹é¾÷µ¥ÀÌŸ´Â MY_DB-20010228.sql ÀÌ·±½ÄÀ¸·Î 
/var/backup ¹Ø¿¡ »ý±é´Ï´Ù. 

BACKUP_DIR Àº ¹é¾÷¹Þ°í ½ÍÀº µð·ºÅ丮 À̱¸¿ä.. 
FILE_PFX Àº ÀúÀåÇÒ ÆÄÀÏ À̸§ÀÇ ÇÁ¸®ÇȽº Á¤µµ.. 
³¯¸¶´Ù ¹é¾÷µÈ°É °¡Áö°í ÀÖ°í ½ÍÀ¸½Ã¸é(ÃæºÐÇÑ Çϵå¿ë·®ÀÌ µÈ´Ù¸é) 
rm -rf ........ ÀÌÁÙÀº ÁÖ¼®Ã³¸®Çصµ ¹«¹æ.. 
mysqldump ´ÙÀ½Àº ¾ËÁÒ? »ç¿ëÀÚ¸í°ú Æнº¿öµå DB¸í.. 

/etc/cron.daily ¹Ø¿¡ º¹»çÇØÁֽðí.. 
½ÇÇà ±ÇÇÑ ÁÖ½Ã¸é µË´Ï´Ù.  








------ /etc/cron.daily/mysqlcump.cron -------------------
#!/bin/sh
#
#
## Chilbong, Kim <san2 at linuxchannel.net>
## 2001.03.01
## http://www.linuxchannel.net
##
##
###########################################
##
## This file name : "mysqldump.cron"
## cp mysqldump.cron /etc/cron.daily/
## chmod 700 /etc/cron.daily/mysqldump.cron
##
###########################################
## user setting
##
##
mysql_host="localhost"
mysql_rootpasswd="xxxxxxx"
backupdir="/var/backup"
mysql_backupdir="${backupdir}/mysqldump"
mysql_dump="/usr/local/mysql/bin/mysqldump"
mysql_show="/usr/local/mysql/bin/mysqlshow"
##
## Are you compress 'xxxx-2001xxxx-xx.sql' ?
##     1 = yes(xxxx-2001xxxx-xx.sql.gz)
##     0 = no
db_compress="1"
##
## end user setting !!!
############################################

sysdtime=`date +%Y%m%d-%H`
mysql_connect="-h $mysql_host -u root -p$mysql_rootpasswd"
mysql_DBs=`$mysql_show $mysql_connect | egrep -v "(Databases|\+)" | awk 
'{print $2}' 2>/dev/null`

mysql_dump_work() {
        mysql_each_DB="$1"
        mysql_dump_file="${mysql_backupdir}/${mysql_each_DB}-${sysdtime}.sql"
        $mysql_dump $mysql_each_DB > $mysql_dump_file
        if [ "$db_compress" = "1" ] ; then
                gzip -9 $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

        chmod -R 600 $mysql_backupdir
        #chown -R root $mysql_backupdir

fi

exit 0
-----------------------------------------------------------------
Regist Addr [ 127.0.0.1 ] ¸ñ·Ïº¸±â À­±Û ¾Æ·§±Û
Á¤±ÔÇ¥Çö½Ä [ »ó¼¼ °Ë»ö ]
Page Loading [ 0.02 Sec ] SQL Time [ 0 Sec ]

Copyleft 1999-2024 by JSBoard Open Project
Theme Designed by IDOO And follow GPL2

°³ÀÎÁ¤º¸ Ãë±Þ¹æħ ÀÌ¿ë ¾à°ü »çÀÌÆ® ¸Ê ¾îµå¹Î °ü¸®