Example #1
0
        private static bool Run(BackupLevel backupLevel, string newBackupDirectory, string webFolderPath, string timeSuffix, DateTime?keepDate, bool waitForAttach)
        {
            bool ok = false;

            if (!(ok = BackupIndex()))
            {
                return(false);
            }
            if (backupLevel != BackupLevel.Index)
            {
                EnsureEmptyDirectory(newBackupDirectory);
                if (backupLevel == BackupLevel.Full)
                {
                    if (!BackupWebfolder(webFolderPath, newBackupDirectory, timeSuffix))
                    {
                        return(false);
                    }
                }
                if (!BackupDatabase(newBackupDirectory, timeSuffix))
                {
                    return(false);
                }
                if (keepDate != null)
                {
                    Clean(Path.GetDirectoryName(newBackupDirectory), keepDate.Value);
                }
            }
            return(true);
        }
Example #2
0
File: VSS.cs Project: radtek/BackO
        public VSS(BackupLevel level)
        {
            this.RestorePosition    = RestoreOrder.AfterStorage;
            this.ExplodedComponents = new List <string>();
            Metadata  = new SPOMetadata();
            BasePaths = new List <BasePath>();
            IVssImplementation vss = VssUtils.LoadImplementation();

            backup = vss.CreateVssBackupComponents();
            //Logger.Append(Severity.DEBUG, "0/6 Initializing Snapshot ("+ ((BasePaths == null)? "NON-component mode" : "component mode")+")");
            backup.InitializeForBackup(null);
            VssBackupType vssLevel = VssBackupType.Full;

            if (level == BackupLevel.Full)
            {
                vssLevel = VssBackupType.Full;
            }
            else if (level == BackupLevel.Refresh)
            {
                vssLevel = VssBackupType.Incremental;
            }

            /*	else if (level == BackupLevel.Differential)
             *                      vssLevel = VssBackupType.Differential;*/
            else if (level == BackupLevel.TransactionLog)
            {
                vssLevel = VssBackupType.Log;
            }
            //if(spoPaths == null) // component-less snapshot set
            //		backup.SetBackupState(false, true, VssBackupType.Full, false);
            //else
            backup.SetBackupState(true, true, vssLevel, false);
            if (OperatingSystemInfo.IsAtLeast(OSVersionName.WindowsServer2003))
            {
                // The only context supported on Windows XP is VssSnapshotContext.Backup
                backup.SetContext(VssSnapshotContext.AppRollback);
            }
            //Logger.Append(Severity.DEBUG, "1/6 Gathering writers metadata and status");
            using (IVssAsync async = backup.GatherWriterMetadata()){
                async.Wait();
                async.Dispose();
            }
            // gather writers status before adding backup set components
            using (IVssAsync async = backup.GatherWriterStatus()){
                async.Wait();
                async.Dispose();
            }
        }
Example #3
0
        private SnapshotSupportedLevel  ConvertBackupLevelToSnLevel(BackupLevel backupLevel)
        {
            if (backupLevel == BackupLevel.Full /*|| backupLevel == BackupLevel.SyntheticFull*/)
            {
                return(SnapshotSupportedLevel.Full);
            }

            /*else if (backupLevel == BackupLevel.Differential)
             *      return SnapshotSupportedLevel.Differential;*/
            else if (backupLevel == BackupLevel.Refresh)
            {
                return(SnapshotSupportedLevel.Incremental);
            }
            else
            {
                return(SnapshotSupportedLevel.Full);
            }
        }
Example #4
0
        /// <summary>
        /// Gets the last task successfully ran for this backupset,
        /// and with the specified level (if not null).
        /// Used to get the 'reference' or 'parent' task when performing a 'Refresh'-level backup.
        /// </summary>
        /// <returns>
        /// The last reference task.
        /// </returns>
        /// <param name='bsId'>
        /// BackupSet identifier.
        /// </param>
        /// <param name='level'>
        /// Level.
        /// </param>
        public Task GetLastReferenceTask(int bsId, BackupLevel level)
        {
            Console.WriteLine("\t\tGetLastReferenceTask() : asked ref for bs#" + bsId + " with level=" + level);
            using (dbc = DAL.Instance.GetDb()){
                /*var refTask =  dbc.Select<Task>( t=> t.BackupSetId == bsId
                 *      && t.Operation == TaskOperation.Backup
                 *      && t.Status == TaskStatus.Ok
                 *      && t.RunStatus == TaskRunningStatus.Done
                 *      && t.Level == level.Value);*/
                // && ((level.HasValue)? level.Value : t.Level != null));

                var ev = OrmLiteConfig.DialectProvider.ExpressionVisitor <Task>();
                if (level != BackupLevel.Default)
                {
                    ev = ev.Where(t => t.BackupSetId == bsId &&
                                  t.Operation == TaskOperation.Backup &&
                                  t.Status == TaskStatus.Ok &&
                                  t.RunStatus == TaskRunningStatus.Done &&
                                  t.Level == level);
                }
                else
                {
                    ev = ev.Where(t => t.BackupSetId == bsId &&
                                  t.Operation == TaskOperation.Backup &&
                                  t.Status == TaskStatus.Ok &&
                                  t.RunStatus == TaskRunningStatus.Done);
                }

                ev = ev.OrderByDescending(t => t.Id);
                var result1 = dbc.Select(ev);

                if (result1.Count > 0)
                {
                    return(result1[0]);
                }
                else
                {
                    return(null);
                }
            }
        }
Example #5
0
 internal BackupRootDriveHandler(BackupRootDrive brd, long taskId, long maxChkSize, long maxPack, int maxChunkFiles, P2PBackup.Common.BackupLevel bType, long refStartDate, long refEndDate, long referenceTaskid /*, long refMaxId*/)
 {
     backupRootDrive      = brd;
     maxChunkSize         = maxChkSize;
     maxPackSize          = maxPack;
     this.maxChunkFiles   = maxChunkFiles;
     nbItems              = 0;
     this.backupType      = bType;
     this.depth           = 0;
     this.subCompletionNb = 0;
     this.completionBase  = 0;
     this.refStartDate    = refStartDate;
     this.refEndDate      = refEndDate;
     this.referenceTaskid = referenceTaskid;
     this.MaxItemID       = 0;      //refMaxId;
     this.TaskId          = taskId;
     //if(path.Type ==  BasePath.PathType.FS)
     //itemIterator = GetFilesToBackup().GetEnumerator();
     prov         = ItemProvider.GetProvider();
     fsEnumerator = FSEnumeratorProvider.GetFSEnumeratorProvider();
 }
Example #6
0
 private static bool Run(BackupLevel backupLevel, string newBackupDirectory, string webFolderPath, string timeSuffix, DateTime? keepDate, bool waitForAttach, bool forceRestore)
 {
     bool ok = false;
     if (!(ok = BackupIndex(forceRestore)))
         return false;
     if (forceRestore)
         ForceRestoreStart();
     if (backupLevel != BackupLevel.Index)
     {
         EnsureEmptyDirectory(newBackupDirectory);
         if (backupLevel == BackupLevel.Full)
             if (!BackupWebfolder(webFolderPath, newBackupDirectory, timeSuffix))
                 return false;
         if (!BackupDatabase(newBackupDirectory, timeSuffix))
             return false;
         if (keepDate != null)
             Clean(Path.GetDirectoryName(newBackupDirectory), keepDate.Value);
     }
     if (forceRestore)
         return WaitForRestored();
     return true;
 }
Example #7
0
        private static void Run(BackupLevel backupLevel, string backupPath, string webFolderPath, double keepDays, bool confirm, bool waitForAttach, bool forceRestore)
        {
            var timer = Stopwatch.StartNew();

            var s = ConfigurationManager.AppSettings[CONFIG_BACKUPDIRECORYPREFIX_KEY];
            if (!String.IsNullOrEmpty(s))
                BackupPrefix = s;

            var now = DateTime.Now;
            var keepDate = keepDays == 0 ? (DateTime?)null :
                (Math.Floor(keepDays) == keepDays ? new DateTime(now.Year, now.Month, now.Day) : now).AddDays(-keepDays);
            //var keepDate = keepDays == 0 ? (DateTime?)null : new DateTime(now.Year, now.Month, now.Day).AddDays(-keepDays);
            //var keepDate = keepDays == 0 ? (DateTime?)null : now.AddDays(-keepDays);
            var timeSuffix = now.ToString("yyyyMMdd-HHmmss");
            var newBackupDirectory = Path.Combine(backupPath, BackupPrefix + timeSuffix);

            Console.WriteLine();
            Console.WriteLine("======================== Sense/Net Backup Tool ==============================");
            Console.WriteLine("  BACKUP LEVEL:     {0}", backupLevel);
            if (backupLevel != BackupLevel.Index)
                Console.WriteLine("  BACKUP DIRECTORY: {0}", newBackupDirectory);
            if (backupLevel == BackupLevel.Full)
                Console.WriteLine("  WEBFOLDER:        {0}", webFolderPath);
            if (keepDate != null && backupLevel != BackupLevel.Index)
                Console.WriteLine("  CLEANING:         The backups will be deleted that are created before {0}", keepDate);
            if(forceRestore)
                Console.WriteLine("  All active instances will restore the index");
            else
                Console.WriteLine("  Active instances will not restore the index");
            Console.WriteLine("=============================================================================");
            if (confirm)
            {
                bool? ok = null;
                do
                {
                    Console.Write("Are you sure you want to continue with this parameters (<Y>: yes, <N>: no) ? ");
                    var key = Console.ReadLine();
                    if (key.ToUpper() == "Y")
                        ok = true;
                    if (key.ToUpper() == "N")
                        ok = false;
                } while (ok == null);
                Console.WriteLine("=============================================================================");
                if (ok == false)
                {
                    Console.WriteLine();
                    Console.WriteLine("Backup is not executed.");
                    Console.WriteLine();
                    return;
                }
            }
            Console.WriteLine("Executing backup...");

            var successful = Run(backupLevel, newBackupDirectory, webFolderPath, timeSuffix, keepDate, waitForAttach, forceRestore);
            timer.Stop();
            if (successful)
            {
                Console.WriteLine();
                Console.WriteLine("========================================");
                Console.WriteLine("Backup is successfully finished.");
                Console.WriteLine("Total executing time: " + timer.Elapsed);
                Console.WriteLine();
            }
            Console.WriteLine();
        }
Example #8
0
        private static void Run(BackupLevel backupLevel, string backupPath, string webFolderPath, double keepDays, bool confirm, bool waitForAttach)
        {
            var timer = Stopwatch.StartNew();

            var s = ConfigurationManager.AppSettings[CONFIG_BACKUPDIRECORYPREFIX_KEY];

            if (!String.IsNullOrEmpty(s))
            {
                BackupPrefix = s;
            }

            var now      = DateTime.UtcNow;
            var keepDate = keepDays == 0 ? (DateTime?)null :
                           (Math.Floor(keepDays) == keepDays ? new DateTime(now.Year, now.Month, now.Day) : now).AddDays(-keepDays);
            //var keepDate = keepDays == 0 ? (DateTime?)null : new DateTime(now.Year, now.Month, now.Day).AddDays(-keepDays);
            //var keepDate = keepDays == 0 ? (DateTime?)null : now.AddDays(-keepDays);
            var timeSuffix         = now.ToString("yyyyMMdd-HHmmss");
            var newBackupDirectory = Path.Combine(backupPath, BackupPrefix + timeSuffix);

            Console.WriteLine();
            Console.WriteLine("======================== Sense/Net Backup Tool ==============================");
            Console.WriteLine("  BACKUP LEVEL:     {0}", backupLevel);
            if (backupLevel != BackupLevel.Index)
            {
                Console.WriteLine("  BACKUP DIRECTORY: {0}", newBackupDirectory);
            }
            if (backupLevel == BackupLevel.Full)
            {
                Console.WriteLine("  WEBFOLDER:        {0}", webFolderPath);
            }
            if (keepDate != null && backupLevel != BackupLevel.Index)
            {
                Console.WriteLine("  CLEANING:         The backups will be deleted that are created before {0}", keepDate);
            }
            Console.WriteLine("=============================================================================");
            if (confirm)
            {
                bool?ok = null;
                do
                {
                    Console.Write("Are you sure you want to continue with this parameters (<Y>: yes, <N>: no) ? ");
                    var key = Console.ReadLine();
                    if (key.ToUpper() == "Y")
                    {
                        ok = true;
                    }
                    if (key.ToUpper() == "N")
                    {
                        ok = false;
                    }
                } while (ok == null);
                Console.WriteLine("=============================================================================");
                if (ok == false)
                {
                    Console.WriteLine();
                    Console.WriteLine("Backup is not executed.");
                    Console.WriteLine();
                    return;
                }
            }
            Console.WriteLine("Executing backup...");

            var successful = Run(backupLevel, newBackupDirectory, webFolderPath, timeSuffix, keepDate, waitForAttach);

            timer.Stop();
            if (successful)
            {
                Console.WriteLine();
                Console.WriteLine("========================================");
                Console.WriteLine("Backup is successfully finished.");
                Console.WriteLine("Total executing time: " + timer.Elapsed);
                Console.WriteLine();
            }
            Console.WriteLine();
        }
