Click or drag to resize

IInfrascaleSdkRunOnlineBackupJob Method

Add new Online Backup job request using existing settings.

Namespace:  SOS.SDK.Contracts
Assembly:  SOS.SDK (in SOS.SDK.dll) Version: 7.6.1.5742
Syntax
C#
OnlineBackupJobSessionContract RunOnlineBackupJob(
	RunOnlineBackupJobRequest request
)

Parameters

request
Type: SOS.SDK.Contracts.DataContracts.RequestsRunOnlineBackupJobRequest
Container with request parameters.

Return Value

Type: OnlineBackupJobSessionContract
Container with JobSession for monitoring.
Exceptions
ExceptionCondition
NotSignedIn
MethodCallFailed
Remarks
Backup jobs are added to jobs queue. Only one backup job can be performed simultaneously. When current job is completed, next job reads actual settings from the settings storage.
Examples

You can start the Backup Job by calling this method. This method is asynchronous and the backup continues to run after the method call returns a response.

Run Online Backup using raw contracts
using System;
using System.Diagnostics;
using System.Security.Principal;
using SOS.SDK.Contracts.DataContracts;
using SOS.SDK.Contracts.DataContracts.Jobs;
using SOS.SDK.Contracts.DataContracts.Jobs.Backup;
using SOS.SDK.Contracts.DataContracts.Requests;
using SOS.SDK.Tools.Creators;
using SOS.SDK.Tools.Runners;

namespace SOS.SDK.Test.Examples.OnlineBackup
{
    public class RunOnlineBackupExamples
    {
        private string _testAccount = @"sdk.test@sosonlinebackup.com";
        private string _testAccountPassword = @"qweqwe";
        private InfrascaleClient _client;
        private IdentityContract _identity;

        public void SignIn()
        {
            if (_client == null)
            {
                _client = new InfrascaleClient();
                _client.Connect();
                _identity = null;
            }

            if (_identity == null)
            {
                var signInResponse = _client.SignIn(new SignInRequest
                {
                    Credentials = new CredentialsContract { Login = _testAccount, Password = _testAccountPassword }
                });

                _identity = signInResponse.Identity;

                _client.SubscribeCallback(new SubscribeCallbackRequest {Identity = _identity});
            }
        }

        public void RunBackup()
        {
            SignIn();

            // Used by Infrascale Server for impersonation under required user permissions
            var currentProcessName = Process.GetCurrentProcess().ProcessName;

            // Used by Infrascale Server for impersonation under required user permissions
            string currentUserName;
            using (var windowsIdentity = WindowsIdentity.GetCurrent())
            {
                currentUserName = windowsIdentity.Name;
            }

            var request = new RunOnlineBackupJobRequest
            {
                CallingProcessName = currentProcessName,
                WindowsUser = currentUserName,
                IgnorePolicy = false,
                EndTime = DateTime.MaxValue,
                Identity = _identity
            };

            _client.RunOnlineBackupJob(request);

            SignOut();
        }
    }
}

You can monitor Backup Job by subscribing to Job Events.

Run Online Backup using raw contracts
using System;
using System.Diagnostics;
using System.Security.Principal;
using SOS.SDK.Contracts.DataContracts;
using SOS.SDK.Contracts.DataContracts.Jobs;
using SOS.SDK.Contracts.DataContracts.Jobs.Backup;
using SOS.SDK.Contracts.DataContracts.Requests;
using SOS.SDK.Tools.Creators;
using SOS.SDK.Tools.Runners;

namespace SOS.SDK.Test.Examples.OnlineBackup
{
    public class RunOnlineBackupExamples
    {
        private string _testAccount = @"sdk.test@sosonlinebackup.com";
        private string _testAccountPassword = @"qweqwe";
        private InfrascaleClient _client;
        private IdentityContract _identity;

        public void SignIn()
        {
            if (_client == null)
            {
                _client = new InfrascaleClient();
                _client.Connect();
                _identity = null;
            }

            if (_identity == null)
            {
                var signInResponse = _client.SignIn(new SignInRequest
                {
                    Credentials = new CredentialsContract { Login = _testAccount, Password = _testAccountPassword }
                });

                _identity = signInResponse.Identity;

                _client.SubscribeCallback(new SubscribeCallbackRequest {Identity = _identity});
            }
        }

