parent
c81902e905
commit
b5f6a8d5ba
@ -0,0 +1,63 @@
|
|||||||
|
package com.ruoyi.web.controller.monitor;
|
||||||
|
|
||||||
|
import com.ruoyi.common.config.RuoYiConfig;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* packageName com.ruoyi.web.controller.monitor
|
||||||
|
*
|
||||||
|
* @author wangxy
|
||||||
|
* @version JDK 8
|
||||||
|
* @className BackupController
|
||||||
|
* @date 2024/9/13
|
||||||
|
* @description 数据库备份
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/monitor/backup")
|
||||||
|
public class BackupController extends BaseController {
|
||||||
|
|
||||||
|
private String prefix = "/monitor/backup";
|
||||||
|
|
||||||
|
@RequiresPermissions("monitor:backup:view")
|
||||||
|
@GetMapping()
|
||||||
|
public String backData() {
|
||||||
|
return prefix + "/backup";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("backups")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult backups(@RequestParam String username,
|
||||||
|
@RequestParam String password,
|
||||||
|
@RequestParam String hostname,
|
||||||
|
@RequestParam String port,
|
||||||
|
@RequestParam String databaseName) {
|
||||||
|
String sqlFileName = RuoYiConfig.getDataBaseBackUp() + ".sql";
|
||||||
|
File file = new File(File.separator + sqlFileName);
|
||||||
|
//目录生成
|
||||||
|
if (!file.getParentFile().exists()) {
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ProcessBuilder processBuilder = new ProcessBuilder("pg_dump", "-Fp", "-f", sqlFileName,
|
||||||
|
"\"host=" + hostname, "port=" + port, "user=" + username, "password=" + password, "dbname=" + databaseName + "\"");
|
||||||
|
Process process = processBuilder.start();
|
||||||
|
if (process.waitFor() == 0) {
|
||||||
|
return AjaxResult.success("备份成功!");
|
||||||
|
} else {
|
||||||
|
return AjaxResult.error("备份失败!");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return AjaxResult.error("备份失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,77 +1,25 @@
|
|||||||
package com.ruoyi.web.controller.monitor;
|
package com.ruoyi.web.controller.monitor;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.date.DatePattern;
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
|
||||||
import cn.hutool.core.util.NumberUtil;
|
|
||||||
import cn.hutool.core.util.ZipUtil;
|
|
||||||
import cn.hutool.system.OsInfo;
|
|
||||||
import cn.hutool.system.SystemUtil;
|
|
||||||
import com.ruoyi.common.config.RuoYiConfig;
|
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* druid 监控
|
* druid 监控
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/monitor/data")
|
@RequestMapping("/monitor/data")
|
||||||
public class DruidController extends BaseController
|
public class DruidController extends BaseController {
|
||||||
{
|
|
||||||
private String prefix = "/druid";
|
private String prefix = "/druid";
|
||||||
|
|
||||||
@RequiresPermissions("monitor:data:view")
|
@RequiresPermissions("monitor:data:view")
|
||||||
@GetMapping()
|
@GetMapping()
|
||||||
public String index()
|
public String index() {
|
||||||
{
|
|
||||||
return redirect(prefix + "/index.html");
|
return redirect(prefix + "/index.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("backups")
|
|
||||||
@ResponseBody
|
|
||||||
public AjaxResult backups(@RequestParam String username,
|
|
||||||
@RequestParam String password,
|
|
||||||
@RequestParam String hostname,
|
|
||||||
@RequestParam String port,
|
|
||||||
@RequestParam String databaseName) {
|
|
||||||
String sqlFileName = RuoYiConfig.getDataBaseBackUp() + ".sql";
|
|
||||||
File file = new File(File.separator + sqlFileName);
|
|
||||||
//目录生成
|
|
||||||
if (!file.getParentFile().exists()) {
|
|
||||||
file.getParentFile().mkdirs();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder("pg_dump", "-Fp", "-f", sqlFileName,
|
|
||||||
"\"host="+hostname, "port="+port, "user="+username, "password="+password, "dbname="+databaseName+"\"");
|
|
||||||
Process process = processBuilder.start();
|
|
||||||
if (process.waitFor() == 0) {
|
|
||||||
return AjaxResult.success("备份成功!");
|
|
||||||
} else {
|
|
||||||
return AjaxResult.error("备份失败!");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return AjaxResult.error("备份失败!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue