Exemplo n.º 1
0
 public SyncVolume(string name, VolumeSource source, BaseArchive archive)
 {
     mName     = name;
     mSource   = source;
     mDatabase = new VolumeSnapshotDatabase(archive.GetSnapshotXmlDir());
     mArchive  = archive;
 }
        public void Restore( VolumeSnapshot snapshot, BaseArchive archive, string onDiskPath )
        {
            mOperation.Reset();

            mFileTotalCount = 0;
            mFilesTotalSize = 0;
            mFileRunningCount = 0;
            mFilesTotalSizeRunning = 0;

            try
            {
                mBusy = true;

                VolumeSnapshotDirectory vsd = snapshot.Root;
                mFileTotalCount = vsd.CountAllFiles( ref mFilesTotalSize );

                if ( !mOperation.CanContinue )
                    return;

                int relativePathStartIndex = vsd.RelativePath.LastIndexOf( PWLib.Platform.Windows.Path.DirectorySeparatorChar );
                if ( relativePathStartIndex < 0 )
                    relativePathStartIndex = 0;
                ProcessDirectoryRestore( vsd, archive, relativePathStartIndex, onDiskPath );
            }
            finally
            {
                mBusy = false;
            }
        }
        public bool DoIncrementalBackup(VolumeSnapshot currentSnapshot, VolumeSnapshot mostRecentSnapshot, VolumeSource source, BaseArchive archive, out bool noChangesRequired)
        {
            noChangesRequired = false;
            mSource           = source;
            mArchive          = archive;

            // see if anything's changed from the last one
            currentSnapshot.Root.Revision = mostRecentSnapshot.Root.Revision;
            if (mComparator.CompareSnapshots(mostRecentSnapshot, currentSnapshot, true))
            {
                FileSync.__Log(this, "Incremental comparison complete, changes detected");
                FileSync.__Log(this, "Total file count " + mComparator.Stats.FileCount);
                FileSync.__Log(this, "Total file size " + mComparator.Stats.TotalFileSize);
                FileSync.__Log(this, "New files " + mComparator.Stats.FilesCreated);
                FileSync.__Log(this, "Removed files " + mComparator.Stats.FilesRemoved);
                FileSync.__Log(this, "Changed files " + mComparator.Stats.FilesChanged);
                FileSync.__Log(this, "New directories " + mComparator.Stats.DirectoriesCreated);
                FileSync.__Log(this, "Removed directories " + mComparator.Stats.DirectoriesRemoved);
                FileSync.__Log(this, "Files unchanged " + mComparator.Stats.FilesTheSame);
                FileSync.__Log(this, "Directories unchanged " + mComparator.Stats.DirectoriesTheSame);

                mFileTotalCount        = mComparator.Stats.FileCount;
                mFilesTotalSize        = mComparator.Stats.TotalFileSize;
                mFileRunningCount      = 0;
                mFilesTotalSizeRunning = 0;
                mComparator.CompareSnapshots(mostRecentSnapshot, currentSnapshot, false);
                return(!mOperation.Cancelled);
            }
            else
            {
                FileSync.__Log(this, "Incremental comparison complete, no changes detected");
                noChangesRequired = true;
                return(true);
            }
        }
Exemplo n.º 4
0
 public SyncVolume( string name, VolumeSource source, BaseArchive archive )
 {
     mName = name;
     mSource = source;
     mDatabase = new VolumeSnapshotDatabase( archive.GetSnapshotXmlDir() );
     mArchive = archive;
 }
Exemplo n.º 5
0
 public SyncVolume( XmlNode parentNode )
 {
     mName = PWLib.XmlHelp.GetAttribute( parentNode, "name", "" );
     mSource = VolumeSource.BuildFromXml( parentNode );
     mArchive = BaseArchive.BuildFromXml( parentNode );
     mDatabase = VolumeSnapshotDatabase.LoadFromXml( parentNode );
 }
        public void Restore(VolumeSnapshot snapshot, BaseArchive archive, string onDiskPath)
        {
            mOperation.Reset();

            mFileTotalCount        = 0;
            mFilesTotalSize        = 0;
            mFileRunningCount      = 0;
            mFilesTotalSizeRunning = 0;

            try
            {
                mBusy = true;

                VolumeSnapshotDirectory vsd = snapshot.Root;
                mFileTotalCount = vsd.CountAllFiles(ref mFilesTotalSize);

                if (!mOperation.CanContinue)
                {
                    return;
                }

                int relativePathStartIndex = vsd.RelativePath.LastIndexOf(PWLib.Platform.Windows.Path.DirectorySeparatorChar);
                if (relativePathStartIndex < 0)
                {
                    relativePathStartIndex = 0;
                }
                ProcessDirectoryRestore(vsd, archive, relativePathStartIndex, onDiskPath);
            }
            finally
            {
                mBusy = false;
            }
        }