        public void RunBackupWithMonitoringAndUsingRawContractsAndUseStoredSettings()
        {
            SignIn();

            // It's safe to make this request multiple times.
            // You can call them before starting each Job.
            _client.SubscribeCallback(new SubscribeCallbackRequest {Identity = _identity});

            using (var listener = _client.ListenOnlineBackupJob(
                OnStarted, OnProgress,
                OnEvents, OnCompleted))
            {
                // Used by Infrascale Server for impersonation under required user permissions
                var currentProcessName = Process.GetCurrentProcess().ProcessName;

                // Used by Infrascale Server for impersonation under required user permissions
                string currentUserName;
                using (var windowsIdentity = WindowsIdentity.GetCurrent())
                {
                    currentUserName = windowsIdentity.Name;
                }

                // Starting Online Backup Job using stored backup settings
                var session = _client.RunOnlineBackupJob(new RunOnlineBackupJobRequest
                {
                    Identity = _identity,
                    CallingProcessName = currentProcessName,
                    WindowsUser = currentUserName
                });

                listener.FilterJobId = session.JobId;

                listener.WaitForCompletion();
            }

            // Note: this call unsubscribes you from all Infrascale Server callbacks, not just from current session events.
            // Don't call this method, if you want to receive other sessions callbacks.
            _client.UnsubscribeCallback(new UnsubscribeCallbackRequest {Identity = _identity});

            SignOut();
        }
    }
}

You can use helper OnlineBackupJobRunner for synchronous running and monitoring of its progress.

Run Online Backup using stored settings
using System;
using System.Diagnostics;
using System.Security.Principal;
using SOS.SDK.Contracts.DataContracts;
using SOS.SDK.Contracts.DataContracts.Jobs;
using SOS.SDK.Contracts.DataContracts.Jobs.Backup;
using SOS.SDK.Contracts.DataContracts.Requests;
using SOS.SDK.Tools.Creators;
using SOS.SDK.Tools.Runners;

namespace SOS.SDK.Test.Examples.OnlineBackup
{
    public class RunOnlineBackupExamples
    {
        private string _testAccount = @"sdk.test@sosonlinebackup.com";
        private string _testAccountPassword = @"qweqwe";
        private InfrascaleClient _client;
        private IdentityContract _identity;

        public void SignIn()
        {
            if (_client == null)
            {
                _client = new InfrascaleClient();
                _client.Connect();
                _identity = null;
            }

            if (_identity == null)
            {
                var signInResponse = _client.SignIn(new SignInRequest
                {
                    Credentials = new CredentialsContract { Login = _testAccount, Password = _testAccountPassword }
                });

                _identity = signInResponse.Identity;

                _client.SubscribeCallback(new SubscribeCallbackRequest {Identity = _identity});
            }
        }

        public void RunBackupWithMonitoringAndUseStoredSettings()
        {
            SignIn();

            var obRunner = CreateOnlineBackupRunner();

            obRunner.Run(_identity, TimeSpan.MaxValue);

            SignOut();
        }

        private void OnStarted(OnlineBackupJobSessionContract started)
        {
            Console.WriteLine("Backup Job {0} is Started", started.JobId);
        }

        private void OnProgress(OnlineBackupJobSessionContract progress)
        {
            Console.WriteLine("JobID: {0}", progress.JobId);
            Console.WriteLine("\tJob state: {0}", progress.BackupState);
            Console.WriteLine("\tCompleted, %: {0}", progress.ProgressPercentage);

            Console.WriteLine("\tBackupSet Total: {0}", CountAndSizeToString(progress.Progress.BackupSet));
            Console.WriteLine("\tFailed:          {0}", CountAndSizeToString(progress.Progress.Failed));
            Console.WriteLine("\tModified:        {0}", CountAndSizeToString(progress.Progress.Modified));
            Console.WriteLine("\tProcessed:       {0}", CountAndSizeToString(progress.Progress.Total));
            Console.WriteLine("\tUnchanged:       {0}", CountAndSizeToString(progress.Progress.Unchanged));
            Console.WriteLine("\tUploaded:        {0}", CountAndSizeToString(progress.Progress.Uploaded));

            foreach (var progressFileState in progress.Progress.FileStates)
            {
                Console.WriteLine("\t{0}: {1} ({2} / {3})", progressFileState.Name, progressFileState.Status, progressFileState.CompletedSizeBytes, progressFileState.TotalSizeBytes);
            }
        }

        private void OnEvents(JobEventsContract events)
        {
            Console.WriteLine("JobID: {0}", events.JobId);
            Console.WriteLine("\tEvents:");

            foreach (var jobEventContract in events.Events)
            {
                Console.WriteLine("\t{0}: [{1}] {2}", jobEventContract.EventTime, jobEventContract.MessageType, jobEventContract.Message);
            }
        }

