您现在的位置是:首页 > 后台技术 > 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("备份成功!");
}
}

很赞哦! ()
上一篇:Servlet过滤器
下一篇:JSP简要记录
随机图文
ActiveMQ学习记录(图文)
昨天用了1个下午的时间学习了ActiveMQ东西,为了以后要用的时候方便查询,记录一下。springboot发送邮件(图文)
springboot发送邮件封装系统配置参数工具类(图文)
以前记得有一个方法可以把配置文件中的配置信息读取到一个类中,这样在项目里用的时候就会很方便了,但是不记得怎么写了,今天特意找了找资料,记录下来,以后想用的化,直接来这里看就好springboot实现不同业务的日志打印到不同的文件中(图文)
这几天有个项目的日志信息比较多,需要把不同业务的日志打印到不同的文件中去,今天在公司搞了很久都没搞定,晚上回来搞,终于搞定了,记录一下。