[ckan-dev] Backing up Organizations

Matt Fullerton matt.fullerton at okfn.de
Mon Jan 12 07:34:02 UTC 2015


I think these commands are there for publishing rather than for
import/export. I would use the API for this. To get the dump:
http://beta.offenedaten.de/api/3/action/organization_list?all_fields=True&include_extras=True

(replace beta.offenedaten.de with your site URL)

To import it would be more tricky, but you could use something like
this in Python (not tested!):

import urllib2
import urllib
import json
import pprint
import os

#Set these env variables before running
url = os.environ['CKANURL']
apikey = os.environ['CKANAPIKEY']

jsonurl = open(sys.argv[1], 'rb')
listpackages = json.loads(jsonurl.read())

for rec in listpackages:
    data_string = urllib.quote(json.dumps(rec))
    request = urllib2.Request(url +'/api/3/action/organization_create')
    request.add_header('Authorization', apikey)
    response = urllib2.urlopen(request, data_string)
    response_dict = json.loads(response.read())
    pprint.pprint(rec['title'] + ": " + str(response_dict['success']))

Usage:
export CKANURL="http://beta.offenedaten.de" [replace with your url]
export CKANAPIKEY="xxxxxxxxxx" [replace with a sysadmin api key from
the user info page]
python importorgs.py path/to/json/file.json

-Matt
--
Matt Fullerton
Softwareentwickler
matt.fullerton at okfn.de
+49 89 74560495
Open Knowledge Foundation Deutschland e.V.
Singerstr. 109
10179 Berlin
http://www.okfn.de


On 12 January 2015 at 03:10, Michael Speth
<spethm at landcareresearch.co.nz> wrote:
> Is it possible to export and import organizations (without backing up the
> entire database)?
>
> The link below shows how to export users and datasets.
> http://docs.ckan.org/en/latest/maintaining/paster.html#dumping-and-loading-databases-to-from-a-file
>
> But how do you import the datasets and users?
>
> Regards
> --
> Michael Speth
> DevOps Computer Engineer
> Landcare Research Consultant
>
> ________________________________
>
> Please consider the environment before printing this email
> Warning: This electronic message together with any attachments is
> confidential. If you receive it in error: (i) you must not read, use,
> disclose, copy or retain it; (ii) please contact the sender immediately by
> reply email and then delete the emails.
> The views expressed in this email may not be those of Landcare Research New
> Zealand Limited. http://www.landcareresearch.co.nz
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>



More information about the ckan-dev mailing list