首页 > 代码库 > linux 杂记
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/logecho $(date +"%Y-%m-%d %H:%M:%S")username="root" # USERNAMEpassword="123456" # PASSWORD Hostname="localhost" # HostnameDBName="PortMasterList" #DB name#DBName="testMavenWeb"programProt="8080"#max save backup file numbermaxBackUpFileCount=5# Linux bin paths, change this if it can not be autodetected via which commandMYSQL="$(which mysql)"MYSQLDUMP="$(which mysqldump)"CHOWN="$(which chown)"CHMOD="$(which chmod)"GZIP="$(which gzip)"# Main directory where backup will be storedbackupDir="/opt/mysql_backup/"$DBName# if not exsis then mkdir[ ! -d $backupDir ] && mkdir -p $backupDir || :# Get data in dd-mm-yyyy formatNOW="$(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 direcho ‘usenrame:‘$username ‘password:‘$password ‘DBName:‘$DBName$MYSQLDUMP -u $username -h $Hostname -p$password $DBName > $FILE# check the backup is successsuccess="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:‘$FILEfi#curl calling java to send emailcurl ‘http://‘$Hostname‘:‘$programProt‘/PortMasterListPortal/ajax/sendBackup.html?success=‘$success‘&secureKey=xxx‘echo ‘‘
linux 杂记
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。