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

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2012-05-28 15:01

浏览 504

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值