cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MERAKI BACKUP AND RESTORE

Highlighted
Getting noticed

MERAKI BACKUP AND RESTORE

Hi guys,

Good Morning.

 

Just want to hear your unique ways about how to backup your configuration in the dashboard to your local drive.

In my situation i had an MX65W with configurations already and then i will have a new MX65W coming to be use in another organization.

My question first is how can i backup my configuration from my existing MX65W so that i can use it to my new MX65W? (But this is answered already by meraki support so they provide me a link  : https://documentation.meraki.com/zGeneral_Administration/Templates_and_Config_Sync/Cloning_Network_S... ).

In this link i just saw how to clone from network to another network in one organization.

 

Now, i want to hear from you guys if you experience this already and how you tried to backup from one organization to another organization.

 

Thanks in advance.

62 REPLIES 62
Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

Highlighted
Getting noticed

Re: MERAKI BACKUP AND RESTORE

Thanks @PhilipDAth , i would try this now.

Highlighted
Head in the Cloud

Re: MERAKI BACKUP AND RESTORE

Config Sync and Templates is the native way of replicating configuration from networks which need to be re-used and re-purposed else where.

 

If you're wanting to back-up the configuration to a local file you can do this via scripting and the API. @PhilipDAth has created a script for this purpose. I've tested it and works fantastic!

Eliot F | Simplifying IT with Cloud Solutions
Found this helpful? Give me some Kudos! (click on the little up-arrow below)
Highlighted
Getting noticed

Re: MERAKI BACKUP AND RESTORE

I found this erro when executing. I am not really familiar with python. 

meraki error local backup.PNG

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

Try changing these three lines from:

del mySNMP['v2CommunityString']
del mySNMP['hostname']
del mySNMP['port']

to:

if 'v2CommunityString' in mySNMP:

<tab>del mySNMP['v2CommunityString']

if 'hostname' in mySNMP:

<tab>del mySNMP['hostname']

if 'port' in mySNMP:

<tab>del mySNMP['port']

 

Make sure you replace "tab" with the tab key.  Formatting is very important in Python.  Let me know if it fixes it so I can update the main script.

Highlighted
Getting noticed

Re: MERAKI BACKUP AND RESTORE

Thanks @PhilipDAth I will update you once done executing.

Highlighted
Getting noticed

Re: MERAKI BACKUP AND RESTORE

C:\Users\Lenovo\Desktop>python meraki-backup.py [API-KEY] "Ardent Network Inc"
Processing network MY NETWORK
Processing network NGKHAI
HTTP Status Code: 404 - No returned data

Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn
conn.connect()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connection.py", line 326, in connect
ssl_context=context)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 814, in __init__
self.do_handshake()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 1068, in do_handshake
self._sslobj.do_handshake()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\retry.py", line 357, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\packages\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn
conn.connect()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connection.py", line 326, in connect
ssl_context=context)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 814, in __init__
self.do_handshake()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 1068, in do_handshake
self._sslobj.do_handshake()
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionAbortedError(10053, 'An established connection was aborted by the software in your host machine', None, 10053, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "meraki-backup.py", line 184, in <module>
write_ssid_settings(file,apikey,row['id'],suppressprint)
File "meraki-backup.py", line 121, in write_ssid_settings
myRules=meraki.getssidl3fwrules(apikey, networkid, row['number'], suppressprint)[0:-2]
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\meraki\meraki.py", line 1703, in getssidl3fwrules
dashboard = requests.get(geturl, headers=headers)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 640, in send
history = [resp for resp in gen] if allow_redirects else []
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 640, in <listcomp>
history = [resp for resp in gen] if allow_redirects else []
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 218, in resolve_redirects
**adapter_kwargs
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionAbortedError(10053, 'An established connection was aborted by the software in your host machine', None, 10053, None))

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

Hi @Ritchie.  Just edit that last post and remove the API key from from the command line.  I'll have a look at the rest.

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

I see it got upset when retrieving the SSID Firewall rules. I haven't tested against a M65W before, so I'll go try that.

 

So the prior change I gave got you past the SNMP issue?

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

I have a couple of thoughts.

 

Are you perhaps using Python V2 instead of Python V3?  To force the version try:

python3 meraki-backup.py <api-key> "Ardent Network Inc"

 

I have also updated the script to include the SNMP fix, and an issue with SSIDs.  So you should download a fresh copy.  You may still get some errors, but you should get a reasonable restore script produced.

Highlighted
Getting noticed

Re: MERAKI BACKUP AND RESTORE

python3.6.PNG

 

 

I am using python 3.6

Highlighted
Head in the Cloud

Re: MERAKI BACKUP AND RESTORE

The old script worked with me fine with Python 3.6, all I did was go into my network-wide settings and just enabled SNMP and set anonymous community strings which did the trick.

Eliot F | Simplifying IT with Cloud Solutions
Found this helpful? Give me some Kudos! (click on the little up-arrow below)
Highlighted
Getting noticed

Re: MERAKI BACKUP AND RESTORE

I will check that.

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

I just tried the script and seems to work fine, at least i can not see any errors but where the results are written ??  which folder ?

Thanks

 

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

The results are written to the "current working directory" - so whatever directory you ran the command in, the restore script will be in.

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

oh ok , sorry Philip, i thougth that the results were written on a file other that the restore script. I see now that the "data" is inside the restore scripts itself. clear.

Thanks again.

Miguel Angel

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

Tried out the backup script. Had some problems getting it to run at first. Error was: 

TypeError: __init__() got an unexpected keyword argument 'strict'

Reason was an out-of-date requests library. Fixed that by using:

pip install --upgrade requests

 

For testing I had created a dummy network that didn't have actual hardware in it but had some hardware independent settings changed. Had problems creating a backup with that somewhat empty network in my org:

 

HTTP Status Code: 404 - No returned data

Traceback (most recent call last):
  File "meraki-backup.py", line 187, in <module>
    write_ssid_settings(file,apikey,row['id'],suppressprint)
  File "meraki-backup.py", line 124, in write_ssid_settings
    myRules=meraki.getssidl3fwrules(apikey, networkid, row['number'], suppresspr
int)[0:-2]
TypeError: 'NoneType' object is not subscriptable

 

 Although the backup without that network was successful I'm not really willing to try out whether restore works on my real networks.

 

I think that Meraki should allow for some kind of backup natively.

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

Thanks for the feedback!  I don't think I have tested it out on a network with no devices in it.  I'll give that a try sometime.

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

@PhilipDAth

Have you considered putting this script under version control on GitHub? Would be a great way to for people to track changes/updates and contribute to the code base.
Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

I hadn't considered it.  I'm not a proper developer ...

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

I too am receiving errors when running the script. Both on Organizations with and without devices on their network. See below.

 

Python 3.6.5

requests  2.18.4

meraki 0.33

 

HTTP Status Code: 404 - No returned data

Traceback (most recent call last):
  File "meraki-backup.py", line 159, in <module>
    write_admins(file,apikey, orgid, suppressprint);
  File "meraki-backup.py", line 53, in write_admins
    for row in myOrgAdmins:
TypeError: 'NoneType' object is not iterable

 

Highlighted
Conversationalist

Re: MERAKI BACKUP AND RESTORE

Hey @WANKiller or @PhilipDAth  could you pleaes indicate me where is that script ? thanks in advance.

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

Check out the second post.

Highlighted
Conversationalist

Re: MERAKI BACKUP AND RESTORE

thanks Philip , good idea about that script btw . Regards
Highlighted
New here

Re: MERAKI BACKUP AND RESTORE

LOL! You need a python script to half-ass backup the Meraki config?  Cisco you're the best!

Just browsing

Re: MERAKI BACKUP AND RESTORE

Hello Team,

 

I am facing below problem,

 
 

PS C:\Users\USER\Documents\Python> python3 meraki-backup.py xxxxxx "xxxxxx"
Traceback (most recent call last):
File "meraki-backup.py", line 142, in <module>
orgid=get_org_id(apikey,args.orgName,suppressprint)
File "meraki-backup.py", line 13, in get_org_id
result = meraki.myorgaccess(apikey, suppressprint)
AttributeError: module 'meraki' has no attribute 'myorgaccess'

 

 

Using python 3.7.5 on windows 10.

 

Sita

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

>LOL! You need a python script to half-ass backup the Meraki config?  Cisco you're the best!

 

The easiest way to back it up is to just copy it.  However this backup is kept in the cloud.  A small number of people prefer to have an offline backup.

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

I just tried it and it worked for me.

 

If you are on Windows did you do the following from an Administrative prompt?

pip install requests
pip install meraki

 

Are you sure the API key you are using has full administrator access?  It sounds like it does not have rights to access the list of organisations.

Highlighted
Just browsing

Re: MERAKI BACKUP AND RESTORE

Hello Philip,

 

Yes, I have already installed requests and meraki modules using pip.

 

API key that has been generated have full administrative access to only meraki organization we have.

 

 

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

The script made some problems for me, because i have switch or wifi networks without fw rules. So I simply insert a try except block in line 185. Now it works like a charm. Great work so far, hope we can add switch configs and device assignment into the code.

Thanks a lot!

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

Thanks for the feedback and the tip.  That should have worked fine with no firewall rules applied.

 

The whole system need a bits of a refresh.  Perhaps a holiday break project.

Highlighted
Conversationalist

Re: MERAKI BACKUP AND RESTORE

Hello Philip, thanks for the script. I tried to backup my conf and it worked well; now I'm trying to restore it and I'm getting this error:

 

Schermata 2019-12-20 alle 12.04.25.JPG

 

 

 

but I'm not confident with python and I can't resolve it

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

I've released a completely refreshed version of the offline backup/restore system now.

https://www.ifm.net.nz/cookbooks/meraki-backup.html 

 

@DiegoAMorelli this should resolve your issue as well.

Highlighted
Just browsing

Re: MERAKI BACKUP AND RESTORE

I am getting an error message that I haven't seen in any of the other replies. When I run the backup script I get:

 

