public void UpdateBackupFileRef(BackupRunFileRef item)
        {
            this.Logger.LogInformation("Updating BackupRunFileRef set with BackupRunFileRefID: {0}", item.BackupRunFileRefID);

            this.dbContext.Update <BackupRunFileRef>(item);
            this.dbContext.SaveChangesAsync();
        }
        public void CompleteFileArchive(BackupRunFileRef backupRef, BackupRun br)
        {
            var cacheFileName = GetCacheEntryForFile(backupRef.FullFileName, br);

            if (File.Exists(cacheFileName))
            {
                Logger.LogDebug("Deleting cache file after archive: {0}", cacheFileName);

                File.Delete(cacheFileName);
            }
        }
        public Stream GetCacheStreamForItem(BackupRunFileRef item, BackupRun br)
        {
            var cacheFile = new FileInfo(GetCacheEntryForFile(item.FullFileName, br));

            if (File.Exists(cacheFile.FullName) == false)
            {
                cacheFile.Create();
            }

            return(cacheFile.OpenRead());
        }
Exemple #4
0
        public bool ArchiveFile(BackupRun backupRun, BackupRunFileRef fileRef, Stream cacheFileStream)
        {
            if (false == isInitialized)
            {
                this.Initialize();
            }

            Logger.LogDebug("Called FileSystemBackup.ArchiveFile");

            //TODO Move direcory check
            //Don't copy directories
            //if (Directory.Exists(cacheFile.FullName))
            //{
            //    Logger.LogInformation(String.Format("Skipping archive for directory reference: {0}", fileRef.FullFileName));

            //    return true;
            //}

            FileInfo archiveFile = new FileInfo(String.Format("{0}{1}{2}{3}{4}",
                                                              this.baseBackupDir,
                                                              Path.DirectorySeparatorChar,
                                                              backupRun.BackupRunID,
                                                              Path.DirectorySeparatorChar,
                                                              fileRef.FullFileName.Substring(3)));

            if (archiveFile.Exists)
            {
                Logger.LogInformation(String.Format("Deleting existing archive entry for file: {0}", fileRef.FullFileName));

                archiveFile.Delete();
            }

            if (archiveFile.Directory.Exists == false)
            {
                Logger.LogInformation(String.Format("Creating parent directory for archive entry: {0}", archiveFile.Directory.FullName));

                archiveFile.Directory.Create();
            }

            byte[] buffer = new byte[1024];
            int    offset = 0;
            int    count;

            while ((count = cacheFileStream.Read(buffer, offset, buffer.Length)) > 0)
            {
                offset += count;
            }

            Logger.LogInformation(String.Format("Completed archive copy for entry: {0} with result: {1}", fileRef.FullFileName, archiveFile.Exists));

            return(true);
        }