AYUDA PARA RESPALDAR TRIGGERS
Publicado por Karina (1 intervención) el 07/08/2019 03:51:45
Hola, estoy realizando un programa java con Base de datos, el programa desde el codigo utiliza WampServer para los respaldos, y noto que no está respaldando los triggers que hay en la base de datos, tampoco se respaldan si hago el backup desde el administrador de mysql...
¿Alguien podría ayudarme?
¿Alguien podría ayudarme?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package d_etiqueta;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
public class Respaldos {
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
public static String variable ="";
/**
*
* @author Farid
*/
public Respaldos() {
}
public void crear() {
// configuracion de la fecha actual
Calendar c = Calendar.getInstance();
String fecha = String.valueOf(c.get(Calendar.DATE));
fecha = fecha + "-" + String.valueOf(c.get(Calendar.MONTH));
fecha = fecha + "-" + String.valueOf(c.get(Calendar.YEAR));
// clase Runtime para lanzar DOS
Runtime runtime = Runtime.getRuntime();
//se prepara File para con la ruta
File backup = new File("C:\\backupPuntoDeRenta");
// se crea la ruta, si no existe crea la ruta completa
backup.mkdirs();
//preparamos el backupfile con la ruta
//y el archivo sql que tendra la fecha y hora de creacion
File backupFile = new File("C:\\backupPuntoDeRenta\\backup" + "_" + fecha + ".sql");
variable=backupFile+"";
try {
InputStreamReader irs;
BufferedReader br;
//preparamos el filewrite para guardar el backup
FileWriter filewrite = new FileWriter(backupFile);
//ruta donde se encuntra mysqldump
String patch = "C:\\wamp\\bin\\mysql\\mysql5.6.17\\bin\\";
//se lanza el DOS
Process child = runtime.exec(patch
+ "mysqldump -h localhost -u root -psistemas etiqueta --triggers");
// "mysqldump -h sql9.freemysqlhosting.net -u sql9298452 -pvCZCYqAwsS sql9298452 --triggers"); PARA RESPALDAR DEL SERVIDOR
/* Se obtiene el stream de salida del programa */
irs = new InputStreamReader(child.getInputStream());
/* Se prepara un BufferedReader para poder leer la salida más comodamente. */
br = new BufferedReader(irs);
String line;
//mientras exista una linea
while ((line = br.readLine()) != null) {
filewrite.write(line + "\n");
}
// terminamos los servicios
irs.close();
br.close();
filewrite.close();
} catch (IOException e) {
System.out.println("Error.. No se realizo el backup!");
System.out.println(e);
}
}
public void borrarArchivoDirectorio() {
String direccion = "C:\\backupPuntoDeRenta";
File directorio = new File(direccion);
File f;
if (directorio.isDirectory()) {
String[] files = directorio.list();
if (files.length > 5) {//borrar despues de 5 dias
for (String archivo : files) {
f = new File(direccion + File.separator + archivo);
long Time;
Time = (System.currentTimeMillis() - f.lastModified());
long cantidadDia = (Time / 86400000);
// Attempt to delete it
//86400000 ms is equivalent to one day
if (cantidadDia>5) {
System.out.println("Borrado:" + archivo);
f.delete();
f.deleteOnExit();
}
}
}
}
}
}
Valora esta pregunta


0