Jump to content

How to export all ASM Policies


guru

Recommended Posts

Here is a bash script that will export all your policies as XML file which is the same as if you went one by one via the GUI

Create file on your machine (I've tested from my Macbook as well as a RedHat server successfully)

vi exportASMpolicies.sh

Then copy and paste the following

!/bin/bash

envir=SAT1
echo "environment:$envir"
ltm=10.46.48.13
echo "ltm:$ltm"
user=admin
echo "user:$user"
pass=SuP3rC00L
echo "password:$pass"

curl -ku $user:$pass -X GET https://$ltm/mgmt/tm/asm/policies | jq '.items[] | "pol_name:" + .name + ";api_id:" + .id' >> asmDetails$envir.txt
cat asmDetails$envir.txt |grep pol_name |cut -d":" -f2 |cut -d";" -f1 >> asmPolicies$envir.txt
cat asmDetails$envir.txt |grep pol_name |cut -d":" -f3 |cut -d'"' -f1 >> asmIDs$envir.txt

folderName="$(zdump AEST)"
mkdir -p asm"$envir"Backup
mkdir "asm"$envir"Backup/""$folderName"

paste -d'\n' asmPolicies"$envir".txt asmIDs"$envir".txt | while read asmPolicy && read asmIDs;do
echo $asmPolicy $asmIDs
curl -ku $user:$pass -X POST https://"$ltm"/mgmt/tm/asm/tasks/export-policy -H 'Content-Type: application/json' -d '{"filename":"'$asmPolicy'","policyReference":{"link":"https://localhost/mgmt/tm/asm/policies/'$asmIDs'"}}'
curl -ku $user:$pass -X GET https://"$ltm"/mgmt/tm/asm/file-transfer/downloads/$asmPolicy >> asm"$envir"Backup/"$folderName"/$asmPolicy.xml
done

rm asmDetails"$envir".txt
rm asmPolicies"$envir".txt
rm asmIDs"$envir".txt

Don't forget to make the file executable

chmod +x exportASMpolicies.sh

Then finally run the command and you should get a folder output

./exportASMpolicies.sh

 

  • Like 1
Link to comment
Share on other sites

This is very awesome and saved me a ton of time since the GUI you can only export one at a time which exports into XML just like this does.

Now the real question is....

Do you have a script to import all the xml files?

Link to comment
Share on other sites

×
×
  • Create New...