Description
I am using a Raspberry pi as my Unifi controller(version atag_6.0.45_14358), and I am trying to take backup of it.
I get the error message:
Exception has occurred: IndexError
list index out of range
File "C:\Users\mabor\OneDrive - IT Relation\Skrivebord\Python\Private\Unifi\UnifiAP.py", line 31, in
CreateBackup=c.create_backup()
This is basically my code(edited to remove unneeded things and passwords and so on):
from future import print_function
import argparse
import time
from collections import defaultdict
from pyunifi.controller import Controller
ControllerIP="192.168.254.111"
Username=""
Password=""
Port="8443" #Management port, default is 8443
Version="v5" #Default version is v5
Siteid="default" #Default siteID in Unifi
c = Controller(ControllerIP, Username, Password, Port, Version, Siteid ,ssl_verify = False)
CreateBackup=c.create_backup()
time.sleep(15)
print(CreateBackup)
Backup=c.get_backup(CreateBackup)
print(Backup)
I got it to work by editing the function create_backup().
Before I started:
def create_backup(self, days='0'):
"""Ask controller to create a backup archive file
..warning:
This process puts significant load on the controller
and may render it partially unresponsive for other requests.
:param days: metrics of the last x days will be added to the backup.
'-1' backup all metrics. '0' backup only the configuration.
:return: URL path to backup file
"""
res = self._run_command('backup', mgr='system', params={'days': days})
return res[0]['url']
I changed mgr='system" to mgr='backup' and then it worked. This seems to be due to the fact that run_command uses the mgr in its API call.
I installed pyunifi using pip install pyunifi on my windows machine. I use pyunifi version
pyunifi==2.20.1