        private void OnCompleted(OnlineBackupJobSessionContract completed)
        {
            Console.WriteLine("JobID: {0}", completed.JobId);
            Console.WriteLine("\tBackup of {0} file(s) is completed.", completed.Progress.Total.Count);
        }

        private string CountAndSizeToString(CountAndSizeContract countAndSize)
        {
            return string.Format("{0} ({1} bytes)", countAndSize.Count, countAndSize.SizeBytes);
        }
    }
}

You can use overloaded method of the OnlineBackupJobRunner for set new Online Backup settings before running backup.

Run Online Backup with storing settings
using System;
using System.Diagnostics;
using System.Security.Principal;
using SOS.SDK.Contracts.DataContracts;
using SOS.SDK.Contracts.DataContracts.Jobs;
using SOS.SDK.Contracts.DataContracts.Jobs.Backup;
using SOS.SDK.Contracts.DataContracts.Requests;
using SOS.SDK.Tools.Creators;
using SOS.SDK.Tools.Runners;

namespace SOS.SDK.Test.Examples.OnlineBackup
{
    public class RunOnlineBackupExamples
    {
        private string _testAccount = @"sdk.test@sosonlinebackup.com";
        private string _testAccountPassword = @"qweqwe";
        private InfrascaleClient _client;
        private IdentityContract _identity;

        public void SignIn()
        {
            if (_client == null)
            {
                _client = new InfrascaleClient();
                _client.Connect();
                _identity = null;
            }

            if (_identity == null)
            {
                var signInResponse = _client.SignIn(new SignInRequest
                {
                    Credentials = new CredentialsContract { Login = _testAccount, Password = _testAccountPassword }
                });

                _identity = signInResponse.Identity;

                _client.SubscribeCallback(new SubscribeCallbackRequest {Identity = _identity});
            }
        }

        public void RunBackupWithMonitoringAndSettingBackupSet()
        {
            SignIn();

            var obRunner = CreateOnlineBackupRunner();

            var obCreator = new OnlineBackupSettingsContractCreator();
            obCreator.AddDir(@"C:\\BackupRoot");

            obRunner.Run(_identity, obCreator, TimeSpan.MaxValue);

            SignOut();
        }

        private void OnStarted(OnlineBackupJobSessionContract started)
        {
            Console.WriteLine("Backup Job {0} is Started", started.JobId);
        }

        private void OnProgress(OnlineBackupJobSessionContract progress)
        {
            Console.WriteLine("JobID: {0}", progress.JobId);
            Console.WriteLine("\tJob state: {0}", progress.BackupState);
            Console.WriteLine("\tCompleted, %: {0}", progress.ProgressPercentage);

            Console.WriteLine("\tBackupSet Total: {0}", CountAndSizeToString(progress.Progress.BackupSet));
            Console.WriteLine("\tFailed:          {0}", CountAndSizeToString(progress.Progress.Failed));
            Console.WriteLine("\tModified:        {0}", CountAndSizeToString(progress.Progress.Modified));
            Console.WriteLine("\tProcessed:       {0}", CountAndSizeToString(progress.Progress.Total));
            Console.WriteLine("\tUnchanged:       {0}", CountAndSizeToString(progress.Progress.Unchanged));
            Console.WriteLine("\tUploaded:        {0}", CountAndSizeToString(progress.Progress.Uploaded));

            foreach (var progressFileState in progress.Progress.FileStates)
            {
                Console.WriteLine("\t{0}: {1} ({2} / {3})", progressFileState.Name, progressFileState.Status, progressFileState.CompletedSizeBytes, progressFileState.TotalSizeBytes);
            }
        }

        private void OnEvents(JobEventsContract events)
        {
            Console.WriteLine("JobID: {0}", events.JobId);
            Console.WriteLine("\tEvents:");

            foreach (var jobEventContract in events.Events)
            {
                Console.WriteLine("\t{0}: [{1}] {2}", jobEventContract.EventTime, jobEventContract.MessageType, jobEventContract.Message);
            }
        }

        private void OnCompleted(OnlineBackupJobSessionContract completed)
        {
            Console.WriteLine("JobID: {0}", completed.JobId);
            Console.WriteLine("\tBackup of {0} file(s) is completed.", completed.Progress.Total.Count);
        }

        private string CountAndSizeToString(CountAndSizeContract countAndSize)
        {
            return string.Format("{0} ({1} bytes)", countAndSize.Count, countAndSize.SizeBytes);
        }
    }
}
See Also