Corrupted project json files after faulty reattaching

Continuously monitor the database storage for available storage to avoid a similar problem from arising in the future.

There may be, but the following procedure has not been tested.

  1. Detach the project directory.
  2. Prepare and set aside a copy of the project directory, in case the following steps result in unintended and unwanted changes to the project directory.
  3. Post under this topic any questions you may have regarding the procedure below.
  4. Save the following script to a file build_manifest.py:
    project_dir = "/path/to/unattached/copy/of/projectdir/"
    manifest_path = "/tmp/WpPwiAf5vi.job_manifest.json"
    failed_job_docs_path = "/tmp/WpPwiAf5vi.failed.json"
    
    import pathlib
    import json
    
    jobs = []
    failed_job_dirs = {}
    
    for doc in pathlib.Path(project_dir).glob('J*/job.json'):
        job_dir = doc.parts[-2]
        with open(doc) as handle:
            try:
                assert job_dir[1:].isdigit(), f"{doc} is not a valid job document path."
                data = json.load(handle)
                assert job_dir == data['uid'], f"Job uid does not match directory name {job_dir}."
                jobs.append(data['uid'])
            except Exception as e:
                failed_job_dirs[job_dir] = str(e)
    
    with open(manifest_path, 'w') as mhandle:
        json.dump({'jobs': sorted(jobs)}, mhandle, indent=4) 
    
    if failed_job_dirs:
        with open(failed_job_docs_path, 'w') as fhandle:
            json.dump(failed_job_dirs, fhandle, indent=4)
    
  5. In build_manifest.py, edit the project_dir definition on the first line to point to the unattached copy of the project directory.
  6. Run the command
    python3 build_manifest.py
  7. The command may take some time to complete. After completion, inspect (without modifying) the *.job_manifest.json and *.failed.json files created by the script inside the /tmp/ directory. *.job_manifest.json should include most job IDs in the project. *.failed.json should include records for a few job IDs along with errors that lead to those job’s exclusion from the job manifest.
  8. Copy the *.job_manifest.json to the unattached project directory as a file named job_manifest.json.
  9. Create a “synthetic” workspaces.json file as described in Attach a project without workspace.json - #2 by wtempel, as applicable given the workspace_uids present in all the project’s jobs’ job.json files.
  10. After creating and placing inside the project directory the job_manifest.json and workspaces.json files, try again attaching the project.