public void Can_Create_FileSystem_Backup() { IFsBackupCreator creator = new FsBackupCreator(DateTime.Now); var file = creator.CreateBackup(@"E:\projects\De Cristal", @"E:\projects\De Cristal"); Assert.IsTrue(File.Exists(file)); }
public void Run() { var backupPath = string.Format(@"{0}\{1}\", _settings.TempDirectory, _backupTime.ToAppDateToString()); var fsDataPath = string.Format(@"{0}\{1}\fs", _settings.TempDirectory, _backupTime.ToAppDateToString()); var sqlDataPath = string.Format(@"{0}\{1}\sql", _settings.TempDirectory, _backupTime.ToAppDateToString()); if (!Directory.Exists(fsDataPath)) Directory.CreateDirectory(fsDataPath); if (!Directory.Exists(sqlDataPath)) Directory.CreateDirectory(sqlDataPath); var fsBackupFiles = new List<string>(); var sqlBackupFiles = new List<string>(); //create zip files for directories first var fsCreator = new FsBackupCreator(_backupTime); foreach (var directory in _settings.Directories) { fsBackupFiles.Add(fsCreator.CreateBackup(directory, fsDataPath)); } //create database backups foreach (var database in _settings.Databases) { var creator = new MsSqlBackupCreator(_backupTime) { DatabaseName = database, Credentials = new NetworkCredential(_settings.DatabaseUsername, _settings.DatabasePassword), HostName = _settings.DatabaseServer, FilePath = sqlDataPath }; sqlBackupFiles.Add(creator.CreateBackup()); } //start ftp transaction var ftpManager = new FtpManager { Credential = _settings.FtpCredentials, Hostname = _settings.FtpHostname }; var ftpFsRootPath = string.Format(@"{0}\{1}\{2}", _settings.FtpRoot, _backupTime.ToAppDateToString(), "FS"); var ftpSqlRootPath = string.Format(@"{0}\{1}\{2}", _settings.FtpRoot, _backupTime.ToAppDateToString(), "SQL"); ftpManager.TransferFile(fsBackupFiles, ftpFsRootPath); ftpManager.TransferFile(sqlBackupFiles, ftpSqlRootPath); Directory.Delete(backupPath, true); //delete the temp directory once database backup is done }