IInfrascaleSdkRunRecoveryJob Method |
Namespace: SOS.SDK.Contracts
RecoveryJobSessionContract RunRecoveryJob( RunRecoveryJobRequest request )
Exception | Condition |
---|---|
NotSignedIn | |
MethodCallFailed |
Starting Recovery Job with recoveryng of all files, backed up from current machine. Receive Recovery Job callbacks.
using System; using System.IO; using System.Linq; using System.Text; using SOS.SDK.Contracts.DataContracts; using SOS.SDK.Contracts.DataContracts.Enums; using SOS.SDK.Contracts.DataContracts.Jobs; using SOS.SDK.Contracts.DataContracts.Jobs.Recovery; using SOS.SDK.Contracts.DataContracts.Requests; using SOS.SDK.Contracts.DataContracts.Responses; using SOS.SDK.Tools.Runners; namespace SOS.SDK.Test.Examples.Recovery { public class RecoveryExamples { private readonly string _testAccount = @"sdk.test@sosonlinebackup.com"; private readonly string _testAccountPassword = @"qweqwe"; private IInfrascaleClient _client; private readonly string _recoveryDestination = @"C:\Obrm.Sdk.TestRecovery\"; private readonly TimeSpan _refreshRecoveryInfoTimeout = TimeSpan.FromMinutes(10); private readonly TimeSpan _recoveryTimeout = TimeSpan.FromMinutes(10); 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 }); } } private void RefreshRecoveryInfoWithRunner() { var runner = new RefreshRecoveryInfoJobRunner(_client); runner.Run(_identity, _refreshRecoveryInfoTimeout); } public void RecoveryOfCurrentSystem() { SignIn(); _client.SubscribeCallback(new SubscribeCallbackRequest { Identity = _identity }); RefreshRecoveryInfoWithRunner(); var recoveryRunner = new RecoveryJobRunner(_client, OnStarted, OnProgress, OnEvents, OnCompleted); recoveryRunner.Run(new RunRecoveryJobRequest { Identity = _identity, Items = new RecoveryItemContract[] { new RecoveryDirectoryContract { Path = Environment.MachineName } }, ConflictResolution = ConflictResolutionContract.Override, IncludePath = true, RestoreDestination = _recoveryDestination }, _recoveryTimeout); //Detach client SignOut(); } private void OnStarted(RecoveryJobSessionContract started) { Console.WriteLine("Recovery Job {0} is Started", started.JobId); } private void OnProgress(RecoveryJobSessionContract progress) { Console.WriteLine("JobID: {0}", progress.JobId); Console.WriteLine("\tJob state: {0}", progress.State); Console.WriteLine("\tCompleted, %: {0}", progress.ProgressPercentage); Console.WriteLine("\tRecoverySet Total: {0}", CountAndSizeToString(progress.Progress.Total)); Console.WriteLine("\tFailed: {0}", CountAndSizeToString(progress.Progress.Failed)); Console.WriteLine("\tInProgress: {0}", CountAndSizeToString(progress.Progress.InProgress)); Console.WriteLine("\tCompleted: {0}", CountAndSizeToString(progress.Progress.Completed)); } 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(RecoveryJobSessionContract completed) { Console.WriteLine("JobID: {0}", completed.JobId); Console.WriteLine("\tRecovery of {0} file(s) is completed.", completed.Progress.Total.Count); Console.WriteLine("JobState: {0}", completed.State); if (completed.State == SessionStateContract.Failed) { Console.WriteLine("Error: {0}", completed.ErrorMessage); } } private string CountAndSizeToString(CountAndSizeContract countAndSize) { return string.Format("{0} ({1} bytes)", countAndSize.Count, countAndSize.SizeBytes); } } }
Starting Recovery Job with filtering recovery items using unified helper method. Receive Recovery Job callbacks.
using System; using System.IO; using System.Linq; using System.Text; using SOS.SDK.Contracts.DataContracts; using SOS.SDK.Contracts.DataContracts.Enums; using SOS.SDK.Contracts.DataContracts.Jobs; using SOS.SDK.Contracts.DataContracts.Jobs.Recovery; using SOS.SDK.Contracts.DataContracts.Requests; using SOS.SDK.Contracts.DataContracts.Responses; using SOS.SDK.Tools.Runners; namespace SOS.SDK.Test.Examples.Recovery { public class RecoveryExamples { private readonly string _testAccount = @"sdk.test@sosonlinebackup.com"; private readonly string _testAccountPassword = @"qweqwe"; private IInfrascaleClient _client; private readonly string _recoveryDestination = @"C:\Obrm.Sdk.TestRecovery\"; private readonly TimeSpan _refreshRecoveryInfoTimeout = TimeSpan.FromMinutes(10); private readonly TimeSpan _recoveryTimeout = TimeSpan.FromMinutes(10); 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 }); } } private void RefreshRecoveryInfoWithRunner() { var runner = new RefreshRecoveryInfoJobRunner(_client); runner.Run(_identity, _refreshRecoveryInfoTimeout); } public void RecoveryWithRunnerFilterMethod() { SignIn(); _client.SubscribeCallback(new SubscribeCallbackRequest { Identity = _identity }); var filter = new RecoveryFilterContract { DateTo = DateTime.UtcNow, FileSizeInKbFrom = 0, FileSizeInKbTo = 1, PathFilter = @"C:\Obrm.Sdk.TestData\", FileName = "1-1.txt" }; var recoveryRunner = new RecoveryJobRunner(_client, OnStarted, OnProgress, OnEvents, OnCompleted); recoveryRunner.Run(_identity, Environment.MachineName, @"C:\Obrm.Sdk.TestData\", filter, ConflictResolutionContract.Override, true, _recoveryDestination, _recoveryTimeout); SignOut(); } private void OnStarted(RecoveryJobSessionContract started) { Console.WriteLine("Recovery Job {0} is Started", started.JobId); } private void OnProgress(RecoveryJobSessionContract progress) { Console.WriteLine("JobID: {0}", progress.JobId); Console.WriteLine("\tJob state: {0}", progress.State); Console.WriteLine("\tCompleted, %: {0}", progress.ProgressPercentage); Console.WriteLine("\tRecoverySet Total: {0}", CountAndSizeToString(progress.Progress.Total)); Console.WriteLine("\tFailed: {0}", CountAndSizeToString(progress.Progress.Failed)); Console.WriteLine("\tInProgress: {0}", CountAndSizeToString(progress.Progress.InProgress)); Console.WriteLine("\tCompleted: {0}", CountAndSizeToString(progress.Progress.Completed)); } 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(RecoveryJobSessionContract completed) { Console.WriteLine("JobID: {0}", completed.JobId); Console.WriteLine("\tRecovery of {0} file(s) is completed.", completed.Progress.Total.Count); Console.WriteLine("JobState: {0}", completed.State); if (completed.State == SessionStateContract.Failed) { Console.WriteLine("Error: {0}", completed.ErrorMessage); } } private string CountAndSizeToString(CountAndSizeContract countAndSize) { return string.Format("{0} ({1} bytes)", countAndSize.Count, countAndSize.SizeBytes); } } }
Starting Recovery Job with getting recovery items by separated calls. Receive Recovery Job callbacks.
using System; using System.IO; using System.Linq; using System.Text; using SOS.SDK.Contracts.DataContracts; using SOS.SDK.Contracts.DataContracts.Enums; using SOS.SDK.Contracts.DataContracts.Jobs; using SOS.SDK.Contracts.DataContracts.Jobs.Recovery; using SOS.SDK.Contracts.DataContracts.Requests; using SOS.SDK.Contracts.DataContracts.Responses; using SOS.SDK.Tools.Runners; namespace SOS.SDK.Test.Examples.Recovery { public class RecoveryExamples { private readonly string _testAccount = @"sdk.test@sosonlinebackup.com"; private readonly string _testAccountPassword = @"qweqwe"; private IInfrascaleClient _client; private readonly string _recoveryDestination = @"C:\Obrm.Sdk.TestRecovery\"; private readonly TimeSpan _refreshRecoveryInfoTimeout = TimeSpan.FromMinutes(10); private readonly TimeSpan _recoveryTimeout = TimeSpan.FromMinutes(10); 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 }); } } private void RefreshRecoveryInfoWithRunner() { var runner = new RefreshRecoveryInfoJobRunner(_client); runner.Run(_identity, _refreshRecoveryInfoTimeout); } public void RecoveryWithFilters() { SignIn(); _client.SubscribeCallback(new SubscribeCallbackRequest { Identity = _identity }); RefreshRecoveryInfoWithRunner(); //Extract metadata items var request = new GetRecoveryItemsRequest { Identity = _identity, Path = Environment.MachineName + @"\C:\Obrm.Sdk.TestData\", Filter = new RecoveryFilterContract { DateTo = DateTime.UtcNow, FileSizeInKbFrom = 0, FileSizeInKbTo = 1, PathFilter = @"C:\Obrm.Sdk.TestData\", FileName = "1-1.txt" } }; var output = _client.GetRecoveryItems(request); var recoveryRunner = new RecoveryJobRunner(_client, OnStarted, OnProgress, OnEvents, OnCompleted); recoveryRunner.Run(new RunRecoveryJobRequest { Identity = _identity, Items = output.EnumerateFiles().Cast<RecoveryItemContract>().ToArray(), ConflictResolution = ConflictResolutionContract.Override, IncludePath = true, RestoreDestination = _recoveryDestination }, _recoveryTimeout); //Detach client SignOut(); } private void OnStarted(RecoveryJobSessionContract started) { Console.WriteLine("Recovery Job {0} is Started", started.JobId); } private void OnProgress(RecoveryJobSessionContract progress) { Console.WriteLine("JobID: {0}", progress.JobId); Console.WriteLine("\tJob state: {0}", progress.State); Console.WriteLine("\tCompleted, %: {0}", progress.ProgressPercentage); Console.WriteLine("\tRecoverySet Total: {0}", CountAndSizeToString(progress.Progress.Total)); Console.WriteLine("\tFailed: {0}", CountAndSizeToString(progress.Progress.Failed)); Console.WriteLine("\tInProgress: {0}", CountAndSizeToString(progress.Progress.InProgress)); Console.WriteLine("\tCompleted: {0}", CountAndSizeToString(progress.Progress.Completed)); } 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(RecoveryJobSessionContract completed) { Console.WriteLine("JobID: {0}", completed.JobId); Console.WriteLine("\tRecovery of {0} file(s) is completed.", completed.Progress.Total.Count); Console.WriteLine("JobState: {0}", completed.State); if (completed.State == SessionStateContract.Failed) { Console.WriteLine("Error: {0}", completed.ErrorMessage); } } private string CountAndSizeToString(CountAndSizeContract countAndSize) { return string.Format("{0} ({1} bytes)", countAndSize.Count, countAndSize.SizeBytes); } } }