mysql开机启动脚本_centos简单的mysql开机自启和自动保存脚本
1.備份
寫一個testdbbackup.sh文件
------------------------
#!/bin/sh
DBName=test
DBUser=root
DBPasswd=root
BackupPath=/root/ db
mysqldump -u$DBUser -p$DBPasswd $DBName > /root/db/`date -I`_$DBName.sql
#刪除7天以前的
#find /root/db -name $DBName.sql -mtime +7 -exec rm {} ;
--------------------------
./testdbbackup.sh看看備份出來的東西在不在?
自動備份
crontab -l
查看現有的多少任務
crontab -e
編輯定時任務每天23點10分備份
10 23 * * * /root/testdbbackup.sh
/sbin/service crond start //啟動服務
/sbin/service crond stop //關閉服務
/sbin/service crond restart //重啟服務
/sbin/service crond reload //重新載入配置
錯誤:/bin/sh^M: bad interpreter
是結尾的window下換行符導致,一般看不見,在vi里面檢查一下結尾吧
2,開機啟動
在/etc/rc.d/rc.local文件末尾添加
1、編輯rc.local文件
#vi /etc/rc.d/rc.local
2、加入如下啟動命令/etc/rc.d/init.d/mysqld start
aphce日志-----以下沒有驗證
access-log太大,CustomLog 前面全加#號
httpd-error.log 太大,修改LogLevel warn 為err
要不然
#!/bin/bash
YESTERDAY=`date -d yesterday +%Y%m%d`
/usr/bin/gzip -c /var/log/httpd/access_log>/var/log/httpd/access${YESTERDAY}.log.gz
>/var/log/httpd/access_log
/usr/bin/gzip -c /var/log/httpd/error_log>/var/log/httpd/error${YESTERDAY}.log.gz
>/var/log/httpd/error_log
chmod u+x /var/log/httpd/log-task.cron
測試:
/var/log/httpd/log-task.cron
crontab -e
然后將以下的的代碼拷貝加入到cron的啟動腳本末尾:
1 0 * * * /var/log/httpd/log-task.cron
分享到:
2012-05-28 15:01
瀏覽 504
評論
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的mysql开机启动脚本_centos简单的mysql开机自启和自动保存脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 什么是贷款程序 贷款的审查和发放
- 下一篇: mysql 临时文件目录_MySQL数据