linux 杂记

一、设置定时任务 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 ‘‘

 

  

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。