Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with create_backup() #61

Open
Borgenstrand opened this issue Feb 4, 2021 · 1 comment · May be fixed by #76
Open

Issues with create_backup() #61

Borgenstrand opened this issue Feb 4, 2021 · 1 comment · May be fixed by #76

Comments

@Borgenstrand
Copy link

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

@finish06
Copy link
Owner

finish06 commented Feb 5, 2021

Yep. That is an issue. Good catch. I will work on getting a release out that has the mgr updated to equal 'backup'.
Thanks!

@BoostCookie BoostCookie linked a pull request Aug 30, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants