본문
#!/bin/sh
DATE=$(date '+%y%m%d')
BACKUP_DIR=/volumeUSB1/usbshare/Backup/dump
BACKUP_DIR=/Backup/dump
DB_PASSWD="password"
DB_LIST=`echo "show databases;" | mysql -N -uroot --password=$DB_PASSWD`
#echo $DB_LIST;
# 백업하지 않을 디비
NOT_DB_LIST=(information_schema performance_schema tmp temp test mysql phpmyadmin test dbispconfig gnu_test1 gnu_test2 gnu_test3 gnu_test4 gnu_test5 performance_schema sys)
if [ -d "$BACKUP_DIR" ] ; then
for DB in $DB_LIST
do
#처리 안할 DB
is_ok=true
for element in "${NOT_DB_LIST[@]}"; do
if [[ "$element" == "$DB" ]]; then
#echo "Not DB $element"
is_ok=false
fi
done
if [[ "$is_ok" == 'false' ]]; then
continue;
fi
#echo "OK DB: $DB"
#continue;
DUMP_FILE="$BACKUP_DIR/$DB.$DATE.sql";
#echo "DUMP_FILE: $DUMP_FILE"
nice -15 mysqldump \
--single-transaction \
--skip-disable-keys \
--skip-lock-tables \
--skip-add-locks \
--quick \
--password=$DB_PASSWD \
$DB > $DUMP_FILE
nice -15 tar cfj $DUMP_FILE.bz2 $DUMP_FILE
rm -f $DUMP_FILE;
done
fi
--------------------------------------------------------------------------
in_array 함수 이용 루틴
#!/bin/sh
DATE=$(date '+%y%m%d')
BACKUP_DIR=/volumeUSB1/usbshare/Backup/dump
BACKUP_DIR=/Backup/dump
DB_PASSWD="password"
DB_LIST=`echo "show databases;" | mysql -N -uroot --password=$DB_PASSWD`
#echo $DB_LIST;
# 백업하지 않을 디비
NOT_DB_LIST=(information_schema performance_schema tmp temp test mysql phpmyadmin test dbispconfig gnu_test1 gnu_test2 gnu_test3 gnu_test4 gnu_test5 performance_schema sys)
in_array() {
local needle array value
needle="${1}"; shift; array=("${@}")
for value in ${array[@]}; do [ "${value}" == "${needle}" ] && echo "true" && return; done
echo "false"
}
if [ -d "$BACKUP_DIR" ] ; then
for DB in $DB_LIST
do
#처리 안할 DB
if [ `in_array $DB ${NOT_DB_LIST[@]}` == 'true' ]; then
#echo "Not DB $DB"
continue;
fi
#echo "OK DB: $DB"
#continue;
DUMP_FILE="$BACKUP_DIR/$DB.$DATE.sql";
#echo "DUMP_FILE: $DUMP_FILE"
nice -15 mysqldump \
--single-transaction \
--skip-disable-keys \
--skip-lock-tables \
--skip-add-locks \
--quick \
--password=$DB_PASSWD \
$DB > $DUMP_FILE
nice -15 tar cfj $DUMP_FILE.bz2 $DUMP_FILE
rm -f $DUMP_FILE;
done
fi
댓글목록
등록된 댓글이 없습니다.