コード例 #1
0
        public bool ProcessStorageReadyBackupEntry(BackupHistoryEntry backupEntryToStorage)
        {
            try
              {
            if (!backupEntryToStorage.StoragePendingFilesPaths.Any())
            {
              _log.Debug("No files to store.");

              return true;
            }

            var relativeFtpBackupDirectory =
              _settingsProvider.GetSetting<string>("RelativeFtpBackupDirectory").TrimEnd('/', '\\');

            using (var ftpClient = new FtpClient())
            {
              ftpClient.DataConnectionType = _dataConnectionType;

              ftpClient.Host = _settingsProvider.GetSetting<string>("FtpHost");
              ftpClient.Port = _settingsProvider.GetSetting<int>("FtpPort");

              ftpClient.Credentials =
            new NetworkCredential(
              _settingsProvider.GetSetting<string>("FtpUsername"),
              _settingsProvider.GetSetting<string>("FtpPassword"));

              _log.Info("Connecting to FTP server (" + ftpClient.Host + ":" + ftpClient.Port + ")...");

              ftpClient.Connect();

              var ftpBackupPath =
            string.Format(
              "{0}/{1} {2} Backup",
              relativeFtpBackupDirectory,
              backupEntryToStorage.CompressStarted.ToString("yyyyMMdd_HHmmss"),
              backupEntryToStorage.BackupType);

              ftpClient.CreateDirectory(ftpBackupPath);

              //  Upload compressed backups to FTP server
              foreach (var storagePendingFilePath in backupEntryToStorage.StoragePendingFilesPaths)
              {
            UploadBackupFile(ftpClient, ftpBackupPath, storagePendingFilePath);
              }

              //  Removed already uploaded backup files
              foreach (var storagePendingFilePath in backupEntryToStorage.StoragePendingFilesPaths)
              {
            File.Delete(storagePendingFilePath);
              }

              _log.Info("Finished uploading files to the FTP server.");
            }

            return true;
              }
              catch (Exception e)
              {
            _log.Error("Failed to upload files to FTP server.", e);

            return false;
              }
        }
コード例 #2
0
        public void UpdateBackupHistoryEntry(BackupHistoryEntry backupEntryToStorage)
        {
            lock (_backupHistoryFileLock)
              {
            var document = _backupHistoryDocument.Value;

            if (document.Root == null)
              throw new Exception("Root element is missing.");

            var oldBackupEntry =
              document.Root
            .Elements("Backup")
            .FirstOrDefault(x => long.Parse(x.NotNullAttribute("id").Value) == backupEntryToStorage.Id);

            if (oldBackupEntry == null)
              throw new Exception("Could not find backup history entry to update (" + backupEntryToStorage.Id + ").");

            oldBackupEntry.ReplaceWith(backupEntryToStorage.ToXElement());

            document.Save(_backupHistoryFilePath);

            InitializeBackupHistoryCache();
              }
        }