Backing Up Ollama Models and Data
What This Article Covers
- What needs to be backed up in an Ollama installation.
- Where Ollama stores its data.
- How to export models and configurations.
- What restoration looks like on a new system.
- Tips for automated and portable backups.
Introduction: Backing Up Ollama Models and Data
Beyond the Ollama application itself, installations contain models, Modelfiles, and configurations. Without a backup, a hardware failure, migration to a new machine, or accidental deletion means losing significant work. Regular backups let you restore models quickly or deploy them identically on another system.
This article shows which data matters and how to back it up reliably.
Key Terms
- Model directory: The location where Ollama stores models.
- Blob: A large binary file representing a model.
- Manifest: Metadata describing a model.
- Modelfile: A definition file for a custom model.
- Volume: A Docker data volume for Ollama.
- Restore: Recovering a backup.
- Export: Saving a model as a file.
Where Does Ollama Store Data?
By default, data lives in:
~/.ollama
On Linux, the actual storage path is:
/usr/share/ollama/.ollama/models
With Docker, the directory resides in the ollama-data volume at /root/.ollama.
Key Contents
models/blobs/: Large binary files for the models.models/manifests/: Model descriptions and metadata.id_ed25519andid_ed25519.pub: Key pair for model signing.
What Should Be Backed Up?
| Component | Reason |
|---|---|
~/.ollama | Contains models, manifests, and keys. |
| Modelfiles | Define custom models. |
| Compose files | Configure the Ollama service. |
.env files | Hold configuration and secrets. |
| Docker volumes | Persistent data in container environments. |
Manual Backup
tar -czf ollama-backup-$(date +%Y%m%d).tar.gz ~/.ollama
For Docker:
docker run --rm -v ollama-data:/data -v $(pwd):/backup alpine \
tar -czf /backup/ollama-data.tar.gz -C /data .
Restore
tar -xzf ollama-backup-20260907.tar.gz -C ~/
For Docker:
docker volume create ollama-data
docker run --rm -v ollama-data:/data -v $(pwd):/backup alpine \
tar -xzf /backup/ollama-data.tar.gz -C /data
Exporting Models
Individual models can be exported:
ollama show llama3.1 --modelfile > llama31.Modelfile
ollama cp llama3.1 mein-llama31
The model can then be imported on another system:
ollama create mein-llama31 -f llama31.Modelfile
Automated Backup Script
#!/bin/bash
set -e
BACKUP_DIR="/backup/ollama/$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"
# Ollama data
tar -czf "$BACKUP_DIR/ollama-data.tar.gz" -C "$HOME" .ollama
# Modelfiles and configuration
rsync -av "$HOME/ollama-config/" "$BACKUP_DIR/ollama-config/"
# Docker Compose
rsync -av /opt/ollama-compose/ "$BACKUP_DIR/compose/"
echo "Backup erstellt: $BACKUP_DIR"
Cron job:
0 4 * * * /usr/local/bin/backup-ollama.sh
Encryption
Encrypt backups with Restic:
restic -r /mnt/backup-repo backup ~/.ollama
Or tar with GPG:
tar -czf - ~/.ollama | gpg -c > ollama-backup.tar.gz.gpg
Offsite Storage
- NAS or external drive.
- Cloud storage with rclone.
- Remote Tailscale node.
- S3-compatible object storage.
Transferring Models to a New Host
- Create a backup.
- Copy
~/.ollamato the new machine. - Install Ollama.
- Run
ollama listto verify models are recognized. - Run
ollama runto test.
Backing Up Docker Volumes
docker run --rm -v ollama-data:/data -v $(pwd):/backup alpine tar -czf /backup/ollama-data.tar.gz -C /data .
On the new system:
docker volume create ollama-data
docker run --rm -v ollama-data:/data -v $(pwd):/backup alpine tar -xzf /backup/ollama-data.tar.gz -C /data
Important Considerations
- Models are large files, so backups require substantial disk space.
- Incremental backups with
rsyncorresticsave space. - Modelfiles and configuration should be backed up together.
- Always create a backup before major updates.
- Test restores regularly.
Common Pitfalls
- Only saving model names: Blobs get left behind.
- Insufficient storage space: Backup fails midway.
- Wrong directory: Ollama data is stored elsewhere.
- Forgetting Docker volumes: Data lives in the volume, not the container.
- No encryption: Private models remain unprotected.
- Never testing restore: A backup that was never tested is worthless.
Further Reading and Resources
- BotServ.de Ollama Commands
- BotServ.de Ollama Model Lifecycle
- BotServ.de Docker Backup
- BotServ.de Docker Volumes
FAQ: Ollama Backup
Can I just copy models?
Yes, the ~/.ollama directory contains everything essential.
Do I need the key pair? Only if you plan to push or verify signed models.
How large is a backup? As large as all your models combined, often several hundred GB.
Can I move models between hosts? Yes, using tar or rsync. Manifests and blobs must stay together.
Should I encrypt backups? Yes, especially if models or configurations contain sensitive information.
Sources and Further Reading
- Ollama data directory: https://github.com/ollama/ollama/blob/main/docs/faq.md
- rsync: https://rsync.samba.org/
- restic: https://restic.net/
Summary: Backing Up Ollama Models and Data
An Ollama backup primarily encompasses the ~/.ollama directory containing models, manifests, and keys. Manual backups with tar or rsync are straightforward, while automated scripts and encrypted offsite backups provide robust protection. Including Modelfiles, Compose configurations, and volumes allows fast recovery when needed. Testing restores regularly ensures your backup will work when it matters most.


