Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String PATH = "";
- if(WebRequest.isUnix()) {
- PATH = SEPARATOR+"backup";
- } else {
- PATH = System.getProperty("ROOT_DIR")+SEPARATOR+"backup";
- }
- File BACKUP_DIR = new File(PATH);
- BACKUP_DIR.mkdir();
- LOGGER.info("BACKUP DIR - "+BACKUP_DIR);
- File FILE = new File(BACKUP_DIR+SEPARATOR+"backup"+new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime())+".sql");
- if(FILE.exists()) {
- Files.deleteIfExists(FILE.toPath());
- }
- LOGGER.info("BACKUP FILE - "+FILE);
- String CMD = "";
- if(WebRequest.isUnix()) {
- CMD = "/usr/bin/mysqldump --host=localhost --user=root --password=root bitstep > "+FILE.getPath();
- } else {
- CMD = "E:\Programs\Xampp\mysql\bin\mysqldump.exe -u root -p root --database bitstep -r " + FILE.getPath();
- }
- LOGGER.info("EXECUTE COMMAND - "+CMD);
- if(!CMD.isEmpty()) {
- Process runtimeProcess = Runtime.getRuntime().exec(CMD);
- int processComplete = runtimeProcess.waitFor();
- if (processComplete == 0) {
- LOGGER.info("Backup Complete");
- } else {
- LOGGER.info("Backup Failure");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement