您现在的位置是:首页 > 后台技术 > JavaJava

JAVA定时备份数据库(图文)

第十三双眼睛2019-07-22【Java】人已围观

简介定时备份数据库非常重要,记录一下,以后用的时候随时来找

以前在公司工作的时候,记得有个定时备份数据库的功能,觉得挺有用的,记录一下
@Component
public class TestTask {
//@Scheduled(cron="0/30 * * * * *")
public void  test() throws IOException{
System.out.println("定时任务测试");
String pathSql = "d:/1.sql";
        File fileSql = new File(pathSql);
        //创建备份sql文件
        if (!fileSql.exists()){
            fileSql.createNewFile();
        }
        //mysqldump -hlocalhost -uroot -p123456 db > /home/back.sql
        StringBuffer sb = new StringBuffer();
        sb.append("mysqldump");
        sb.append(" -h localhost");
        sb.append(" -u"+" root");
        sb.append(" -p"+"123456");
        sb.append(" "+"yyg"+" >");
        sb.append(pathSql);
        System.out.println("cmd命令为:"+sb.toString());
        Runtime runtime = Runtime.getRuntime();
        System.out.println("开始备份:"+"yyg");
        Process process = runtime.exec("cmd /c"+sb.toString());
        System.out.println("备份成功!");
}
}

Tags:JAVA   定时任务   数据库

很赞哦! ()

上一篇:Servlet过滤器

下一篇:JSP简要记录

文章评论

    共有条评论来说两句吧...

    用户名:

    验证码:

站点信息

  • 网站名称:JavaStudy
  • 建站时间:2019-1-14
  • 网站程序:帝国CMS7.5
  • 文章统计242篇文章
  • 标签管理标签云
  • 统计数据百度统计
  • 微信公众号:扫描二维码,关注我们