Example #9
0
        private bool StartTask(Task task)
        {
            bool done = false;

            if (task.Operation == TaskOperation.HouseKeeping)
            {
                return(StartHouseKeeping(task));
            }

            PeerNode taskTargetNode = GetHandlingNode(task);

            // temp : for debugging udp wakeup

            /*if(taskTargetNode == null){
             *      NodesMonitor.Instance.WakeUp(new DAL.NodeDAO().Get(task.NodeId));
             *      Thread.Sleep(5000);
             *      taskTargetNode = GetHandlingNode(task.Id);
             * }*/

            if (taskTargetNode == null)
            {
                throw new UnreachableNodeException("Node #" + taskTargetNode + " is offline or unreachable");
            }
            else if (taskTargetNode.Quota > 0 && taskTargetNode.UsedQuota >= taskTargetNode.Quota)
            {
                throw new OverQuotaException(taskTargetNode.UsedQuota, taskTargetNode.Quota);
            }
            else if (taskTargetNode.Status == NodeStatus.Idle)
            {
                Logger.Append("HUBRN", Severity.INFO, "Node #" + taskTargetNode.Id + " is idle, telling him to wakeup and prepare for task #" + task.Id);
                NodeWakeUpNeeded(taskTargetNode);
                return(false);
            }
            Logger.Append("HUBRN", Severity.INFO, "Starting Task " + task.Id + " : type " + task.Type + " ( level " + task.Level /* .BackupSet.ScheduleTimes[0].Level*/ + "), backup Set " + task.BackupSet.Id + " for client #" + task.BackupSet.NodeId + " (handled by node #" + task.BackupSet.HandledBy + ")");
            //Console.WriteLine("TaskScheduler : handledby = "+task.BackupSet.HandledBy+", proxying info is null : "+(task.BackupSet.ProxyingInfo == null));
            try{
                BackupLevel referenceLevel = BackupLevel.Default;
                if (task.Level == BackupLevel.Differential)
                {
                    referenceLevel = BackupLevel.Full;
                }

                P2PBackup.Common.Task referenceTask = new DAL.TaskDAO().GetLastReferenceTask(task.BackupSet.Id, referenceLevel);
                if (referenceTask != null)
                {
                    task.StorageBudget = (int)((referenceTask.OriginalSize / task.BackupSet.MaxChunkSize) + 2);
                    Console.WriteLine(" ____ ref task=" + referenceTask.Id + ", oSize=" + referenceTask.OriginalSize / 1024 / 1024 + "MB, maxchunksize=" + task.BackupSet.MaxChunkSize / 1024 / 1024 + "MB, %%=" + referenceTask.OriginalSize / task.BackupSet.MaxChunkSize + ", calculated budget=" + task.StorageBudget);
                    task.ParentTask = referenceTask;
                }

                if (task.Level != BackupLevel.Full)
                {
                    if (referenceTask == null || referenceTask.Id <= 0)                     // no ref backup found, doing full
                    {
                        Logger.Append("HUBRN", Severity.INFO, "No reference backup found for task " + task.Id + ", performing FULL backup.");
                        task.Level = BackupLevel.Full;
                    }
                    else
                    {
                        task.ParentTrackingId = referenceTask.Id;
                        Logger.Append("HUBRN", Severity.INFO, "Task " + task.Id + " is " + task.Level + "."
                                      + " Using reference task " + referenceTask.Id + " (" + referenceTask.StartDate + " - " + referenceTask.EndDate + ")");
                    }
                }
                taskTargetNode.ManageTask(task, TaskAction.Start);
                task.RunStatus = TaskRunningStatus.Started;
                //n.Status = NodeStatus.Backuping;
                done = true;
            }
            catch (Exception e) {
                done = false;
                Logger.Append("HUBRN", Severity.ERROR, "Could not send task " + task.Id + " to node #" + taskTargetNode.Id + " : " + e.ToString() /*+"---Stacktrace:"+e.StackTrace+" inner msg:"+e.InnerException.Message*/);
                //n.Status = NodeStatus.Error;
            }
            return(done);
        }
