code: def restore(archive, oqdata):
      
      if os.path.exists(oqdata):
          sys.exit('%s exists already' % oqdata)
      if '://' in archive:
          # get the zip archive from an URL
          resp = requests.get(archive)
          _, archive = archive.rsplit('/', 1)
          with open(archive, 'wb') as f:
              f.write(resp.content)
      if not os.path.exists(archive):
          sys.exit('%s does not exist' % archive)
      t0 = time.time()
      oqdata = os.path.abspath(oqdata)
      assert archive.endswith('.zip'), archive
      os.mkdir(oqdata)
      zipfile.ZipFile(archive).extractall(oqdata)
      dbpath = os.path.join(oqdata, 'db.sqlite3')
      db = Db(sqlite3.connect, dbpath, isolation_level=None,
              detect_types=sqlite3.PARSE_DECLTYPES)
      n = 0
      for fname in os.listdir(oqdata):
          mo = re.match('calc_(\d+)\.hdf5', fname)
          if mo:
              job_id = int(mo.group(1))
              fullname = os.path.join(oqdata, fname)[:-5]  # strip .hdf5
              db("UPDATE job SET user_name=?x, ds_calc_dir=?x WHERE id=?x",
                 getpass.getuser(), fullname, job_id)
              safeprint('Restoring ' + fname)
              n += 1
      dt = time.time() - t0
      safeprint('Extracted %d calculations into %s in %d seconds'
                % (n, oqdata, dt))
docs: Build a new oqdata directory from the data contained in the zip archive