안녕하세요? MEGA IDC 서버운영팁입니다.
mysql 자동 백업을 위한 스크립트 작성 방법입니다.
#!/bin/sh
###################
# mysql backup tools #
# code by colorweb #
###################
_USERNAME="root"
_PASSWORD="비번"
_BACKUP_DIR="/backup/db/"
c_time="3"
/usr/bin/mysqladmin -u $_USERNAME -p$_PASSWORD reload >& /dev/null
mkdir -p $_BACKUP_DIR$(date +%Y%m%d)
now_db=`echo "show databases" | /usr/bin/mysql -u $_USERNAME -p$_PASSWORD`
num=1
for dir in $now_db ; do
if [ $dir != "Database" ]; then
/usr/bin/mysqldump -u $_USERNAME -p$_PASSWORD \
--databases $dir > $_BACKUP_DIR$(date +%Y%m%d)/$dir-$(date +%Y%m%d).sql
echo "Database - $dir - Backup Complete!!"
num=$(($num+1))
fi
find $_BACKUP_DIR* -ctime $c_time -exec rm -rf {} \;
done
=================
30 4 * * * /etc/cron.d/db.sh
0 6 * * * find /backup/db -mtime +3 -exec rm -f {} \;