/// <summary> /// Releases the resources associated with the backup /// </summary> public void Dispose() { if (this.uploader != null) this.uploader.Dispose(); this.uploader = null; }
/// <summary> /// Adds a file to the archive /// </summary> /// <param name="entry"> /// The backup metadata for the file /// </param> /// <param name="stream"> /// The file stream to add to the archive /// </param> public void Backup(Backup.Entry entry, Stream stream) { // if we are not currently uploading a vault archive, // then attach a new uploader and create a blob for it if (this.uploader == null) { this.uploader = new GlacierUploader( this.archive.Glacier, this.archive.Vault ); this.archive.BackupIndex.InsertBlob( new Backup.Blob() { Name = this.uploader.UploadID } ); } // fetch the upload blob and sync it with the uploader's offset var blob = this.archive.BackupIndex.LookupBlob(this.uploader.UploadID); if (blob.Length != this.uploader.Length) blob.Length = this.uploader.Resync(blob.Length); // upload the incoming stream and update the backup entry var offset = this.uploader.Length; var length = this.uploader.Upload(stream); entry.Blob = blob; entry.Offset = offset; entry.Length = length; }
/// <summary> /// Commits the current vault archive to Glacier /// </summary> public void Checkpoint() { if (this.uploader != null) { // complete the vault archive and update the blob var blob = this.archive.BackupIndex.LookupBlob(this.uploader.UploadID); this.uploader.Flush(); blob.Length = this.uploader.Length; var archiveID = this.uploader.Complete(); blob.Name = archiveID; this.archive.BackupIndex.UpdateBlob(blob); // detach the uploader for the current vault archive this.uploader.Dispose(); this.uploader = null; } this.archive.Save(); }