Automated config backup

48 views
Skip to first unread message

Simon Cox

unread,
Nov 28, 2018, 10:09:32 AM11/28/18
to Jam.py Users Mailing List


Below is a short script that allows you to automate the backup the config of your Jam.py app.

It is not sufficient simply to back-up your database if you want to restore from a complete failure.

Hope this is useful to someone


import requests

import json

import os


# change these variables (or better yet, store in a config file ;-)

login = "admin"

password = "superstrongpassword"

url = 'http://my.jam-py.app'

downloadfolder = r'C:\Config backups'



session = requests.Session()


data
= json.dumps(["login",0,0,[login,password],time.time()*1000])


headers = {

   'Content-Type' : 'application-json'

}


r = session.post(url + '/api', data=data, headers=headers)


data = json.dumps(["server",0,0,["server_export_task",[1,url]],time.time()*1000])


r
= session.post(url + '/api', data=data)


pth = r.json()['result']['data'][0]


r = session.get(pth)


open(os.path.join(downloadfolder, os.path.basename(pth)), 'wb').write(r.content)


Dražen Babić

unread,
Nov 28, 2018, 8:44:53 PM11/28/18
to Simon Cox, Jam.py Users Mailing List
Cheers mate

I tried and missing a few dependencies for python3:

pip install jsonlib-python3

but

Traceback (most recent call last):
File "backup.py", line 24, in <module>
data = json.dumps(["login",0,0,[login,password],time.time()*1000])
NameError: name 'time' is not defined

Any suggestion for that one?

Ta
> --
> You received this message because you are subscribed to the Google Groups
> "Jam.py Users Mailing List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jam-py+un...@googlegroups.com.
> To post to this group, send email to jam...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jam-py/a3c395e5-7b7b-47cc-ae78-0688e3c63822%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Dražen Babić

unread,
Nov 28, 2018, 8:56:02 PM11/28/18
to Simon Cox, Jam.py Users Mailing List
Figured,

"import time" was missing :)

Awesome work, thanks!
Reply all
Reply to author
Forward
0 new messages