Example #1
0
        public virtual void Operations()
        {
            if (this.backup.Ftp)
            {
                this.communicator.GetFtpSettings();
                Thread.Sleep(20000);

                if (!BackupOperations.Ftp(this.DestinationPaths[0]))
                {
                    this.reportMaker.AddError(new ErrorDetails()
                    {
                        Problem = "Could not upload files to FTP. Check the connection settings.",
                    });
                }
            }
            if (this.backup.Ssh)
            {
                this.communicator.GetSshSettings();
                Thread.Sleep(20000);

                if (!BackupOperations.Ssh(this.DestinationPaths[0]))
                {
                    this.reportMaker.AddError(new ErrorDetails()
                    {
                        Problem = "Could not upload files to SSH. Check the connection settings.",
                    });
                }
            }
        }
Example #2
0
        public static bool ZipFiles(List <string> destinationPaths)
        {
            try
            {
                foreach (string destinationPath in destinationPaths)
                {
                    FileStream      fsOut     = File.Create(destinationPath);
                    ZipOutputStream zipStream = new ZipOutputStream(fsOut);
                    zipStream.SetLevel(3);
                    zipStream.Password = null;

                    int folderOffset = destinationPath.Length + (destinationPath.EndsWith("\\") ? 0 : 1);
                    BackupOperations.CompressFolder(destinationPath, zipStream, folderOffset);


                    zipStream.IsStreamOwner = true;
                    zipStream.Close();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #3
0
        public virtual void Operations()
        {
            if (this.backup.Batches)
            {
                this.communicator.GetBatchSettings();
                Thread.Sleep(20000);

                BackupOperations.Batches(this.reportMaker, "AFTER");
            }

            if (this.backup.Ftp)
            {
                this.communicator.GetFtpSettings();
                Thread.Sleep(20000);

                if (!BackupOperations.Ftp(this.DestinationPaths, this.backup))
                {
                    this.reportMaker.AddError(new ErrorDetails()
                    {
                        Problem = "Could not upload files to FTP. Check the connection settings.",
                    });
                }
            }

            if (this.backup.Ssh)
            {
                this.communicator.GetSshSettings();
                Thread.Sleep(20000);

                if (!BackupOperations.Ssh(this.DestinationPaths[0]))
                {
                    this.reportMaker.AddError(new ErrorDetails()
                    {
                        Problem = "Could not upload files to SSH. Check the connection settings.",
                    });
                }
            }


            if (this.backup.DatabaseBackup)
            {
                this.dump.FullBackup();
            }

            if (this.backup.Rar)
            {
                if (!BackupOperations.ZipFiles(this.DestinationPaths, this.backup))
                {
                    this.reportMaker.AddError(new ErrorDetails()
                    {
                        Problem = "Could not ZIP the files."
                    });
                }
            }
        }
Example #4
0
        public virtual void Start()
        {
            if (this.backup.Batches)
            {
                this.communicator.GetBatchSettings();
                Thread.Sleep(20000);

                BackupOperations.Batches(this.reportMaker, "BEFORE");
            }

            foreach (string item in this.SourcePaths)
            {
                if (this.backup.BackupType == "FULL")
                {
                    this.CreateLog(item);
                }
                this.Backup(item, new List <string>(this.DestinationPaths));
                this.backupCountFolders++;
            }
            this.backupCount++;
        }
Example #5
0
        protected override void Backup(string sourcePath, List <string> destinationPaths)
        {
            //Prespsani destination path
            for (int i = 0; i < destinationPaths.Count; i++)
            {
                destinationPaths[i] += $"\\{sourcePath.Substring(Functionality.IdentifyCharPosition('\\', sourcePath))}";
            }

            //Vytvoří podsložky
            foreach (string destinationPath in destinationPaths)
            {
                int index = 0;
                if (Directory.Exists(destinationPath) && backup.Override)
                {
                    try
                    {
                        Directory.Delete(destinationPath, true);
                    }
                    catch (Exception ex)
                    {
                        this.reportMaker.AddError(new ErrorDetails()
                        {
                            Exception = ex.Message,
                            Problem   = "Could not delete the old folder. Override failed",
                            Path      = destinationPath
                        });
                    }
                }

                foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories))
                {
                    try
                    {
                        Directory.CreateDirectory(dirPath.Replace(sourcePath, destinationPath));
                    }
                    catch (Exception ex)
                    {
                        this.reportMaker.AddError(new ErrorDetails()
                        {
                            Exception = ex.Message,
                            Problem   = "The program was unable to create folder.",
                            Path      = dirPath
                        });
                    }
                    index++;
                }

                if (index == 0)
                {
                    try
                    {
                        Directory.CreateDirectory(destinationPath);
                    }
                    catch (Exception ex)
                    {
                        this.reportMaker.AddError(new ErrorDetails()
                        {
                            Exception = ex.Message,
                            Problem   = "The program was unable to destination create folder.",
                            Path      = destinationPath
                        });
                    }
                }
            }

            //Zkopíruje všechny soubory a přepíše existující, zanese o nich zaznamy do logu
            foreach (string destinationPath in destinationPaths)
            {
                foreach (string newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories).OrderBy(f => new FileInfo(f).FullName))
                {
                    try
                    {
                        File.Copy(newPath, newPath.Replace(sourcePath, destinationPath), true);
                        FileInfo fileInfo = new FileInfo(newPath);
                        //*newLog.Add(new LogModel() { Action = "EXI", FileName = fileInfo.Name, FilePath = fileInfo.FullName, LastWriteTime = Convert.ToDateTime(fileInfo.LastWriteTime) });
                        reportMaker.AddFile(new FileInfo(newPath));
                    }
                    catch (Exception ex)
                    {
                        this.reportMaker.AddError(new ErrorDetails()
                        {
                            Problem       = "The file was not copied",
                            Path          = newPath,
                            Exception     = ex.Message,
                            AffectedFiles = 1
                        });
                    }
                }
            }

            if (this.backup.Rar)
            {
                if (!BackupOperations.ZipFiles(destinationPaths))
                {
                    this.reportMaker.AddError(new ErrorDetails()
                    {
                        Problem = "Could not ZIP the files."
                    });
                }
            }
        }