public static void Backup() { var db = DbMocker.NewDataBase(); //List<UserInfo> list = new List<UserInfo>(); //for (int i = 0; i < 10; i++) //{ // var user1 = new UserInfo // { // Name = "NameInsert" + i, // Age = 20 + 16, // DTCreate = new DateTime(1985, 1, 1), // Role = RoleType.经理 // }; // list.Add(user1); // //db.Insert(user1); //} ////db.InsertBulk(list); //db.InsertBatch(list, new BatchOptions() { BatchSize = 30 }); BackupOption option = new BackupOption(); option.BackupExportType = BackupExportType.InsertSQL; option.EnableSqlFilter = false; option.SQL = "";// "SELECT * FROM TB_USER WHERE ID >0 AND ID <=10 ORDER BY ID "; var result = db.Backup <UserInfo>(option); Console.WriteLine(result.ToString()); }
public BackupMetadata(Guid originalServicePartitionId, DateTime timeStampUtc, BackupOption backupOption, Guid backupId) { BackupId = backupId; OriginalServicePartitionId = originalServicePartitionId; TimeStampUtc = timeStampUtc; BackupOption = backupOption; }
/// <summary> /// Backups database file. /// If dblock is true, operation will block all insert, delete and shrink operations til end /// </summary> public async Task <bool> Backup(BackupOption option, bool dblock = true) { if (_file == null) { return(false); } try { await Close(dblock); if (option == BackupOption.Move) { File.Move(Filename, Filename + ".backup", true); } else { File.Copy(Filename, Filename + ".backup", true); } return(true); } catch (Exception e) { _database.TriggerError(ErrorHint.Backup, e); return(false); } }
Task IStateProviderReplica.BackupAsync( BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { return(this.stateManager.BackupAsync(option, timeout, cancellationToken, backupCallback)); }
/// <summary> /// Performs a backup of all reliable state managed by this <see cref="IStateProviderReplica"/>. /// </summary> /// <param name="option">The type of backup to perform.</param> /// <param name="timeout">The timeout for this operation.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <param name="backupCallback">Callback to be called when the backup folder has been created locally and is ready to be moved out of the node.</param> /// <returns>Task that represents the asynchronous backup operation.</returns> /// <remarks> /// Boolean returned by the backupCallback indicate whether the service was able to successfully move the backup folder to an external location. /// If false is returned, BackupAsync throws InvalidOperationException with the relevant message indicating backupCallback returned false. /// Also, backup will be marked as unsuccessful. /// </remarks> public Task BackupAsync( BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { return(this.Replicator.BackupAsync(backupCallback, option, timeout, cancellationToken)); }
public Task BackupAsync( BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { throw new NotImplementedException(); }
/// <summary> /// Create a new <see cref="BackupMetadataFile"/> and write it to the given file. /// </summary> /// <returns>Task that represents the asynchronous operation.</returns> public static async Task <BackupMetadataFile> CreateAsync( string fileName, BackupOption backupOption, Guid parentBackupId, Guid backupId, Guid partitionId, long replicaId, Epoch startingEpoch, long startingLsn, Epoch backupEpoch, long backupLsn, CancellationToken cancellationToken) { // Create the file with asynchronous flag and 4096 cache size (C# default). // MCoskun: Default IoPriorityHint is used. // Reason: Backup is a user operation. using (var filestream = FabricFile.Open( fileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read, 4096, FileOptions.Asynchronous)) { Utility.SetIoPriorityHint(filestream.SafeFileHandle, Kernel32Types.PRIORITY_HINT.IoPriorityHintLow); var backupMetadataFile = new BackupMetadataFile(fileName); backupMetadataFile.properties = new BackupMetadataFileProperties() { BackupOption = backupOption, ParentBackupId = parentBackupId, BackupId = backupId, PartitionId = partitionId, ReplicaId = replicaId, StartingEpoch = startingEpoch, StartingLsn = startingLsn, BackupEpoch = backupEpoch, BackupLsn = backupLsn, }; // Write the properties. var propertiesHandle = await FileBlock.WriteBlockAsync(filestream, writer => backupMetadataFile.properties.Write(writer)).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); // Write the footer. backupMetadataFile.footer = new FileFooter(propertiesHandle, Version); await FileBlock.WriteBlockAsync(filestream, writer => backupMetadataFile.footer.Write(writer)).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); // Flush to underlying stream. await filestream.FlushAsync(cancellationToken).ConfigureAwait(false); return(backupMetadataFile); } }
/// <summary> /// Initializes a new instance of the <cref name="BackupInfo"/> class. /// </summary> /// <param name="directory">Folder path that contains the backup.</param> /// <param name="option"><cref name="BackupOption"/> that was used to take the backup.</param> /// <param name="version"><cref name="BackupVersion"/> of the backup.</param> /// <param name="startBackupVersion"><cref name="BackupVersion"/> of first logical log record in the backup.</param> /// <param name="backupId">Id of the backup.</param> /// <param name="parentBackupId">Id of the corresponding full backup in case of incremental backup, Guid.Empty in case this is full backup.</param> public BackupInfo(string directory, BackupOption option, BackupVersion version, BackupVersion startBackupVersion, Guid backupId, Guid parentBackupId) { this.Directory = directory; this.Option = option; this.Version = version; this.StartBackupVersion = startBackupVersion; this.BackupId = backupId; this.ParentBackupId = parentBackupId; }
/// <summary> /// Initializes a new instance of the <cref name="BackupInfo"/> class. /// </summary> /// <param name="directory">Folder path that contains the backup.</param> /// <param name="option"><cref name="BackupOption"/> that was used to take the backup.</param> /// <param name="version"><cref name="BackupVersion"/> of the backup.</param> public BackupInfo(string directory, BackupOption option, BackupVersion version) { this.Directory = directory; this.Option = option; this.Version = version; this.StartBackupVersion = BackupVersion.InvalidBackupVersion; this.BackupId = Guid.Empty; this.ParentBackupId = Guid.Empty; }
public Task BackupAsync(BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { string stateBin = Path.Combine(Path.GetTempPath(), "state.bin"); using (var fs = File.Create(stateBin)) { _store.Serialize(fs); } var info = new BackupInfo(Path.GetDirectoryName(stateBin), option, new BackupInfo.BackupVersion()); return(backupCallback(info, CancellationToken.None)); }
/// <summary> /// Creates a backup of the transactional replicator and all registered state providers. /// </summary> /// <param name="backupCallback">Method that will be called once the local backup folder has been created.</param> /// <param name="backupOption">The backup option. </param> /// <param name="timeout">The timeout for the backup.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests. </param> /// <exception cref="FabricBackupInProgressException">Backup is in progress.</exception> /// <exception cref="FabricNotPrimaryException">Replicator role is not primary.</exception> /// <exception cref="ArgumentException">backup folder path is null.</exception> /// <exception cref="ArgumentNullException">backupCallbackAsync delegate is null.</exception> /// <exception cref="OperationCanceledException">Operation has been canceled.</exception> /// <exception cref="FabricTransientException">Retriable exception.</exception> /// <exception cref="TimeoutException">Operation has timed out.</exception> /// <returns>Task that represents the asynchronous backup.</returns> internal Task <BackupInfo> BackupAsync( Func <BackupInfo, CancellationToken, Task <bool> > backupCallback, BackupOption backupOption, TimeSpan timeout, CancellationToken cancellationToken) { return(this.stateManager.LoggingReplicator.BackupAsync( backupCallback, backupOption, timeout, cancellationToken)); }
Task IStateProviderReplica.BackupAsync( BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { throw new NotImplementedException( string.Format( CultureInfo.CurrentCulture, Actors.SR.ErrorMethodNotSupported, "Backup", this.GetType())); }
Task IStateProviderReplica.BackupAsync(BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { AcquireBackupLock(); try { var backupFolderPath = GetLocalBackupFolderPath(); PrepareBackupFolder(backupFolderPath); return(storeReplica.BackupAsync(backupFolderPath, option == BackupOption.Full ? StoreBackupOption.Full : StoreBackupOption.Incremental, info => UserBackupCallbackHandler(info, backupCallback), cancellationToken)); } finally { ReleaseBackupLock(); } }
/// <inheritdoc /> public async Task <BackupMetadata> UploadBackupFolderAsync(BackupOption backupOption, Guid servicePartitionId, string sourceDirectory, CancellationToken cancellationToken) { //use folder names containing the service partition and the utc date: var timeStamp = DateTime.UtcNow; string destinationFolder = CreateDateTimeFolderName(servicePartitionId, timeStamp); //upload await CopyFolderAsync(sourceDirectory, destinationFolder, cancellationToken); //create metadata to return var info = new BackupMetadata(servicePartitionId, timeStamp, backupOption); //store the backup id. await StoreBackupMetadataAsync(destinationFolder, info); return(info); }
public override void Visit(BackupOption node) { this.action(node); }
/// <summary> /// Creates a backup of current replica. /// </summary> /// <param name="backupCallback">Backup callback to trigger at finish of Backup operation.</param> /// <param name="backupOption">The type of backup to perform.</param> /// <param name="timeout">The timeout for this operation.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>Task representing this asynchronous backup operation.</returns> public async Task BackupAsync(Func <BackupInfo, CancellationToken, Task <bool> > backupCallback, BackupOption backupOption, TimeSpan timeout, CancellationToken cancellationToken) { await this.Replicator.BackupAsync(backupCallback, backupOption, timeout, cancellationToken); }
/// <summary> /// Asynchronously starts the creation of a backup of the state of this replica and stores that into the central store. /// </summary> /// <param name="service"></param> /// <param name="backupOption"></param> /// <returns></returns> public static async Task BeginCreateBackup(this IBackupRestoreServiceInternal service, BackupOption backupOption) { var backupDescription = new BackupDescription(backupOption, service.PostBackupCallbackAsync); await service.BackupAsync(backupDescription); service.LogCallback?.Invoke($"BackupRestoreService - BeginCreateBackup for partition {service.Context.PartitionId}."); }
public void Parse(string[] args) { for (int i = 0; i < args.Length; i++) { string s = args[i]; if ((s == null) || (s.Length == 0)) { // do not process bogus args. continue; } if ((s == VaultCmdLineClientDefines.StdInParam) && (_cmd == Command.BATCH)) { items.Add(s); continue; } if (s[0] == '-') { Option option = VaultCmdLineClient.LookupOptionByString(s.Substring(1)); switch (option) { case Option.BACKUP: { if (TestForArgument(i, args.Length, s)) { string sOpt = args[++i]; switch (sOpt.ToLower()) { case "yes": case "true": this.MakeBackup = BackupOption.yes; break; case "no": case "false": this.MakeBackup = BackupOption.no; break; default: if (!Error) { Error = true; ErrorMessage = string.Format("Invalid value for -backup: {0}. Use \"yes\" or \"no\".", sOpt); } break; } } break; } case Option.BEGINDATE: { if (TestForArgument(i, args.Length, s)) { string sDate = args[++i]; try { this.HistoryBeginDate = DateTime.Parse(sDate); } catch (Exception eBegDate) { Error = true; ErrorMessage = string.Format("{0} could not be converted to a valid date: {1}", option, eBegDate.Message); } } break; } case Option.BEGINVERSION: { if (TestForArgument(i, args.Length, s)) { string sVersion = args[++i]; try { this.VersionHistoryBeginVersion = long.Parse(sVersion); } catch (Exception e) { Error = true; ErrorMessage = string.Format("{0} could not be converted to a valid numeric version number: {1}", option, e.Message); } } break; } case Option.BEGINLABEL: { if (TestForArgument(i, args.Length, s)) { HistoryBeginLabel = args[++i]; } break; } case Option.COMMENT: { if (TestForArgument(i, args.Length, s)) { _comment = args[++i]; } break; } case Option.COMMIT: { AutoCommit = true; break; } case Option.COMPARETO: { if (TestForArgument(i, args.Length, s)) { _strDiffCompareTo = args[++i]; } break; } case Option.DATESORT: if (TestForArgument(i, args.Length, s)) { DateSort = VaultCmdLineClient.LookupDateSortOptionByString(args[++i]); } break; case Option.DESTFOLDER: { if (TestForArgument(i, args.Length, s)) { DestPath = args[++i]; } break; } case Option.LABELWORKINGFOLDER: { if (TestForArgument(i, args.Length, s)) { LabelWorkingFolder = args[++i]; } break; } case Option.DESTPATH: { if (TestForArgument(i, args.Length, s)) { DestPath = args[++i]; } break; } case Option.ENDDATE: { if (TestForArgument(i, args.Length, s)) { string sDate = args[++i]; try { this.HistoryEndDate = DateTime.Parse(sDate); } catch (Exception eEndDate) { Error = true; ErrorMessage = string.Format("{0} could not be converted to a valid date: {1}", option, eEndDate.Message); } } break; } case Option.ENDLABEL: { if (TestForArgument(i, args.Length, s)) { HistoryEndLabel = args[++i]; } break; } case Option.EXCLUDEACTIONS: { if (TestForArgument(i, args.Length, s)) { HistoryExcludedActions = args[++i]; } break; } case Option.EXCLUDEUSERS: { if (TestForArgument(i, args.Length, s)) { HistoryExcludedUsers = args[++i]; } break; } case Option.EXCLUSIVE: { CheckOutExclusive = true; break; } case Option.SERVER: case Option.HOST: { if (TestForArgument(i, args.Length, s)) { _host = args[++i]; } break; } case Option.KEEPCHECKEDOUT: { _bKeepCheckedOut = true; break; } case Option.LEAVEFILE: { LocalCopy = LocalCopyType.Leave; break; } case Option.MAKEWRITABLE: { MakeWritable = MakeWritableType.MakeAllFilesWritable; break; } case Option.MAKEREADONLY: { MakeWritable = MakeWritableType.MakeAllFilesReadOnly; break; } case Option.MERGE: { if (TestForArgument(i, args.Length, s)) { string strOpt = args[++i]; MergeOption mo = VaultCmdLineClient.LookupMergeOptionByString(strOpt); switch (mo) { case MergeOption.auto: case MergeOption.automatic: case MergeOption.automerge: Merge = MergeType.AttemptAutomaticMerge; break; case MergeOption.later: case MergeOption.mergelater: case MergeOption.no_overwrite: Merge = MergeType.MergeLater; break; case MergeOption.overwrite: Merge = MergeType.OverwriteWorkingCopy; break; default: if (Error == false) { Error = true; ErrorMessage = string.Format("Invalid value for -{0}: {1}", Option.MERGE, strOpt); } break; } } break; } case Option.NOCLOAKS: { this.RespectCloaks = false; break; } case Option.NORECURSIVE: { this.Recursive = false; break; } case Option.NOSSL: { _ssl = false; break; } case Option.OUT: { if (TestForArgument(i, args.Length, s)) { string sName = args[++i]; this.OutFile = sName; } break; } case Option.PASSWORD: { if (TestForArgument(i, args.Length, s)) { _password = args[++i]; } break; } case Option.PERFORMDELETIONS: { if (TestForArgument(i, args.Length, s)) { PerformDeletions = VaultCmdLineClient.LookupPerformDeletionsOptionByString(args[++i]); } break; } case Option.PROXYSERVER: { if (TestForArgument(i, args.Length, s)) { _proxyServer = args[++i]; } break; } case Option.PROXYPORT: { if (TestForArgument(i, args.Length, s)) { _proxyPort = args[++i]; } break; } case Option.PROXYUSER: { if (TestForArgument(i, args.Length, s)) { _proxyUser = args[++i]; } break; } case Option.PROXYPASSWORD: { if (TestForArgument(i, args.Length, s)) { _proxyPassword = args[++i]; } break; } case Option.PROXYDOMAIN: { if (TestForArgument(i, args.Length, s)) { _proxyDomain = args[++i]; } break; } case Option.REPOSITORY: { if (TestForArgument(i, args.Length, s)) { _repository = args[++i]; } break; } case Option.REQUIRECHECKOUT: { RequireCheckOut = true; break; } case Option.REVERTFILE: { LocalCopy = LocalCopyType.Replace; break; } case Option.ROWLIMIT: { if (TestForArgument(i, args.Length, s)) { string sInt = args[++i]; try { HistoryRowLimit = Int32.Parse(sInt); } catch (Exception) { } } break; } case Option.SETFILETIME: { if (TestForArgument(i, args.Length, s)) { string strOpt = args[++i]; FileTimeOption fto = VaultCmdLineClient.LookupFileTimeOptionByString(strOpt); switch (fto) { case FileTimeOption.current: this.SetFileTime = SetFileTimeType.Current; break; case FileTimeOption.checkin: this.SetFileTime = SetFileTimeType.CheckIn; break; case FileTimeOption.modification: case FileTimeOption.modified: this.SetFileTime = SetFileTimeType.Modification; break; default: if (!Error) { Error = true; ErrorMessage = string.Format("Invalid value for -setfiletime: {0}", strOpt); } break; } } break; } case Option.SSL: { _ssl = true; break; } case Option.UNCHANGED: { if (TestForArgument(i, args.Length, s)) { string sOpt = args[++i]; switch (sOpt.ToLower()) { case "leavecheckedout": this.Unchanged = UnchangedHandler.LeaveCheckedOut; break; case "undocheckout": this.Unchanged = UnchangedHandler.UndoCheckout; break; case "checkin": this.Unchanged = UnchangedHandler.Checkin; break; default: if (!Error) { Error = true; ErrorMessage = string.Format("Invalid value for -unchanged: {0}", sOpt); } break; } } break; } case Option.URL: { if (TestForArgument(i, args.Length, s)) { _url = args[++i]; } break; } case Option.USERNAME: case Option.USER: { if (TestForArgument(i, args.Length, s)) { _user = args[++i]; } break; } case Option.VAULTDIFF: { if (TestForArgument(i, args.Length, s)) { _strDiffBin = args[++i]; } break; } case Option.VAULTDIFF_OPTIONS: { if (TestForArgument(i, args.Length, s)) { _strDiffArgs = args[++i]; } break; } case Option.WILDCARD: { if (TestForArgument(i, args.Length, s)) { Wildcard = args[++i]; } break; } case Option.VERBOSE: { Verbose = true; break; } case Option.YESIAMSURE: { _yesiamsure = true; break; } default: { if (!Error) { Error = true; ErrorMessage = string.Format("unknown option: {0} - run 'vault.exe HELP' for help", s); } break; } } } else { if (!checkForCommand(s)) { if ( (s[0] == VaultDefine.RootName[0]) && (s.EndsWith(VaultDefine.PathSeparator.ToString())) ) { s = RepositoryPath.NormalizeFolder(s); } else if (s == VaultDefine.RootName) { s = RepositoryPath.NormalizeFolder(s); } items.Add(s); } } } }
//maybe add file hashes? /// <summary> /// Creates a new instance using the provided arguments. /// </summary> /// <param name="originalServicePartitionId">Indicates the Stateful Service Parition Guid that the backup was created for.</param> /// <param name="timeStampUtc">Indicates when the backup was created.</param> /// <param name="backupOption">Indicates the type of backup.</param> public BackupMetadata(Guid originalServicePartitionId, DateTime timeStampUtc, BackupOption backupOption) : this(originalServicePartitionId, timeStampUtc, backupOption, Guid.NewGuid()) { }
/// <inheritdoc /> public Task BeginCreateBackup(BackupOption backupOption) { return(BackupRestoreServiceOperations.BeginCreateBackup(this, backupOption)); }
/// <inheritdoc /> public Task BeginCreateBackup(BackupOption backupOption) { return(BackupRestoreServiceInternalExtensions.BeginCreateBackup(this, backupOption)); }
public Task BackupAsync(BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func<BackupInfo, CancellationToken, Task<bool>> backupCallback) { return _innerStateProvider.BackupAsync(option, timeout, cancellationToken, backupCallback); }
Task IStateProviderReplica.BackupAsync(BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { return(SpecialTasks.True); }
public Task BackupAsync(BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) => Task.CompletedTask;
public FileBackupMetadata(string relativeFolder, Guid originalServicePartitionId, DateTime timeStampUtc, BackupOption backupOption, Guid backupId) : base(originalServicePartitionId, timeStampUtc, backupOption, backupId) { if (string.IsNullOrWhiteSpace(relativeFolder)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(relativeFolder)); } RelativeFolder = relativeFolder; }
/// <summary> /// Asynchronously starts the creation of a backup of the state of this replica and stores that into the central store. /// This method completes and returns before the backup process is completely done. /// </summary> /// <param name="service"></param> /// <param name="backupOption"></param> /// <returns></returns> public static async Task BeginCreateBackup(this IBackupRestoreServiceOperations service, BackupOption backupOption) { try { var backupDescription = new BackupDescription(backupOption, service.PostBackupCallbackAsync); await service.BackupAsync(backupDescription); } catch (Exception ex) { string message = $"Failed to create backup information for partition {service.Context.PartitionId}"; service.LogCallback?.Invoke($"{nameof(BackupRestoreServiceOperations)} - {nameof(BeginCreateBackup)} failed for partition: {service.Context.PartitionId}. Message:{message} - Error: {ex.Message}"); throw new Exception(message, ex); } service.LogCallback?.Invoke($"{nameof(BackupRestoreServiceOperations)} - {nameof(BeginCreateBackup)} succeeded for partition {service.Context.PartitionId}."); }
public BlobBackupMetadata(BlobStorageUri blockBlobUri, Guid originalServicePartitionId, DateTime timeStampUtc, BackupOption backupOption, Guid backupId) : base(originalServicePartitionId, timeStampUtc, backupOption, backupId) { BlockBlobUri = blockBlobUri ?? throw new ArgumentNullException(nameof(blockBlobUri)); }
public override void ExplicitVisit(BackupOption fragment) { _fragments.Add(fragment); }
/// <summary> /// Takes a backup of the current state of Reliable Collections. /// </summary> /// <param name="backupOption">The type of backup to perform.</param> /// <param name="timeout">The timeout for this operation.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <param name="backupCallback">Callback to be called when the backup folder has been created locally and is ready to be moved out of the node.</param> /// <returns>Task that represents the asynchronous backup operation.</returns> public async Task BackupAsync(BackupOption backupOption, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { log.Info("Parser BackupAsync Call"); await this.backupParserImpl.BackupAsync(backupCallback, backupOption, timeout, cancellationToken); }
/// <inheritdoc /> public Task BackupAsync(BackupOption option, TimeSpan timeout, CancellationToken cancellationToken, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { // TODO return(Task.FromResult(0)); }
/// <summary> /// Initializes a new instance of the <cref name="BackupDescription"/> structure. /// </summary> /// <param name="option"> /// The <cref name="BackupOption"/> for the backup. /// </param> /// <param name="backupCallback"> /// Callback to be called when the backup folder has been created locally and is ready to be moved out of the node. /// </param> public BackupDescription(BackupOption option, Func <BackupInfo, CancellationToken, Task <bool> > backupCallback) { this.option = option; this.backupCallback = backupCallback; }