예제 #1
0
        // </snippet_RestoreFileFromSnapshot>

        // <snippet_DeleteSnapshot>
        //-------------------------------------------------
        // Delete a snapshot
        //-------------------------------------------------
        public async Task DeleteSnapshotAsync(string shareName, string snapshotTime)
        {
            // Get the connection string from app settings
            string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            // Instatiate a ShareServiceClient
            ShareServiceClient shareService = new ShareServiceClient(connectionString);

            // Get a ShareClient
            ShareClient share = shareService.GetShareClient(shareName);

            // Get a ShareClient that points to a snapshot
            ShareClient snapshotShare = share.WithSnapshot(snapshotTime);

            try
            {
                // Delete the snapshot
                await snapshotShare.DeleteIfExistsAsync();
            }
            catch (RequestFailedException ex)
            {
                Console.WriteLine($"Exception: {ex.Message}");
                Console.WriteLine($"Error code: {ex.Status}\t{ex.ErrorCode}");
            }
        }
        // <snippet_RestoreFileFromSnapshot>
        //-------------------------------------------------
        // Restore file from snapshot
        //-------------------------------------------------
        public async Task RestoreFileFromSnapshot(string shareName, string directoryName, string fileName, string snapshotTime)
        {
            // Get the connection string from app settings
            string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            // Instatiate a ShareServiceClient
            ShareServiceClient shareService = new ShareServiceClient(connectionString);

            // Get a ShareClient
            ShareClient share = shareService.GetShareClient(shareName);

            // Get a ShareDirectoryClient, then a ShareFileClient to the live file
            ShareDirectoryClient liveDir  = share.GetDirectoryClient(directoryName);
            ShareFileClient      liveFile = liveDir.GetFileClient(fileName);

            // Get as ShareClient that points to a snapshot
            ShareClient snapshot = share.WithSnapshot(snapshotTime);

            // Get a ShareDirectoryClient, then a ShareFileClient to the snapshot file
            ShareDirectoryClient snapshotDir  = snapshot.GetDirectoryClient(directoryName);
            ShareFileClient      snapshotFile = snapshotDir.GetFileClient(fileName);

            // Restore the file from the snapshot
            ShareFileCopyInfo copyInfo = await liveFile.StartCopyAsync(snapshotFile.Uri);

            // Display the status of the operation
            Console.WriteLine($"Restore status: {copyInfo.CopyStatus}");
        }
        // </snippet_RestoreFileFromSnapshot>
        //Uri snapshotFileUri = GetFileSasUri(shareName, snapshotDir.Name + "/" + snapshotFile.Name, DateTime.UtcNow.AddHours(24), ShareFileSasPermissions.Read);

        // <snippet_DeleteSnapshot>
        //-------------------------------------------------
        // Delete a snapshot
        //-------------------------------------------------
        public async Task DeleteSnapshotAsync(string shareName, string snapshotTime)
        {
            // Get the connection string from app settings
            string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            // Instatiate a ShareServiceClient
            ShareServiceClient shareService = new ShareServiceClient(connectionString);

            // Get a ShareClient
            ShareClient share = shareService.GetShareClient(shareName);

            // Get as ShareClient that points to a snapshot
            ShareClient snapshot = share.WithSnapshot(snapshotTime);

            // This deletes the whole share, not just the snapshot
            await snapshot.DeleteIfExistsAsync();
        }
예제 #4
0
        // <snippet_ListSnapshotContents>
        //-------------------------------------------------
        // List the snapshots on a share
        //-------------------------------------------------
        public void ListSnapshotContents(string shareName, string snapshotTime)
        {
            // Get the connection string from app settings
            string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            // Instatiate a ShareServiceClient
            ShareServiceClient shareService = new ShareServiceClient(connectionString);

            // Get a ShareClient
            ShareClient share = shareService.GetShareClient(shareName);

            Console.WriteLine($"Share: {share.Name}");

            // Get as ShareClient that points to a snapshot
            ShareClient snapshot = share.WithSnapshot(snapshotTime);

            // Get the root directory in the snapshot share
            ShareDirectoryClient rootDir = snapshot.GetRootDirectoryClient();

            // Recursively list the directory tree
            ListDirTree(rootDir);
        }