private static bool RestaurarDatos(string archivo) { bool restaurarDatos = false; List <string> credentials = UtilVarios.GetCredentialsDB(); string server = credentials[0]; string user = credentials[1]; string database = credentials[2]; string pass = credentials[3]; UtilDB.UnzipDB(archivo); archivo = archivo.Substring(0, archivo.Length - 3); UtilDB.RestoreDB(server, 3306, user, pass, database, archivo); // compruebo si se restauraron los datos Char delimiter = '_'; String[] substrings = archivo.Split(delimiter); int pc = Convert.ToInt32(substrings[2].Substring(2)); string fecha = substrings[3].Substring(0, 10); int registroRestaurado = DAL.DatosDAL.RegistroRestaurado(fecha, pc); if (registroRestaurado > 0) { restaurarDatos = true; } return(restaurarDatos); }
// EXPORTAR DATOS POS public static void ExportarDatos() { credentials = UtilVarios.GetCredentialsDB(); server = credentials[0]; user = credentials[1]; database = credentials[2]; pass = credentials[3]; DataTable tbl = BL.GetDataBLL.RazonSocial(); idRazonSocial = tbl.Rows[0][0].ToString(); strFile = idRazonSocial + "_datos.sql"; UtilDB.DumpDatos(server, user, pass, database, @"c:\windows\temp\" + strFile); if (ValidarDump()) { if (File.Exists(@"c:\windows\temp\" + strFile + ".xz")) { File.Delete(@"c:\windows\temp\" + strFile + ".xz"); } UtilDB.ZipDB(@"c:\windows\temp\" + strFile); strFile = strFile + ".xz"; Reintentar: UtilFTP.UploadFromFile(@"c:\windows\temp\" + strFile, "/datos/" + strFile); UtilFTP.DownloadFile(@"c:\windows\temp\tmp_" + strFile, "/datos/" + strFile); if (!UtilVarios.FileCompare(@"c:\windows\temp\tmp_" + strFile, @"c:\windows\temp\" + strFile)) { if (intentosUpload < 5) { intentosUpload++; goto Reintentar; } } } else { if (intentosDump < 5) { intentosDump++; ExportarDatos(); } } intentosUpload = 0; intentosDump = 0; }
private static bool ValidarDump() { bool comprobarDump = true; DAL.DatosDAL.DeleteAll(); UtilDB.RestoreDB(server, 3306, user, pass, "dump_admin", "C:\\Windows\\Temp\\" + strFile); DataSet ds = DAL.DatosDAL.ControlarUpdate(); int records; foreach (DataTable tbl in ds.Tables) { records = Convert.ToInt16(tbl.Rows[0][0].ToString()); if (records == 0) { comprobarDump = false; break; } } return(comprobarDump); }