Exemplo n.º 7
0
 public Volume( VolumeEventController eventController, VolumeDescriptor volumeDesc, VolumeSource source, BaseArchive archive )
 {
     mEventController = eventController;
     mVolumeDesc = volumeDesc;
     mBackupRestoreObject = new BackupRestoreVolume( mVolumeDesc.VolumeName, source, archive );
     Init();
 }
Exemplo n.º 8
0
 public SyncVolume(XmlNode parentNode)
 {
     mName     = PWLib.XmlHelp.GetAttribute(parentNode, "name", "");
     mSource   = VolumeSource.BuildFromXml(parentNode);
     mArchive  = BaseArchive.BuildFromXml(parentNode);
     mDatabase = VolumeSnapshotDatabase.LoadFromXml(parentNode);
 }
Exemplo n.º 9
0
 public BackupRestoreVolume(string name, VolumeSource source, BaseArchive archive)
 {
     mName     = name;
     mSource   = source;
     mArchive  = archive;
     mDatabase = new VolumeSnapshotDatabase(archive.GetSnapshotXmlDir());
     Init();
 }
Exemplo n.º 10
0
 public void Dispose()
 {
     if (mArchive != null)
     {
         mArchive.Dispose();
     }
     mArchive = null;
 }
 public VolumeDescriptor AddNewDescriptor( string volName, string volFilename, VolumeSource source, BaseArchive archive )
 {
     VolumeDescriptor vd = new VolumeDescriptor( mEventController, volName, volFilename, source, archive );
     lock ( mDescriptorList )
     {
         mDescriptorList.Add( vd );
     }
     Config.Active.Save();
     return vd;
 }
