Esempio n. 1
0
        /// <summary>
        /// Checks if we have all the required reference information (ref backup usn metadata)
        /// and if the usn journal is available (existing and usable from reference journal & transaction ids)
        /// </summary>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public bool CheckCapability()
        {
            if (Utilities.PlatForm.IsUnixClient())
            {
                return(false);
            }
            try{
                if (prevJournalId == 0 || prevTransactionId == 0 /*|| brd.SystemDrive.DriveFormat.ToLower() != "ntfs"*/)
                {
                    Logger.Append(Severity.DEBUG, "No reference USN journal found. Either this is the first backup, either SetMetadata() has not been called yet, or drive is not NTFS/ReFS");
                    return(false);
                }

                using (NtfsUsnJournal jtest = new NtfsUsnJournal(brd /*.Snapshot.MountPoint*/)){
                    Console.WriteLine("CheckCapability() : instanciated usn j");
                    if (!jtest.IsUsnJournalActive())
                    {
                        Logger.Append(Severity.INFO, "the drive " + brd.SystemDrive.OriginalMountPoint + " doesn't have an USN tracking journal."
                                      + " It can be manually created using the command 'fsutil usn createjournal m=400000 a=100 " + brd.SystemDrive.OriginalMountPoint + "'");
                    }


                    if (journalId != prevJournalId /*|| transactionId < prevTransactionId*/)                      // journal has been reset, can't rely on it
                    {
                        Logger.Append(Severity.WARNING, "Drive " + brd.SystemDrive.OriginalMountPoint + " USN Journal has been reset since last time we checked it. Can't be used :"
                                      + "transaction id " + transactionId + "/" + prevTransactionId + ", journal " + journalId + "/" + prevJournalId);

                        /*Console.WriteLine ("********************************");
                        *  Console.WriteLine ("***MAKE IT RETURN FALSE!!!      *");
                        *  Console.WriteLine ("********************************");*/
                        return(false);
                    }
                    if (prevTransactionId < journalMinUsn)                    // some space has been freeed inside the journal, we cannot read back to wanted transaction
                    {
                        Logger.Append(Severity.WARNING, "Drive " + brd.SystemDrive.MountPoint + " Wanted start USN (" + prevTransactionId + ")is too old, has been recycled by the journal (min usable USN is " + journalMinUsn + "). Unable to use USN. If this occurs frequently, consider growing the USN journal max size.");
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception e) {
                Logger.Append(Severity.WARNING, "Drive '" + brd.SystemDrive.MountPoint + " (snap " + brd.Snapshot.MountPoint + ")' : can't use UsnJournal incremental/differential provider : " + e.ToString()
                              + ". Journal may not be accessed, not available for this kind of filesystem, or doesn't exist. You can create one using 'fsutil usn createjournal' command");
                return(false);
            }
        }