Example 5: Import and export data

You can export data from an McAfee ePO server and import that data to another McAfee ePO server with a script.

Importing and exporting common settings for permissions, policies, or other ePolicy Orchestrator objects is useful when performing server migrations, setting up a secondary McAfee ePO server, or simply creating a test environment. This script exports client tasks and policies for a given product, then imports them to a second server.

#Example 5
import mcafee
mc = mcafee.client('localhost','8443','ga','ga','https','json')

# Find the product id
productId = None
policies = mc.policy.find('McAfee Agent')
for policy in policies:
	productId = policy['productId']

if productId == None:
	error = 'Error finding the product id.'
	sys.exit(error)

tasks = mc.clienttask.export(productId=productId)
file = open('tasks.xml', 'w')
print >>file, tasks
file.close()

policies = mc.policy.export(productId=productId)
file = open('policies.xml', 'w')
print >>file, policies
file.close()

# Import these into another server:
mc2 = mcafee.client('anotherEpoServer','8443','ga','ga','https','json')
mc2.clienttask.importClientTask(uploadFile='file:///tasks.xml')
mc2.policy.importPolicy(file='file:///policies.xml')

The script retrieves the product ID by searching for a policy containing the string 'McAfee Agent'. Using that product ID, you can export all client tasks and policies for that product.

To import the tasks and policies, create a connection to a second ePolicy Orchestrator server (mc2) and run the corresponding import commands.