Ranger Import and Export Configurations
Ranger import and export bootstrap helper functions exist to import and export Ranger configurations.
Ranger import and export bootstrap helper functions are useful for cluster resiliency, recovery operations, and moving Ranger policies from one cluster to another and are helpful in several scenarios.
- Disaster Recovery
- Create a new cluster and using the
import_ranger_policies
helper function, you can import all the Ranger policies present in an old cluster to a new cluster. - Testing or Development Environments
- To create a testing or development environment using any existing cluster Ranger policies, you can use the
export_ranger_policies
helper function to export all the Ranger policies present at the source cluster to a JSON file. Using theimport_ranger_policies
helper function, you can import all the policies to a destination cluster.
To perform Ranger import and export operations, Ambari and Ranger admin credentials must be same.
To execute a bootstrap script, see Running the Bootstrap Script.
For more information on the Ranger import and export helper functions, see:
Ranger Import and Export Helper Functions
For more information Ranger import and export bootstrap script configurations, see Ranger Import and Export Configurations.
For Ranger import and export helper function examples, see Ranger Import and Export Configuration Examples.
To execute a bootstrap script, see Running the Bootstrap Script.
Helper Function | Functionality |
---|---|
export_ranger_policies (ranger_config_dict) |
This helper function exports ranger policies in multiple formats. (JSON, CSV, EXCEL). But only JSON format is supported for Example:
Ranger-Export-Config-Info:
Optional Parameters:
When the bootstrap-script job to export Ranger policies is successful, Ranger exports policies in a specified format file at the output_folder_path location. |
import_ranger_policies (ranger_config_dict) |
This helper function imports Ranger policies using provided JSON input file. You can create and pass Example: ranger_config_dict = { "input_file_path": "/tmp/Ranger_policies.json", # Mandatory param for import operation "service_list": "hdfs, kafka" # optional param } Ranger-Import-Config-Info: input_file_path : The path to Ranger_policies.json file, created by the Ranger-policy-export function on the source cluster. The exported JSON file can be placed either in the target cluster local path or in the Object Store location.(PAR URL)Optional Parameters:
When the bootstrap-script job to import Ranger policies is successful, Ranger imports polices from the provided |
restore_ranger_policies (ranger_config_dict) |
This helper function restores Ranger policies using backup file. You can pass which backup file to use to restore Ranger policies. By default this function restores Ranger policies using latest backup file present in the backup files directory. You can create and pass Example
Ranger-Restore-Config-Info: restore_policies_input_file_path: An optional parameter, When the bootstrap-script job to restore Ranger policies is successful, Ranger restores polices using the provided |
cleanup_ranger_policy_backup_files (ranger_config_dict) |
This helper function deletes Ranger policy backup files using file-list or pattern. You can create and pass the Example:
Ranger-Policy-Cleanup-Config-Info:
Example:
|
Ranger Import and Export Configuration Examples
For more information on the Ranger import and export helper functions, see Ranger Import and Export Helper Functions.
#!/usr/bin/env python2.7
def execute(ranger_policy_helper):
logger = ranger_policy_helper.getLogger()
logger.info('Testing Ranger export-import functions')
ranger_config_dict = {
"input_file_path": "<Ranger_Policies.json_input_filepath>", # Mandatory param, Input file to import policies.
"service_list": "hdfs,hive" # Optional param, imports policies only from hdfs and hive services.
}
ranger_policy_helper.import_ranger_policies(ranger_config_dict)
#!/usr/bin/env python2.7
def execute(ranger_policy_helper):
logger = ranger_policy_helper.getLogger()
logger.info('Testing Ranger export-import functions')
ranger_config_dict = {
"output_folder_path": "/tmp", # Mandatory param, exports output file to /tmp folder
"service_list": "hdfs,hive" # Optional param, exports policies only from hdfs and hive services.
}
ranger_policy_helper.export_ranger_policies(ranger_config_dict)
#!/usr/bin/env python2.7
def execute(ranger_policy_helper):
logger = ranger_policy_helper.getLogger()
logger.info('Testing Ranger export-import functions')
# Restores Ranger policies from the provided input file. If User don't provide this param, restore-function restores Ranger policies using latest backup file present in the backup files directory.
ranger_config_dict = {
"restore_policies_input_file_path": "/tmp/Ranger_Policies.json" # Optional param
}
ranger_policy_helper.restore_ranger_policies(ranger_config_dict)
#!/usr/bin/env python2.7
def execute(ranger_policy_helper):
logger = ranger_policy_helper.getLogger()
logger.info('Testing Ranger export-import functions')
ranger_config_dict = {
"ranger_backup_files_tobe_removed": ['Ranger_Policies_*','*','Ranger_Policies.json'] # File-list or pattern to delete Ranger-policy backup files.
}
ranger_policy_helper.cleanup_ranger_policy_backup_files(ranger_config_dict)