Ejemplo n.º 1
0
        public List <BackupInfo> GetBackups()
        {
            Lfx.Environment.Folders.EnsurePathExists(BackupPath);

            List <BackupInfo> Res = new List <BackupInfo>();

            System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo(this.BackupPath);
            foreach (System.IO.DirectoryInfo DirItem in Dir.GetDirectories("*.*"))
            {
                BackupInfo Backup = new BackupInfo();

                if (System.IO.File.Exists(this.BackupPath + DirItem.Name + System.IO.Path.DirectorySeparatorChar + "info.xml"))
                {
                    // Nuevo formato de archivo de información
                }
                else if (System.IO.File.Exists(this.BackupPath + DirItem.Name + System.IO.Path.DirectorySeparatorChar + "info.txt"))
                {
                    // Antiguo formato de información
                    string ArchivoIni = Lfx.Types.Strings.ReadTextFile(this.BackupPath + DirItem.Name + System.IO.Path.DirectorySeparatorChar + "info.txt");
                    Backup.Name           = DirItem.Name;
                    Backup.UserName       = Lfx.Types.Ini.ReadString(ArchivoIni, "", "Usuario");
                    Backup.CompanyName    = Lfx.Types.Ini.ReadString(ArchivoIni, "", "Empresa");
                    Backup.ProgramVersion = Lfx.Types.Ini.ReadString(ArchivoIni, "", "VersiónLazaro");
                    Backup.BackupDate     = DateTime.ParseExact(Lfx.Types.Ini.ReadString(ArchivoIni, "", "FechaYHora"), @"dd\-MM\-yyyy ""a las"" HH\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture);
                }

                Res.Add(Backup);
            }

            Res.Sort(delegate(BackupInfo b1, BackupInfo b2) { return(b1.BackupDate.CompareTo(b2.BackupDate)); });
            Res.Reverse();

            return(Res);
        }
Ejemplo n.º 2
0
 public void StartBackup(BackupInfo backupInfo)
 {
     System.Threading.ThreadStart BackupThread = delegate { this.Backup(backupInfo); };
     System.Threading.Thread      Thr          = new System.Threading.Thread(BackupThread);
     Thr.IsBackground = true;
     Thr.Start();
 }
Ejemplo n.º 3
0
 public void StartBackup(BackupInfo backupInfo)
 {
         System.Threading.ThreadStart BackupThread = delegate { this.Backup(backupInfo); };
         System.Threading.Thread Thr = new System.Threading.Thread(BackupThread);
         Thr.IsBackground = true;
         Thr.Start();
 }
Ejemplo n.º 4
0
        public Lfx.Types.OperationResult Backup(BackupInfo backupInfo)
        {
            string WorkFolder = backupInfo.Name + System.IO.Path.DirectorySeparatorChar;

            Lfx.Environment.Folders.EnsurePathExists(this.BackupPath);

            if (!System.IO.Directory.Exists(Lfx.Environment.Folders.TemporaryFolder + WorkFolder))
            {
                System.IO.Directory.CreateDirectory(Lfx.Environment.Folders.TemporaryFolder + WorkFolder);
            }

            Lfx.Types.OperationProgress Progreso = new Lfx.Types.OperationProgress("Creando copia de seguridad", "Se está creando un volcado completo del almacén de datos en una carpeta, para resguardar.");
            Progreso.Modal     = true;
            Progreso.Advertise = true;
            Progreso.Begin();
            Progreso.Max = Lfx.Workspace.Master.Structure.Tables.Count + 1;

            Progreso.ChangeStatus("Exportando estructura");
            Progreso.ChangeStatus(Progreso.Value + 1);
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.AppendChild(Lfx.Workspace.Master.Structure.ToXml(doc));
            doc.Save(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "dbstruct.xml");

            BackupWriter Writer = new BackupWriter(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "dbdata.lbd");

            Writer.Write(":BKP");

            IList <string> TableList = Lfx.Data.DatabaseCache.DefaultCache.GetTableNames();

            foreach (string Tabla in TableList)
            {
                string NombreTabla = Tabla;
                if (Lfx.Workspace.Master.Structure.Tables.ContainsKey(Tabla))
                {
                    NombreTabla = Lfx.Workspace.Master.Structure.Tables[Tabla].Label;
                }

                Progreso.ChangeStatus("Volcando " + NombreTabla);
                Progreso.ChangeStatus(Progreso.Value + 1);
                ExportTableBin(Tabla, Writer);
            }
            Writer.Close();

            System.IO.FileStream Archivo = new System.IO.FileStream(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "info.txt", System.IO.FileMode.Append, System.IO.FileAccess.Write);
            using (System.IO.StreamWriter Escribidor = new System.IO.StreamWriter(Archivo, System.Text.Encoding.Default)) {
                Escribidor.WriteLine("Copia de seguridad de Lázaro");
                Escribidor.WriteLine("");
                Escribidor.WriteLine("Empresa=" + backupInfo.CompanyName);
                Escribidor.WriteLine("EspacioTrabajo=" + Lfx.Workspace.Master.Name);
                Escribidor.WriteLine("FechaYHora=" + System.DateTime.Now.ToString("dd-MM-yyyy") + " a las " + System.DateTime.Now.ToString("HH:mm:ss"));
                Escribidor.WriteLine("Usuario=" + backupInfo.UserName);
                Escribidor.WriteLine("Estación=" + Lfx.Environment.SystemInformation.MachineName);
                Escribidor.WriteLine("VersiónLazaro=" + backupInfo.ProgramVersion);
                Escribidor.WriteLine("");
                Escribidor.WriteLine("Por favor no modifique ni elimine este archivo.");
                Escribidor.Close();
                Archivo.Close();
            }

            if (Lfx.Workspace.Master.CurrentConfig.ReadGlobalSetting <int>("Sistema.ComprimirCopiasDeSeguridad", 0) != 0)
            {
                Progreso.ChangeStatus("Comprimiendo los datos");
                Lfx.FileFormats.Compression.Archive ArchivoComprimido = new Lfx.FileFormats.Compression.Archive(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "backup.7z");
                ArchivoComprimido.Add(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "*");
                if (System.IO.File.Exists(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "backup.7z"))
                {
                    Progreso.ChangeStatus("Eliminando archivos temporales");
                    // Borrar los archivos que acabo de comprimir
                    System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo(Lfx.Environment.Folders.TemporaryFolder + WorkFolder);
                    foreach (System.IO.FileInfo DirItem in Dir.GetFiles())
                    {
                        if (DirItem.Name != "backup.7z" && DirItem.Name != "info.txt")
                        {
                            System.IO.File.Delete(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + DirItem.Name);
                        }
                    }
                }
            }

            Progreso.ChangeStatus("Almacenando");
            Progreso.ChangeStatus(Progreso.Value + 1);
            Lfx.Environment.Folders.MoveDirectory(Lfx.Environment.Folders.TemporaryFolder + WorkFolder, this.BackupPath + WorkFolder);

            int GuardarBackups = Lfx.Workspace.Master.CurrentConfig.ReadGlobalSetting <int>("Sisteam.Backup.CantMax", 14);

            if (GuardarBackups > 0)
            {
                List <BackupInfo> ListaDeBackups = this.GetBackups();
                if (ListaDeBackups.Count > GuardarBackups)
                {
                    Progreso.ChangeStatus("Eliminando copias de seguridad antiguas");
                    int BorrarBackups = ListaDeBackups.Count - GuardarBackups;
                    if (BorrarBackups < ListaDeBackups.Count)
                    {
                        for (int i = 1; i <= BorrarBackups; i++)
                        {
                            this.Delete(this.GetOldestBackupName());
                        }
                    }
                }
            }

            Progreso.End();

            return(new Lfx.Types.SuccessOperationResult());
        }
Ejemplo n.º 5
0
                public Lfx.Types.OperationResult Backup(BackupInfo backupInfo)
                {
                        string WorkFolder = backupInfo.Name + System.IO.Path.DirectorySeparatorChar;

                        Lfx.Environment.Folders.EnsurePathExists(this.BackupPath);

                        if (!System.IO.Directory.Exists(Lfx.Environment.Folders.TemporaryFolder + WorkFolder))
                                System.IO.Directory.CreateDirectory(Lfx.Environment.Folders.TemporaryFolder + WorkFolder);

                        Lfx.Types.OperationProgress Progreso = new Lfx.Types.OperationProgress("Creando copia de seguridad", "Se está creando un volcado completo del almacén de datos en una carpeta, para resguardar.");
                        Progreso.Modal = true;
                        Progreso.Advertise = true;
                        Progreso.Begin();
                        Progreso.Max = Lfx.Workspace.Master.Structure.Tables.Count + 1;

                        Progreso.ChangeStatus("Exportando estructura");
                        Progreso.ChangeStatus(Progreso.Value + 1);
                        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                        doc.AppendChild(Lfx.Workspace.Master.Structure.ToXml(doc));
                        doc.Save(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "dbstruct.xml");

                        BackupWriter Writer = new BackupWriter(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "dbdata.lbd");
                        Writer.Write(":BKP");

                        IList<string> TableList = Lfx.Data.DataBaseCache.DefaultCache.GetTableNames();
                        foreach (string Tabla in TableList) {
                                string NombreTabla = Tabla;
                                if (Lfx.Workspace.Master.Structure.Tables.ContainsKey(Tabla))
                                        NombreTabla = Lfx.Workspace.Master.Structure.Tables[Tabla].Label;

                                Progreso.ChangeStatus("Volcando " + NombreTabla);
                                Progreso.ChangeStatus(Progreso.Value + 1);
                                ExportTableBin(Tabla, Writer);

                        }
                        Writer.Close();

                        System.IO.FileStream Archivo = new System.IO.FileStream(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "info.txt", System.IO.FileMode.Append, System.IO.FileAccess.Write);
                        using (System.IO.StreamWriter Escribidor = new System.IO.StreamWriter(Archivo, System.Text.Encoding.Default)) {
                                Escribidor.WriteLine("Copia de seguridad de Lázaro");
                                Escribidor.WriteLine("");
                                Escribidor.WriteLine("Empresa=" + backupInfo.CompanyName);
                                Escribidor.WriteLine("EspacioTrabajo=" + Lfx.Workspace.Master.Name);
                                Escribidor.WriteLine("FechaYHora=" + System.DateTime.Now.ToString("dd-MM-yyyy") + " a las " + System.DateTime.Now.ToString("HH:mm:ss"));
                                Escribidor.WriteLine("Usuario=" + backupInfo.UserName);
                                Escribidor.WriteLine("Estación=" + Lfx.Environment.SystemInformation.MachineName);
                                Escribidor.WriteLine("VersiónLazaro=" + backupInfo.ProgramVersion);
                                Escribidor.WriteLine("");
                                Escribidor.WriteLine("Por favor no modifique ni elimine este archivo.");
                                Escribidor.Close();
                                Archivo.Close();
                        }

                        if (Lfx.Workspace.Master.CurrentConfig.ReadGlobalSetting<int>("Sistema.ComprimirCopiasDeSeguridad", 0) != 0) {
                                Progreso.ChangeStatus("Comprimiendo los datos");
                                Lfx.FileFormats.Compression.Archive ArchivoComprimido = new Lfx.FileFormats.Compression.Archive(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "backup.7z");
                                ArchivoComprimido.Add(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "*");
                                if (System.IO.File.Exists(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "backup.7z")) {
                                        Progreso.ChangeStatus("Eliminando archivos temporales");
                                        // Borrar los archivos que acabo de comprimir
                                        System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo(Lfx.Environment.Folders.TemporaryFolder + WorkFolder);
                                        foreach (System.IO.FileInfo DirItem in Dir.GetFiles()) {
                                                if (DirItem.Name != "backup.7z" && DirItem.Name != "info.txt") {
                                                        System.IO.File.Delete(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + DirItem.Name);
                                                }
                                        }
                                }
                        }

                        Progreso.ChangeStatus("Almacenando");
                        Progreso.ChangeStatus(Progreso.Value + 1);
                        Lfx.Environment.Folders.MoveDirectory(Lfx.Environment.Folders.TemporaryFolder + WorkFolder, this.BackupPath + WorkFolder);

                        int GuardarBackups = Lfx.Workspace.Master.CurrentConfig.ReadGlobalSetting<int>("Sisteam.Backup.CantMax", 14);
                        if (GuardarBackups > 0) {
                                List<BackupInfo> ListaDeBackups = this.GetBackups();
                                if (ListaDeBackups.Count > GuardarBackups) {
                                        Progreso.ChangeStatus("Eliminando copias de seguridad antiguas");
                                        int BorrarBackups = ListaDeBackups.Count - GuardarBackups;
                                        if (BorrarBackups < ListaDeBackups.Count) {
                                                for (int i = 1; i <= BorrarBackups; i++) {
                                                        this.Delete(this.GetOldestBackupName());
                                                }
                                        }
                                }
                        }

                        Progreso.End();

                        return new Lfx.Types.SuccessOperationResult();
                }
Ejemplo n.º 6
0
                public List<BackupInfo> GetBackups()
                {
                        Lfx.Environment.Folders.EnsurePathExists(BackupPath);

                        List<BackupInfo> Res = new List<BackupInfo>();
                        System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo(this.BackupPath);
                        foreach (System.IO.DirectoryInfo DirItem in Dir.GetDirectories("*.*")) {
                                BackupInfo Backup = new BackupInfo();

                                if (System.IO.File.Exists(this.BackupPath + DirItem.Name + System.IO.Path.DirectorySeparatorChar + "info.xml")) {
                                        // Nuevo formato de archivo de información

                                } else if (System.IO.File.Exists(this.BackupPath + DirItem.Name + System.IO.Path.DirectorySeparatorChar + "info.txt")) {
                                        // Antiguo formato de información
                                        string ArchivoIni = Lfx.Types.Strings.ReadTextFile(this.BackupPath + DirItem.Name + System.IO.Path.DirectorySeparatorChar + "info.txt");
                                        Backup.Name = DirItem.Name;
                                        Backup.UserName = Lfx.Types.Ini.ReadString(ArchivoIni, "", "Usuario");
                                        Backup.CompanyName = Lfx.Types.Ini.ReadString(ArchivoIni, "", "Empresa");
                                        Backup.ProgramVersion = Lfx.Types.Ini.ReadString(ArchivoIni, "", "VersiónLazaro");
                                        Backup.BackupDate = DateTime.ParseExact(Lfx.Types.Ini.ReadString(ArchivoIni, "", "FechaYHora"), @"dd\-MM\-yyyy ""a las"" HH\:mm\:ss", System.Globalization.CultureInfo.InvariantCulture);
                                }

                                Res.Add(Backup);
                        }

                        Res.Sort(delegate(BackupInfo b1, BackupInfo b2) { return b1.BackupDate.CompareTo(b2.BackupDate); });
                        Res.Reverse();

                        return Res;
                }