A comprehensive set of bash scripts to export, compare, and migrate configurations and saved objects between Elasticsearch/Kibana environments (on-premises to cloud).
elastic-exporter.sh- Exports configurations and saved objects from both local and cloud environmentscompare.sh- Compares exported configurations between environmentsmigrationv.sh- Migrates resources by creating new objects (non-destructive approach)
jqinstalled on your systemcurlfor API requests- Environment variables configured (see setup below)
Set the following environment variables in your shell:
# API Keys
export OAPI_KEY=REDACTED_API_KEY
export CAPI_KEY="your_cloud_api_key"
# Elasticsearch URLs
export LOCAL_ES_URL="https://your-local-elasticsearch:9200"
export CLOUD_ES_URL="https://your-cloud-elasticsearch:9200"
# Kibana URLs
export LOCAL_KIBANA="https://your-local-kibana:5601"
export CLOUD_KIBANA="https://your-cloud-kibana:5601"-
Export configurations from both environments:
./elastic-exporter.sh
-
Compare the exported configurations:
./compare.sh
-
Migrate resources to cloud (creates new objects):
./migrationv.sh all
Full Export (Recommended):
./elastic-exporter.shExports all resources from both environments to a timestamped directory.
Direct API Calls:
# Elasticsearch API calls
./elastic-exporter.sh es <env> <method> <endpoint> [data]
# Kibana API calls
./elastic-exporter.sh kb <env> <method> <endpoint> [data]
# Export saved objects only
./elastic-exporter.sh saved-objects <env>Examples:
./elastic-exporter.sh es local GET _cluster/health
./elastic-exporter.sh kb cloud GET api/spaces/space
./elastic-exporter.sh saved-objects local
./elastic-exporter.sh helpBasic Usage:
./compare.shAutomatically finds the latest export folder and compares all resources.
Specify Export Directory:
./compare.sh dir ./elastic_export_20250624_143022Migrate All Resources:
./migrationv.sh allMigrate Specific Resource Types:
./migrationv.sh ilm # ILM policies
./migrationv.sh pipelines # Logstash pipelines
./migrationv.sh templates # Index templates
./migrationv.sh roles # Security roles
./migrationv.sh spaces # Kibana spaces
./migrationv.sh objects # Saved objects
./migrationv.sh settings # Cluster settings (selective)Specify Export Directory:
./migrationv.sh dir ./elastic_export_20250624_143022 ilmMultiple Resource Types:
./migrationv.sh spaces objects templates- Cluster settings - Persistent and transient cluster configurations
- ILM policies - Index Lifecycle Management policies
- Index templates - Index and component templates
- Security roles - Role-based access control definitions
- Snapshot repositories - Backup repository configurations
- Logstash pipelines - Central pipeline management configurations
- Spaces configuration - Kibana space definitions
- Saved objects - Dashboards, visualizations, index patterns, searches, etc.
- Exported per space for granular control
- Includes all object types and dependencies
elastic_export_YYYYMMDD_HHMMSS/
├── es_resources/
│ ├── local/
│ │ ├── cluster_settings.json
│ │ ├── ilm_policy.json
│ │ ├── index_templates.json
│ │ ├── security_roles.json
│ │ ├── snapshot_repositories.json
│ │ └── logstash_pipelines.json
│ └── cloud/
│ └── [same structure as local/]
├── kibana/
│ ├── local/
│ │ └── kibana_spaces.json
│ └── cloud/
│ └── kibana_spaces.json
├── local_saved_objects/
│ ├── local_kibana_space_default_export.ndjson
│ └── local_kibana_space_[space_name]_export.ndjson
└── cloud_saved_objects/
├── cloud_kibana_space_default_export.ndjson
└── cloud_kibana_space_[space_name]_export.ndjson
The compare.sh script provides detailed analysis:
- ✅ Green: Resources exist in both environments
- ❌ Red: Resources missing in cloud (need migration)
⚠️ Yellow: Resources only in cloud (not in local)- Detailed diffs for complex resources like templates and pipelines
- Per-space comparison for Kibana saved objects
- Object count summaries for each space
The migrationv.sh script uses a non-destructive approach:
- Creates new objects with prefixed names:
migrated_YYYYMMDD_HHMMSS_[original_name] - Preserves existing cloud resources
- Allows safe rollback if needed
- Updates references between objects automatically
- Analysis Phase: Compares local vs cloud resources
- Planning Phase: Shows what will be created/modified
- Confirmation: Requires user approval before changes
- Execution Phase: Creates new resources with updated names
- Verification: Confirms successful creation
- Choose specific resource types to migrate
- Interactive cluster settings selection (safety feature)
- Skip built-in/system resources automatically
- Handle missing dependencies gracefully
- Automatically skips system resources (e.g.,
.monitoring-*,kibana_system) - Warns about potentially dangerous cluster settings
- Requires explicit confirmation for destructive operations
- Validates API connectivity before operations
- Provides detailed error messages with suggestions
- Graceful handling of missing resources or permissions
- Rollback capabilities for failed migrations
- Success/failure detection for all operations
- Post-creation verification by fetching created resources
- Detailed logging of all operations
API Key Authentication:
# Test your API keys
curl -H "Authorization: ApiKey $CAPI_KEY" "$CLOUD_ES_URL/_cluster/health"Missing Dependencies:
# Install jq on Ubuntu/Debian
sudo apt-get install jq
# Install jq on macOS
brew install jqPermission Issues:
# Make scripts executable
chmod +x elastic-exporter.sh compare.sh migrationv.shAdd set -x to the beginning of any script for detailed execution logging.
- Test in non-production environment first
- Backup your cloud environment
- Review comparison results carefully
- Start with less critical resources (e.g., spaces before objects)
- Migrate incrementally - one resource type at a time
- Verify each step before proceeding
- Keep export timestamps for reference
- Document any custom modifications needed
- Test migrated objects functionality
- Update references in applications if needed
- Monitor performance impact
- Clean up unused resources when confident
Modify the scripts to add custom filtering logic for your specific use case.
Use the individual migration functions for automated batch processing.
Scripts can be integrated into deployment pipelines for consistent environment management.
Feel free to submit issues, feature requests, or pull requests to improve these scripts.