Example #10
0
        private string ParseAndAddBS(string rawData)
        {
            ArrayList clientIds;
            ArrayList paths;

            if (rawData.Substring(0, 2) == "[]")
            {
                return("You must select at least 1 node which will process this backup set");
            }
            int endOfClients = rawData.IndexOf("]],");

            clientIds = GetClientIds(rawData.Substring(2, endOfClients - 2));
            if (clientIds.Count == 0)
            {
                return("You must select at least one client to backup");
            }
            if (rawData.Substring(endOfClients, 3) == "[]")
            {
                return("You must select at least one path to backup");
            }
            int endOfPaths = rawData.IndexOf('{');

            paths = GetPaths(rawData.Substring(endOfClients, endOfPaths - endOfClients));
            int    endOfFilesSelection = rawData.IndexOf('}');
            string jGroupBk            = rawData.Substring(endOfPaths + 1, endOfFilesSelection - endOfPaths - 1);
            string rootPath            = GetValueFromJson("basePath", jGroupBk);

            if (paths.Count == 0 || rootPath == null)
            {
                return("You must select at least one path to backup");
            }
            string includePolicy = GetValueFromJson("includePolicy", jGroupBk);
            string excludePolicy = GetValueFromJson("excludePolicy", jGroupBk);
            bool   compress      = (GetValueFromJson("compress", jGroupBk) == "on")?true:false;
            bool   encrypt       = (GetValueFromJson("encrypt", jGroupBk) == "on")?true:false;
            int    endOfOps      = rawData.IndexOf('}', endOfFilesSelection - endOfPaths);
            string jGroupOps     = rawData.Substring(endOfFilesSelection - endOfPaths, endOfOps);
            string preops        = GetValueFromJson("preops", jGroupOps);
            string postops       = GetValueFromJson("postops", jGroupOps);

            Console.WriteLine("rootPath=" + rootPath + ",includepolicy=" + includePolicy + "excludepolicy=" + excludePolicy + ",compress=" + compress);
            // getting per-day backup scheduling
            string rawSchedulingInfo = rawData.Substring(endOfOps);

            List <ScheduleTime> bTimes = new List <ScheduleTime>();
            List <BasePath>     bPaths = new List <BasePath>();

            for (int i = 0; i < 7; i++)
            {
                string day = ((DayOfWeek)i).ToString();
                if (GetValueFromJson(day + "Do", rawSchedulingInfo) == "on")
                {
                    if (GetValueFromJson(day + "Hour", rawSchedulingInfo).Split(':').Length == 2 &&
                        GetValueFromJson(day + "Type", rawSchedulingInfo) != null)
                    {
                        BackupLevel  bType = (BackupLevel)Enum.Parse(typeof(BackupLevel), GetValueFromJson(day + "Type", rawSchedulingInfo));
                        ScheduleTime bt    = new ScheduleTime(bType, (DayOfWeek)i, GetValueFromJson(day + "Hour", rawSchedulingInfo), string.Empty);
                        bTimes.Add(bt);
                    }
                }
            }
            if (rootPath != null)
            {
                BasePath bp = new BasePath();
                bp.Path = rootPath;
                bp.IncludePolicy.Add(includePolicy);
                bp.ExcludePolicy.Add(excludePolicy);
                bPaths.Add(bp);
            }
            foreach (string thePath in paths)
            {
                BasePath bp = new BasePath();
                bp.Path = thePath;
                bp.IncludePolicy.Add(includePolicy);
                bp.ExcludePolicy.Add(excludePolicy);
                bPaths.Add(bp);
            }
            IRemoteOperations rOp          = RemotingManager.GetRemoteObject();
            string            createResult = null;

            foreach (int client in clientIds)
            {
                BackupSet newBs = new BackupSet();
                newBs.NodeId        = client;
                newBs.ScheduleTimes = bTimes;
                newBs.BasePaths     = bPaths;
                //newBs.Compress = compress;
                //newBs.Encrypt = encrypt;
                newBs.Preop   = preops;
                newBs.Postop  = postops;
                createResult += "," + rOp.CreateBackupSet(newBs);
            }
            if (createResult == null)
            {
                return("New BackupSet successfully created on Hub.");
            }
            else
            {
                return(createResult);
            }
        }