Traceback (most recent call last):
File "C:\Users\bry\AppData\Local\Programs\Python\Python38-32\scripts\meraki-backup.py", line 200, in <module>
from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv'

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

I think I missed one step.  Try:

pip install -U python-dotenv

Let me know if that fixes it and I'll update the instructions.

Highlighted
Just browsing

Re: MERAKI BACKUP AND RESTORE

That did get me past that error. Now I am getting this:

 

Processing network correct network name
warning: MX VLANs disabled - wont be able to restore IP addressing
Traceback (most recent call last):
File "C:\Users\bry\AppData\Local\Programs\Python\Python38-32\scripts\meraki-backup.py", line 251, in <module>
write_ssid_settings(file,meraki,row['id'])
File "C:\Users\bry\AppData\Local\Programs\Python\Python38-32\scripts\meraki-backup.py", line 180, in write_ssid_settings
mySSIDs=meraki.ssids.get_network_ssids(networkid)
File "C:\Users\bry\AppData\Local\Programs\Python\Python38-32\lib\site-packages\meraki_sdk\controllers\ssids_controller.py", line 117, in get_network_ssids
self.validate_response(_context)
File "C:\Users\bry\AppData\Local\Programs\Python\Python38-32\lib\site-packages\meraki_sdk\controllers\base_controller.py", line 94, in validate_response
raise APIException('HTTP response not OK.', context)
meraki_sdk.exceptions.api_exception.APIException: HTTP response not OK.

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

That means it is failing to get a list of SSIDs in your network.

 

What kind of WiFi device do you have in your network, and are you an Organisation admin so you have rights to read the properties?

Highlighted
Just browsing

Re: MERAKI BACKUP AND RESTORE

I just have one Ubiquity Unify WAP. I am an organization admin.

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

@Cardinal ,

 

So you don't even see a "Wireless" section in the dashboard, correct?

 

Do you have an ordinary MX (like an MX64) or one with WiFi integrated (such as an MX64W)?

Highlighted
Just browsing

Re: MERAKI BACKUP AND RESTORE

Right, there is no "wireless section". I see an option to set up a wireless concentrator, but I haven't done anything with that. It is an MX 64.

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

I am trying to run the script and getting this.. MerakiBackup.JPG

 

Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

Are you sure your API key is correct @AndrewE ?

 

The script is failing at the most basic of levels, finding the orgs that you have access to.

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

Nevermind.. I found the error of my ways.. 🙂
Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

I had placed the api in the wrong location.

Is there a way to target a single network inside an Organization? In some instances there is no Mx so the script fails out and missed around 60 networks.
Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

>Is there a way to target a single network inside an Organization?

 

No, but it should not fail.  Can you post an example of the error you get please.

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

MerakiBackup.PNG

 

I've run it a couple of times and it always seems to hang on a random network at this point.  I don't know if it is the script or what.  

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

Just for Ref. The site that pops that error has no MX appliance.
Highlighted
Kind of a big deal

Re: MERAKI BACKUP AND RESTORE

Thanks for the valuable tip.  I'm not sure I have ever had a network without any MX's.

 

I'll check the network type in that case and conditionally processed based on that.

Highlighted
Here to help

Re: MERAKI BACKUP AND RESTORE

I added some try except blocks and I also wanted to backup my swatches and all ports:

 

def write_mydevices(file,meraki,networkid):
mydevice=meraki.devices.get_network_devices(networkid)
if mydevice is None:
return
file.write("\t# Devices\n")
file.write("\t# https://developer.cisco.com/meraki/api/#/rest/api-endpoints/devices/update-network-device\n")
for row in mydevice:
file.write("\tputurl = 'https://api.meraki.com/api/v0/networks/{0}}/devices/claim.format(str(networkid))\n")
file.write("\tdashboard = session.put(puturl, json="+str(row['serial'])+", headers=headers)\n")
file.write("\tputurl = 'https://api.meraki.com/api/v0/networks/{0}/devices/"+str(row['serial'])+"'.format(str(networkid))\n")
file.write("\tdashboard = session.put(puturl, json="+str(row)+", headers=headers)\n")
if 'switchProfileId' in row:
switchports=meraki.switch_ports.get_device_switch_ports(row['serial'])
for port in switchports:
file.write("\tputurl = 'https://api.meraki.com/api/v0/devices/"+str(row['serial'])+"'/switchPorts/"+str(port['number'])+"'.f...")
file.write("\tdashboard = session.put(puturl, json="+str(port)+", headers=headers)\n")

 

[...]

 

try:
write_mx_vlans(file,meraki, row['id'])
except:
print("no mx VLAN")
try:
write_mx_cellular_fw_rules(file,meraki,row['id'])
except:
print("no mobile firewall rule")
try:
write_mx_l3_fw_rules(file,meraki,row['id'])
except:
print("no MX firewall rule")
try:
write_vpn_settings(file,meraki,row['id'])
except:
print("no VPN")
try:
write_ssid_settings(file,meraki,row['id'])
except:
print("no SSID")
try:
write_qos(file,meraki,row['id'])
except:
print("no QoS")
try:
write_mydevices(file,meraki,row['id'])
except:
print("no devices")

Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.