Snapshots are crucial for data backup and disaster recovery in Amazon OpenSearch Service. These snapshots allow you to generate backups of your domain indexes and cluster state at specific moments and save them in a reliable storage location such as Amazon Simple Storage Service (Amazon S3).
Snapshots play a critical role in providing the availability, integrity and ability to recover data in OpenSearch Service domains. By implementing a robust snapshot strategy, you can mitigate risks associated with data loss, streamline disaster recovery processes and maintain compliance with data management best practices.
This post provides a detailed walkthrough about how to efficiently capture and manage manual snapshots in OpenSearch Service. It covers the essential steps for taking snapshots of your data, implementing safe transfer across different AWS Regions and accounts, and restoring them in a new domain. This guide is designed to help you maintain data integrity and continuity while navigating complex multi-Region and multi-account environments in OpenSearch Service.
Refer to this developer guide to understand more about index snapshots
Understanding manual snapshots
Manual snapshots are point-in-time backups of your OpenSearch Service domain that are initiated by the user. Contrary to automated snapshots, which are taken on a regular basis in accordance with the specified retention policy by OpenSearch Service, manual snapshots give you the ability to take backups whenever required, whether for the full cluster or for individual indices. This is particularly useful when you want to preserve a specific state of your data for future reference or before implementing significant changes to your domain.
Snapshots are not instantaneous. They take time to complete and don’t represent perfect point-in-time views of the domain. While a snapshot is in progress, you can still index documents and make other requests to the domain, but new documents and updates to existing documents generally aren’t included in the snapshot. The snapshot includes primary shards as they existed when you initiate the snapshot process.
The following are some scenarios where manual snapshots play an important role:
- Data recovery – The primary purpose of snapshots, whether manual or automated, is to provide a means of data recovery in the event of a failure or data loss. If something goes wrong with your domain, you can restore it to a previous state using a snapshot.
- Migration – Manual snapshots can be useful when you want to migrate data from one domain to another. You can create a snapshot of the source domain and then restore it on the target domain.
- Testing and development – You can use snapshots to create copies of your data for testing or development purposes. This allows you to experiment with your data without affecting the production environment.
- Backup control – Manual snapshots give you more control over your backup process. You can choose exactly when to create a snapshot, which can be useful if you have specific requirements that are not met by automated snapshots.
- Long-term archiving – Manual snapshots can be kept for as long as you want, which can be useful for long-term archiving of data. Automated snapshots, on the other hand, are often deleted after a certain period of time.
Solution overview
The following sections outline the procedure for taking a manual snapshot and then restoring it in a different domain, spanning across various Regions and accounts. The high-level steps are as follows:
- Create an AWS Identity and Access Management (IAM) role and user.
- Register a manual snapshot repository.
- Take manual snapshots.
- Set up S3 bucket replication.
- Create an IAM role and user in the target account.
- Add a bucket policy.
- Register the repository and restore snapshots in the target domain.
Prerequisite
This post assumes you have the following resources set up:
- An active and running OpenSearch Service domain.
- An S3 bucket to store the manual snapshots of your OpenSearch Service domain. The bucket has to be in the same Region where the OpenSearch Service domain is hosted.
Create an IAM role and user
Complete the following steps to create your IAM role and user:
- Create an IAM role to grant permissions to OpenSearch Service. For this post, we name the role
TheSnapshotRole
. - Create a new policy using the following code and attach it to the role to allow access to the S3 bucket.
- Edit the trust relationship of
TheSnapshotRole
to specify OpenSearch Service in thePrincipal
statement, as shown in the following example. Under theCondition
block, we recommend that you use theaws:SourceAccount
andaws:SourceArn
condition keys to protect yourself against the confused deputy problem. The source account is the owner and the source ARN is the ARN of the OpenSearch Service domain.
- Generate an IAM user to register the snapshot repository. For this post, we name the user
TheSnapUser
. - To register a snapshot repository, you need to pass
TheSnapshotRole
to OpenSearch Service. You also need access to thees:ESHttpPut
To grant both of these permissions, attach the following policy to the IAM role whose credentials are being used to sign the request.
Register a manual snapshot repository
Complete the following steps to map the snapshot role and the user in OpenSearch Dashboards (if using fine-grained access control):
- Navigate to the OpenSearch Dashboards endpoint connected to your OpenSearch Service domain.
- Sign in with the admin user or a user with the
security_manager
role - From the main menu, choose Security, Roles, and select the
manage_snapshots
role - Choose Mapped users, then choose Manage mapping.
- Add the ARN of
TheSnapshotRole
for Backend role and the ARN ofTheSnapUser
for User:arn:aws:iam::123456789123:role/TheSnapshotRole
arn:aws:iam::123456789123:user/TheSnapUser
- Choose Map and confirm the user and role shows up under Mapped users.
- To register a snapshot repository, send a PUT request to the OpenSearch Service domain endpoint through an API platform like Postman or Insomnia. For more details, see Registering a manual snapshot repository.
Note: While using Postman or Insomnia to run the API calls mentioned throughout this blog, choose AWS IAM v4 as the authentication method and input your IAM credentials in the Authorization section. Ensure you use the credentials of an OpenSearch user who has the ‘all_access’ OpenSearch role assigned on the domain.
If your domain resides within a virtual private cloud (VPC), you must be connected to the VPC for the request to successfully register the snapshot repository. Accessing a VPC varies by network configuration, but likely involves connecting to a VPN or corporate network. To check that you can reach the OpenSearch Service domain, navigate to https://
in a web browser and verify that you receive the default JSON response.
Take manual snapshots
Taking a snapshot isn’t possible if another snapshot is currently in progress. The Ultrawarm storage tier migration process also utilizes snapshots to move data between hot and warm storage, running this process in the background. Additionally, automated snapshots are taken based on the schedule configured for the cluster by the service. See Protecting data with encryption for protecting your Amazon S3 data.
- To verify, run the following command
- After you confirm no snapshot is running, run the following command to take a manual snapshot
- Run the following command to verify the state of all snapshots of your domain
Set up S3 bucket replication
Before you start, have the following in place:
- Locate the destination bucket where the data will be replicated. If you don’t have one, create a new S3 bucket in a distinct region, separate from the region of the source bucket.
- To allow access to objects in this bucket by other AWS accounts (because the destination OpenSearch Service domain is in a different account), you need to enable access control lists (ACLs) on the bucket. ACLs will be used to specify and manage access permissions for the bucket and its objects.
Complete the following steps to set up S3 bucket replication. For more information, see Walkthroughs: Examples for configuring replication.
- On the Amazon S3 console, choose Buckets in the navigation pane.
- Choose the bucket you want to replicate (the source bucket with snapshots).
- On the Management tab, choose Create replication rule.
- Replication requires versioning to be enabled for the source bucket, so choose Enable bucket versioning and enable versioning.
- Specify the following details:
- For Rule ID, enter a name for your rule.
- For Status, choose Enabled.
- For Rule scope, specify the data to be replicated.
- For Destination S3 bucket, enter the target bucket name where the data will be replicated.
- For IAM role, choose Create new role.
- Choose Save.
- In the Replicate existing objects pop-up window, select Yes, replicate existing objects to start replication.
- Choose Submit.
You will see a new active replication rule in the replication table on the Management tab of the source S3 bucket.
Create an IAM role and user in the target account
Complete the following steps to create your IAM role and user in the target account.
- Create an IAM role to grant permissions to the target OpenSearch Service. For this post, name the role
DestinationSnapshotRole
. - Create a new policy using the following code and attach it to the role
DestinationSnapshotRole
to allow access to the target S3 bucket
- Edit the trust relationship of
DestinationSnapshotRole
to specify OpenSearch Service in thePrincipal
statement as shown in the following example.
- Generate an IAM user to register the snapshot repository. For this post, name the user
DestinationSnapUser
. - To register a snapshot repository, you need to pass
DestinationSnapshotRole
to OpenSearch Service. You also need access to thees:ESHttpPut
To grant both of these permissions, attach the following policy to the IAM role whose credentials are being used to sign the request
Complete the following steps to map the snapshot role and user in the target OpenSearch Dashboards (if using fine-grained access control).
- Navigate to the OpenSearch Dashboard’s endpoint connected with your OpenSearch Service domain.
- Sign in with the admin user or a user with the
security_manager
role - From the main menu, choose Security, Roles, and choose the
manage_snapshots
role - Choose Mapped users, then choose Manage mapping.
- Add the ARN of
TheSnapshotRole
for Backend role and the ARN ofTheSnapUser
for User:arn:aws:iam::123456789123:role/DestinationSnapshotRole
arn:aws:iam::123456789123:user/DestinationSnapUser
- Choose Map and confirm the user and role shows up under Mapped users.
Add a bucket policy
In the destination S3 bucket details page, on the Permissions tab, choose Edit, then add the following bucket policy. This policy allows the target OpenSearch Service domain from another AWS account to access the snapshot created by a different AWS account.
Register the repository and restore snapshots in the target domain
To complete this step, you need an active and running OpenSearch Service domain in the target account.
Identify the snapshot you want to restore. Make sure all settings for this index, such as custom analyzer packages or allocation requirement settings, and data are compatible with the domain. Then complete the following steps
- To register the repository in the target OpenSearch Service domain, run the following command.
- After you register the repository, run the following command to see all snapshots.
- To restore a snapshot, run the following command.
- Alternately, you might want to restore all indexes except the dashboards and fine-grained access control indexes.
- Sign in to OpenSearch Dashboards connected to the target OpenSearch Service domain and run the following command to check if the data is getting restored.
- Run the following recovery command to check the progress of the restore operation.
Troubleshooting
This re:Post article addresses the majority of common errors that arise when attempting to restore a manual snapshot, along with effective solutions to resolve them.
Conclusion
In this post, we presented a procedure for taking manual snapshots and restoring them in OpenSearch Service. With manual snapshots, you have the power to manage your data backups, preserving key moments in time, confidently experimenting with domain modifications, and protecting against any data loss. Additionally, being able to restore snapshots across various domains, Regions, and accounts enables a new degree of data portability and flexibility, giving you the freedom to better manage and optimize your domains.
With great data protection comes great innovation. Now that you’re equipped with this knowledge, you can explore the endless possibilities that OpenSearch Service offers, confident in your ability to secure, restore, and thrive in the dynamic world of cloud-based data analytics and management.
See blog post to understand how to use snapshot management policies to manage automated snapshot in OpenSearch Service.
If you have feedback about this post, submit it in the comments section. If you have questions about this post, start a new thread on the Amazon OpenSearch Service forum or contact AWS Support.
Stay tuned for more exciting updates and new features in Amazon OpenSearch Service.
About the authors
Madhan Kumar Baskaran works as a Search Engineer at AWS, specializing in Amazon OpenSearch Service. His primary focus involves assisting customers in constructing scalable search applications and analytics solutions. Based in Bellevue, Washington, Madhan has a keen interest in data engineering and DevOps.
Priyanshi Omer is a Customer Success Engineer at AWS OpenSearch, based in Bengaluru. Her primary focus involves assisting customers in constructing scalable search applications and analytics solutions. She works closely with customers to help them migrate their workloads and aids existing customers in fine-tuning their clusters to achieve better performance and cost savings. Outside of work, she enjoys spending time with her cats and playing video games