1. 程式人生 > 其它 >【洛谷】P3188 [HNOI2007]夢幻島寶珠(01揹包+二進位制)

【洛谷】P3188 [HNOI2007]夢幻島寶珠(01揹包+二進位制)

#!/bin/bash

#-----------------------------------------------------------------------------
# Author:Bathing
# Function:This script will be used for mysql backups,It was created by Bathing.
# Date:2021-07-22
# QQinfo:576590916
# work on Mysql_5.7
#-----------------------------------------------------------------------------
#設定顏色顯示
SETCOLOR_SUCCESS="echo -en \\033[0;32m"
SETCOLOR_FAILURE="echo -en \\033[0;31m"
SETCOLOR_WARNING="echo -en \\033[0;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"

#設定登陸變數
MY_USER=""
MY_PASS=""
MY_PORT=""
MY_HOST="localhost"

#mysql安裝目錄
name=/www/server/mysql

#user
USER=`whoami`

#備份的資料庫名,可定義多個數據庫,中間以空格隔開,如: (test test1 test2)
dbname=()

#備份路徑
backpath=${name}/backup

#備份的時間
DATA=$(date +%Y%m%d-%H%M)

#日誌備份路徑
logpath=${name}/log

#指令碼執行賬號為root賬戶
ACCOUNT_JUDGE_FUN () {

if [ "$(whoami)" != "root" ];then
${SETCOLOR_WARNING} && echo "warning:please use root account install cloudroom system!" && ${SETCOLOR_NORMAL}
exit 1
fi

}
ACCOUNT_JUDGE_FUN

#建立備份路徑
mkdir -p ${logpath}
chown -R mysql:mysql ${logpath}
mkdir -p ${backpath}
touch ${logpath}/mysqlbackup.log

#開始備份資料庫
for db in ${dbname[*]}; do
/usr/bin/mysqldump -u${MY_USER} -h${MY_HOST} -P${MY_PORT} -p${MY_PASS} --single-transaction ${dbname} > ${backpath}/${db}-${DATA}.sql 2>/dev/null
#備份成功以下操作
if [ "$?" == 0 ];then
cd ${backpath}
#備份日誌記錄
echo ================================================ >> ${logpath}/mysqlbackup.log
echo 備份時間為${DATA},開始備份${db}資料庫...>> ${logpath}/mysqlbackup.log
#為節約硬碟空間,將資料庫壓縮
tar zcf ${db}${DATA}.tar.gz ${db}-${DATA}.sql > /dev/null
#刪除原始檔案,只留壓縮後文件
rm -f ${backpath}/${db}-${DATA}.sql
echo The mysql database is backed up successfully!! >> ${logpath}/mysqlbackup.log
echo ================================================ >> ${logpath}/mysqlbackup.log
else
#備份失敗則進行以下操作
echo Failed to back up the mysql database. Procedure!! >> ${logpath}/mysqlbackup.log
echo ================================================ >> ${logpath}/mysqlbackup.log
fi
done
#保留7天的資料備份

find ${backpath} -mtime +7 -name "*.gz" -exec rm -rf {} \;

記錄工作中的一下問題