码迷,mamicode.com
首页 > 系统相关 > 详细

linux 杂记

时间:2014-08-26 11:27:55      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   java   for   2014   div   

一、设置定时任务 crontab

  新增:crontab -e

 

二、日志查看

  tail -200f logs/catalina.out

 

三、mysql备份shell

  

#!/bin/bash
# Shell script to backup MySql database
# Author: Henry he
# Last updated: 2014-08-25
# crontab -e
# 0 8 * * 1 /home/elkan/H_Docs/PortMasterListPortal/backup.sh >> /opt/mysql_backup/log

echo $(date +"%Y-%m-%d %H:%M:%S")

username="root"     # USERNAME
password="123456"       # PASSWORD 
Hostname="localhost"          # Hostname
DBName="PortMasterList" #DB name
#DBName="testMavenWeb"
programProt="8080"

#max save backup file number
maxBackUpFileCount=5

# Linux bin paths, change this if it can not be autodetected via which command
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
CHOWN="$(which chown)"
CHMOD="$(which chmod)"
GZIP="$(which gzip)"

# Main directory where backup will be stored
backupDir="/opt/mysql_backup/"$DBName

# if not exsis then mkdir
[ ! -d $backupDir ] && mkdir -p $backupDir || :

# Get data in dd-mm-yyyy format
NOW="$(date +"%Y-%m-%d-%H-%M-%S")"

FILE="$backupDir/$DBName.$NOW.bak"

# Only root can access it!
#$CHOWN 0.0 -R $backupDir
#$CHMOD 0600 $backupDir

# connect to mysql using mysqldump for select mysql database
# and pipe it out to file in backup dir
echo usenrame:$username password:$password DBName:$DBName
$MYSQLDUMP -u $username -h $Hostname -p$password $DBName > $FILE

# check the backup is success
success="true"
if [ ! -s "$FILE" ]; then 
    success="false"
    rm -f $FILE
    echo backup fail
else
    # delete the redundant backup files
    i=0
    for file in $(ls -t $backupDir)
    do
        i=`expr $i + 1`
        #echo $file
        if [ "$i" -gt "$maxBackUpFileCount" ]
        then
            $(rm -f "$backupDir/$file")
            echo rm file:"$backupDir/$file"
        fi
    done

    echo backup success file path:$FILE
fi

#curl calling java to send email
curl http://$Hostname:$programProt/PortMasterListPortal/ajax/sendBackup.html?success=$success&secureKey=xxx
echo ‘‘

 

  

 

linux 杂记

标签:style   blog   http   color   os   java   for   2014   div   

原文地址:http://www.cnblogs.com/hzm112567/p/3936774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!