---
title: Cleanup And Archiving
product: ccpem-pipeliner
doc_type: guide
version: main
source: git2docs (code-derived, validation-filtered)
canonical: https://git2docs.com/wabam/docs/ccpem-pipeliner/ccpem-pipeliner/cleanup-and-archiving
---

# Cleanup And Archiving

_Reclaiming disk space with cleanup and trash, and preserving projects as archives_

## Overview

This page explains how to reclaim disk space in a pipeliner project and how to preserve a completed workflow as a portable archive. Cleanup operations remove intermediate files from job directories (optionally moving them to a `Trash/Cleanup/` holding area so they can be restored), while archiving bundles the upstream job graph for a terminal job into a compressed tarball stored under `ProjectArchives/`. Both capabilities are available through `pipeliner` CLI flags and the `PipelinerProject` Python API.

## Prerequisites

Before you begin:

- `ccpem-pipeliner` installed in your Python 3.9+ environment (`pip install ccpem-pipeliner`)
- A pipeliner project open in the current working directory (a `default_pipeline.star` file and a `.CCPEM_pipeliner_project` marker must exist)
- For archiving: all jobs in the upstream graph of the chosen terminal job must have a status of `Succeeded`, `Failed`, or `Aborted` — `Running` or `Scheduled` jobs block archive creation
- For a **full** archive: sufficient disk space to copy entire job directories
- `tar` available on `PATH` when `tar=True` (the default) is used via the Python API

## Examples

### Example 1 — Normal and harsh cleanup, then restore

```python
from pipeliner.api.manage_project import PipelinerProject

proj = PipelinerProject()

# Normal cleanup: remove intermediate files, moved to Trash/Cleanup/
proj.run_cleanup(['MotionCorr/job002/', 'CtfFind/job003/'])

# Harsh cleanup: remove even more files
proj.run_cleanup(['Class2D/job005/'], harsh=True)

# Restore a job's cleaned files from Trash/Cleanup/ back to the job directory
proj.restore_from_cleanup('MotionCorr/job002/')
```

---

### Example 2 — Delete a job, then empty the trash

```python
from pipeliner.api.manage_project import PipelinerProject

proj = PipelinerProject()

# Move a job and its child jobs to Trash/
proj.delete_job('Class2D/job005/')

# Permanently delete everything in Trash/ — cannot be undone
PipelinerProject.empty_trash()
```

---

### Example 3 — Create a simple and a full archive

```python
from pipeliner.api.manage_project import PipelinerProject

proj = PipelinerProject()

# Simple archive: parameter files + re-run script only (default)
simple_path = proj.create_archive('PostProcess/job010/')

# Full archive: entire job directories
full_path = proj.create_archive('PostProcess/job010/', full=True)
```

Both archives are written under `ProjectArchives/` as `.tar.gz` files.
