您现在的位置是:首页 > 后台技术 > 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("备份成功!");
}
}
@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("备份成功!");
}
}
![](/d/file/p/2019/07-22/11256d91dd620466443fa9a48514d939.png)
很赞哦! ()
上一篇:Servlet过滤器
下一篇:JSP简要记录
随机图文
代码简洁之道-mapstruct(图文)
mapstruct的简单介绍及使用彻底搞懂字符编码(图文)
彻底搞懂字符编码springboot实现不同业务的日志打印到不同的文件中(图文)
这几天有个项目的日志信息比较多,需要把不同业务的日志打印到不同的文件中去,今天在公司搞了很久都没搞定,晚上回来搞,终于搞定了,记录一下。微服务springcloud(图文)
微服务就是由一系列围绕自己业务开发的微小服务构成,他们独立部署运行在自己的进程里,基于分布式的管理 微服务是一种架构方式: 将单一应用基于业务拆分多个微小服务,他们独立运行 独立部署 每个服务运行在自己计算机进程里面 对于这些服务都是分布式管理。 这种架构是将单个的整体应用程序分割成更小的项目关联的独立的服务。一个服务通常实现一组独立的特性或功能,包含自己的业务逻辑和适配器。各个微服务之间的关联通过暴露api来实现(http)。这些独立的微服务不需要部署在同一个虚拟机,同一个系统和同一个应用服务器中