Exemplo n.º 12
0
        public VolumeDescriptor( VolumeEventController eventController, string volName, string volFilename, VolumeSource source, BaseArchive archive )
        {
            mEventController = eventController;
            mName = volName;
            mVolumeFilename = volFilename;

            mVolume = new Volume( mEventController, this, source, archive );
            ConnectToVolumeEvents( mVolume );
            mIsAvailable = true;
            SaveVolumeData();
        }
 public bool DoFullBackup( VolumeSnapshot currentSnapshot, VolumeSource source, BaseArchive archive )
 {
     mOperation.Reset();
     mFileTotalCount = currentSnapshot.FileCount;
     mFileRunningCount = 0;
     mFilesTotalSize = currentSnapshot.TotalFileSize;
     mFilesTotalSizeRunning = 0;
     mArchive = archive;
     mSource = source;
     return CopyAll( currentSnapshot.Root );
 }
 public bool DoFullBackup(VolumeSnapshot currentSnapshot, VolumeSource source, BaseArchive archive)
 {
     mOperation.Reset();
     mFileTotalCount        = currentSnapshot.FileCount;
     mFileRunningCount      = 0;
     mFilesTotalSize        = currentSnapshot.TotalFileSize;
     mFilesTotalSizeRunning = 0;
     mArchive = archive;
     mSource  = source;
     return(CopyAll(currentSnapshot.Root));
 }
        void MergeSnapshotRevisions(VolumeSnapshotDatabase database, VolumeSource source, BaseArchive archive, int numRevisionsToRemove)
        {
            try
            {
                mDatabase = database;
                mArchive  = archive;
                mBusy     = true;

                List <VolumeSnapshotRevision> revisionHistory = database.GetRevisionHistory();
                if (numRevisionsToRemove == revisionHistory.Count)
                {
                    // Need to remove all old revisions, delete everything
                    FileSync.__Log(this, "Merge deleting all revisions");
                    database.DeleteAllRevisions();
                }
                else
                {
                    // now we know how many revisions to remove, need to rebuild the new first revision.
                    VolumeSnapshotRevision currentRevision = revisionHistory[numRevisionsToRemove];
                    VolumeSnapshot         currentSnapshot = database.LoadSnapshotRevision(source, currentRevision);

                    FileSync.__Log(this, "Merge is turning revision [" + currentRevision.ToString() + "] into baseline");
                    TurnSnapshotIntoBaseline(currentSnapshot);

                    // Now go through all existing snapshot .xml files and change any files referencing
                    // a snapshot that has been removed and change it to the current snapshot revision.
                    for (int revisionNum = numRevisionsToRemove + 1; revisionNum < revisionHistory.Count; ++revisionNum)
                    {
                        VolumeSnapshotRevision incrementalRevision = revisionHistory[revisionNum];
                        VolumeSnapshot         incrementalSnapshot = database.LoadSnapshotRevision(source, incrementalRevision);

                        FileSync.__Log(this, "Merge is reflecting revision [" + incrementalRevision.ToString() + "] into new baseline [" + currentRevision.ToString() + "]");
                        UpdateSnapshotToReflectBaselineRevision(incrementalSnapshot, currentRevision);
                    }

                    // delete old revision data
                    for (int revisionNum = 0; revisionNum < numRevisionsToRemove; ++revisionNum)
                    {
                        VolumeSnapshotRevision revisionToDelete = revisionHistory[revisionNum];
                        FileSync.__Log(this, "Merge is deleting revision [" + revisionToDelete.ToString() + "]");
                        database.DeleteSnapshotRevision(revisionToDelete);
                    }
                }
            }
            catch (System.Exception ex)
            {
                FileSync.__LogError(this, "Volume.CheckForExpiredSnapshotRevisions", ex);
            }
            finally
            {
                mBusy = false;
            }
        }
        void MergeSnapshotRevisions( VolumeSnapshotDatabase database, VolumeSource source, BaseArchive archive, int numRevisionsToRemove )
        {
            try
            {
                mDatabase = database;
                mArchive = archive;
                mBusy = true;

                List<VolumeSnapshotRevision> revisionHistory = database.GetRevisionHistory();
                if ( numRevisionsToRemove == revisionHistory.Count )
                {
                    // Need to remove all old revisions, delete everything
                    FileSync.__Log( this, "Merge deleting all revisions" );
                    database.DeleteAllRevisions();
                }
                else
                {
                    // now we know how many revisions to remove, need to rebuild the new first revision.
                    VolumeSnapshotRevision currentRevision = revisionHistory[ numRevisionsToRemove ];
                    VolumeSnapshot currentSnapshot = database.LoadSnapshotRevision( source, currentRevision );

                    FileSync.__Log( this, "Merge is turning revision [" + currentRevision.ToString() + "] into baseline" );
                    TurnSnapshotIntoBaseline( currentSnapshot );

                    // Now go through all existing snapshot .xml files and change any files referencing
                    // a snapshot that has been removed and change it to the current snapshot revision.
                    for ( int revisionNum = numRevisionsToRemove + 1; revisionNum < revisionHistory.Count; ++revisionNum )
                    {
                        VolumeSnapshotRevision incrementalRevision = revisionHistory[ revisionNum ];
                        VolumeSnapshot incrementalSnapshot = database.LoadSnapshotRevision( source, incrementalRevision );

                        FileSync.__Log( this, "Merge is reflecting revision [" + incrementalRevision.ToString() + "] into new baseline [" + currentRevision.ToString()  + "]" );
                        UpdateSnapshotToReflectBaselineRevision( incrementalSnapshot, currentRevision );
                    }

                    // delete old revision data
                    for ( int revisionNum = 0; revisionNum < numRevisionsToRemove; ++revisionNum )
                    {
                        VolumeSnapshotRevision revisionToDelete = revisionHistory[ revisionNum ];
                        FileSync.__Log( this, "Merge is deleting revision [" + revisionToDelete.ToString() + "]" );
                        database.DeleteSnapshotRevision( revisionToDelete );
                    }
                }
            }
            catch ( System.Exception ex )
            {
                FileSync.__LogError( this, "Volume.CheckForExpiredSnapshotRevisions", ex );
            }
            finally
            {
                mBusy = false;
            }
        }
        private void ProcessDirectoryRestore(VolumeSnapshotDirectory sourceDir, BaseArchive archive, int relativePathStartIndex, string targetDir)
        {
            if (!mOperation.CanContinue)
            {
                return;
            }

            PWLib.Platform.Windows.Directory.CreateDirectory(targetDir);

            foreach (VolumeSnapshotFile fileEntry in sourceDir.Files)
            {
                try
                {
                    string outDir = targetDir + fileEntry.RelativePath.Substring(relativePathStartIndex);
                    archive.RestoreFile(fileEntry.Revision, fileEntry.RelativePath, outDir, new ArchiveFileDelegate(Restore_ArchiveStoreFile), fileEntry);

                    ulong runningSize = mFilesTotalSizeRunning + fileEntry.FileSize;
                    if (runningSize > mFilesTotalSize)
                    {
                        runningSize = mFilesTotalSize;
                    }
                    if (Progress != null)
                    {
                        Progress(mFileRunningCount + 1, mFileTotalCount, runningSize, mFilesTotalSize);
                    }
                }
                catch (System.Exception e)
                {
                    if (Error != null)
                    {
                        Error("Restore file failed '" + fileEntry.RelativePath + "'", e);
                    }
                }

                if (!mOperation.CanContinue)
                {
                    return;
                }

                mFileRunningCount++;
                mFilesTotalSizeRunning += fileEntry.FileSize;
            }

            foreach (VolumeSnapshotDirectory directoryEntry in sourceDir.Directories)
            {
                ProcessDirectoryRestore(directoryEntry, archive, relativePathStartIndex, targetDir);
                if (!mOperation.CanContinue)
                {
                    return;
                }
            }
        }
 public void MergeSnapshotRevisionsByLimitedRevisionCount( VolumeSnapshotDatabase database, VolumeSource source, BaseArchive archive, int maxRevisions )
 {
     // only keep a specific number of revisions
     List<VolumeSnapshotRevision> revisionHistory = database.GetRevisionHistory();
     int numRevisionsToRemove = 0;
     if ( revisionHistory.Count > maxRevisions )
     {
         numRevisionsToRemove = revisionHistory.Count - maxRevisions;
     }
     if ( numRevisionsToRemove > 0 )
     {
         FileSync.__Log( this, "Merge will remove " + numRevisionsToRemove + " revisions" );
         MergeSnapshotRevisions( database, source, archive, numRevisionsToRemove );
     }
     else
         FileSync.__Log( this, "Merge will not remove any revisions" );
 }
 public void MergeSnapshotRevisionsByTimeLimit( VolumeSnapshotDatabase database, VolumeSource source, BaseArchive archive, TimeSpan timePeriodToKeep )
 {
     // only keep revisions within a certain time period (e.g. last 6 months)
     List<VolumeSnapshotRevision> revisionHistory = database.GetRevisionHistory();
     int numRevisionsToRemove = 0;
     DateTime cutOffDate = DateTime.Now - timePeriodToKeep;
     foreach ( VolumeSnapshotRevision revision in revisionHistory )
     {
         if ( revision.CreationTime >= cutOffDate )
         {
             break;
         }
         else
             numRevisionsToRemove++;
     }
     if ( numRevisionsToRemove > 0 )
     {
         FileSync.__Log( this, "Merge will remove " + numRevisionsToRemove + " revisions" );
         MergeSnapshotRevisions( database, source, archive, numRevisionsToRemove );
     }
     else
         FileSync.__Log( this, "Merge will not remove any revisions" );
 }
        public bool DoIncrementalBackup( VolumeSnapshot currentSnapshot, VolumeSnapshot mostRecentSnapshot, VolumeSource source, BaseArchive archive, out bool noChangesRequired )
        {
            noChangesRequired = false;
            mSource = source;
            mArchive = archive;

            // see if anything's changed from the last one
            currentSnapshot.Root.Revision = mostRecentSnapshot.Root.Revision;
            if ( mComparator.CompareSnapshots( mostRecentSnapshot, currentSnapshot, true ) )
            {
                FileSync.__Log( this, "Incremental comparison complete, changes detected" );
                FileSync.__Log( this, "Total file count " + mComparator.Stats.FileCount );
                FileSync.__Log( this, "Total file size " + mComparator.Stats.TotalFileSize );
                FileSync.__Log( this, "New files " + mComparator.Stats.FilesCreated );
                FileSync.__Log( this, "Removed files " + mComparator.Stats.FilesRemoved );
                FileSync.__Log( this, "Changed files " + mComparator.Stats.FilesChanged );
                FileSync.__Log( this, "New directories " + mComparator.Stats.DirectoriesCreated );
                FileSync.__Log( this, "Removed directories " + mComparator.Stats.DirectoriesRemoved );
                FileSync.__Log( this, "Files unchanged " + mComparator.Stats.FilesTheSame );
                FileSync.__Log( this, "Directories unchanged " + mComparator.Stats.DirectoriesTheSame );

                mFileTotalCount = mComparator.Stats.FileCount;
                mFilesTotalSize = mComparator.Stats.TotalFileSize;
                mFileRunningCount = 0;
                mFilesTotalSizeRunning = 0;
                mComparator.CompareSnapshots( mostRecentSnapshot, currentSnapshot, false );
                return !mOperation.Cancelled;
            }
            else
            {
                FileSync.__Log( this, "Incremental comparison complete, no changes detected" );
                noChangesRequired = true;
                return true;
            }
        }
        public void MergeSnapshotRevisionsByLimitedRevisionCount(VolumeSnapshotDatabase database, VolumeSource source, BaseArchive archive, int maxRevisions)
        {
            // only keep a specific number of revisions
            List <VolumeSnapshotRevision> revisionHistory = database.GetRevisionHistory();
            int numRevisionsToRemove = 0;

            if (revisionHistory.Count > maxRevisions)
            {
                numRevisionsToRemove = revisionHistory.Count - maxRevisions;
            }
            if (numRevisionsToRemove > 0)
            {
                FileSync.__Log(this, "Merge will remove " + numRevisionsToRemove + " revisions");
                MergeSnapshotRevisions(database, source, archive, numRevisionsToRemove);
            }
            else
            {
                FileSync.__Log(this, "Merge will not remove any revisions");
            }
        }
        public void MergeSnapshotRevisionsByTimeLimit(VolumeSnapshotDatabase database, VolumeSource source, BaseArchive archive, TimeSpan timePeriodToKeep)
        {
            // only keep revisions within a certain time period (e.g. last 6 months)
            List <VolumeSnapshotRevision> revisionHistory = database.GetRevisionHistory();
            int      numRevisionsToRemove = 0;
            DateTime cutOffDate           = DateTime.Now - timePeriodToKeep;

            foreach (VolumeSnapshotRevision revision in revisionHistory)
            {
                if (revision.CreationTime >= cutOffDate)
                {
                    break;
                }
                else
                {
                    numRevisionsToRemove++;
                }
            }
            if (numRevisionsToRemove > 0)
            {
                FileSync.__Log(this, "Merge will remove " + numRevisionsToRemove + " revisions");
                MergeSnapshotRevisions(database, source, archive, numRevisionsToRemove);
            }
            else
            {
                FileSync.__Log(this, "Merge will not remove any revisions");
            }
        }
        private void ProcessDirectoryRestore( VolumeSnapshotDirectory sourceDir, BaseArchive archive, int relativePathStartIndex, string targetDir )
        {
            if ( !mOperation.CanContinue )
                return;

            PWLib.Platform.Windows.Directory.CreateDirectory( targetDir );

            foreach ( VolumeSnapshotFile fileEntry in sourceDir.Files )
            {
                try
                {
                    string outDir = targetDir + fileEntry.RelativePath.Substring( relativePathStartIndex );
                    archive.RestoreFile( fileEntry.Revision, fileEntry.RelativePath, outDir, new ArchiveFileDelegate( Restore_ArchiveStoreFile ), fileEntry );

                    ulong runningSize = mFilesTotalSizeRunning + fileEntry.FileSize;
                    if ( runningSize > mFilesTotalSize )
                        runningSize = mFilesTotalSize;
                    if ( Progress != null )
                        Progress( mFileRunningCount + 1, mFileTotalCount, runningSize, mFilesTotalSize );
                }
                catch ( System.Exception e )
                {
                    if ( Error != null )
                        Error( "Restore file failed '" + fileEntry.RelativePath + "'", e );
                }

                if ( !mOperation.CanContinue )
                    return;

                mFileRunningCount++;
                mFilesTotalSizeRunning += fileEntry.FileSize;
            }

            foreach ( VolumeSnapshotDirectory directoryEntry in sourceDir.Directories )
            {
                ProcessDirectoryRestore( directoryEntry, archive, relativePathStartIndex, targetDir );
                if ( !mOperation.CanContinue )
                    return;
            }
        }