Skip to content
BotServBotServ
OllamaBackupModel backupRestoreData protection

Backup Ollama Models and Data

Secure Ollama installation, models and config. Backup strategies, restore and portability.

S

schutzgeist

3 min read
Backup Ollama Models and Data

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_ed25519 and id_ed25519.pub: Key pair for model signing.

What Should Be Backed Up?

ComponentReason
~/.ollamaContains models, manifests, and keys.
ModelfilesDefine custom models.
Compose filesConfigure the Ollama service.
.env filesHold configuration and secrets.
Docker volumesPersistent 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

  1. Create a backup.
  2. Copy ~/.ollama to the new machine.
  3. Install Ollama.
  4. Run ollama list to verify models are recognized.
  5. Run ollama run to 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 rsync or restic save 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

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

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.

Back to Blog
Share:

Related Posts