centos简单的mysql开机自启和自动保存脚本

来源:互联网 发布:移动硬盘怎么恢复数据 编辑:程序博客网 时间:2024/05/17 22:06

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


 


 

 

 

原创粉丝点击