Downloaded models can take far longer to replace than the Ollama application. On Linux, a backup of the systemd service's data preserves the model store and local identity so a restored installation can use them again.

The service account's home and environment determine where Ollama stores its files. A standard Linux service installation has a different home from your terminal account, so copying your own home directory can miss every downloaded model.

You need sudo access, an installed model, and enough free disk space for the archive and an extracted copy. A complete data backup can contain authentication keys and must remain private; stopping the service also interrupts requests and model downloads.

Steps to back up and restore Ollama data:

  1. Inspect the service account and configuration paths.
    $ systemctl show ollama -p User -p Group -p FragmentPath -p DropInPaths
    FragmentPath=/etc/systemd/system/ollama.service
    DropInPaths=
    User=ollama
    Group=ollama
  2. Locate the running service's home and model-directory override.
    $ sudo cat /proc/"$(systemctl show ollama -p MainPID --value)"/environ | tr '\0' '\n' | grep -E '^(HOME|OLLAMA_MODELS)='
    HOME=/usr/share/ollama

    The remaining paths assume this service home and no OLLAMA_MODELS override. If either differs, the source, archive layout, and restore destination need to match the active locations before copying. macOS normally stores models under ~/.ollama/models; Windows uses the account's .ollama\models directory. Those user installations do not use this systemd restore.

  3. List the models that the backup must recover.
    $ ollama list
    NAME            ID              SIZE      MODIFIED    
    qwen2.5:0.5b    a8b0c5157701    397 MB    2 hours ago

    qwen2.5:0.5b is the installed model used for the recovery check. An existing model from your inventory can take its place.

  4. Reserve a private backup directory.
    $ sudo mkdir -m 700 /var/backups/ollama-recovery

    The directory must be new. If it already exists, a different backup directory avoids overwriting an earlier recovery copy. Archives containing keys must stay on access-controlled storage and be encrypted before transfer to untrusted storage.

  5. Save the effective service definition.
    $ sudo systemctl cat ollama | sudo tee /var/backups/ollama-recovery/service-unit.txt > /dev/null

    The saved definition includes any systemd drop-ins. It is recovery information for the service setup; the data restore below keeps the existing service configuration.

  6. Record the service's starting state.
    $ systemctl show ollama -p ActiveState -p UnitFileState -p User -p Group | sudo tee /var/backups/ollama-recovery/service-state.txt > /dev/null
  7. Stop Ollama before archiving its data.
    $ sudo systemctl stop ollama

    Stopping the service prevents a pull or another write from changing blobs and manifests during the copy.
    Related: How to manage the Ollama service

  8. Confirm that the service is stopped.
    $ systemctl is-active ollama
    inactive

    inactive returns exit status 3. Any active state means the data is not ready for copying.

  9. Archive the stopped service's data in the private backup directory.
    $ sudo tar -C /usr/share/ollama -czf /var/backups/ollama-recovery/ollama-data.tar.gz .ollama

    The archive includes model manifests, blobs, and any keys in .ollama. It does not include the Ollama binary or model files stored outside that directory.

  10. Restrict the archive to its root owner.
    $ sudo chmod 600 /var/backups/ollama-recovery/ollama-data.tar.gz
  11. Inspect the archive's contents.
    $ sudo tar -tzf /var/backups/ollama-recovery/ollama-data.tar.gz

    The listing must contain .ollama/models/manifests and .ollama/models/blobs with the expected model files. An archive listing alone does not prove that a model can run.

  12. Create an empty staging directory for the restore.
    $ sudo mkdir -m 700 /var/backups/ollama-recovery/restore
  13. Extract the archive into the staging directory.

    Only a trusted backup belongs in this privileged extraction. An empty staging directory keeps restored files separate from the current store.

    $ sudo tar -C /var/backups/ollama-recovery/restore -xzf /var/backups/ollama-recovery/ollama-data.tar.gz
  14. Assign the restored data to the service account.
    $ sudo chown -R ollama:ollama /var/backups/ollama-recovery/restore/.ollama

    The owner and group must match the service values inspected earlier, especially when recovering onto another installation.

  15. Move the original data into the protected rollback directory.

    This removes the original store from the live path while retaining it for rollback. Ollama must remain stopped. If recovery fails, the retained original can replace the restored .ollama directory while the service is stopped; the archive also remains available.

    $ sudo mv -T /usr/share/ollama/.ollama /var/backups/ollama-recovery/original.ollama
  16. Put the restored data in the service's active location.
    $ sudo mv -T /var/backups/ollama-recovery/restore/.ollama /usr/share/ollama/.ollama
  17. Start the service with the restored data.
    $ sudo systemctl start ollama
  18. Wait for the local API to respond.
    $ curl -fsS --retry 5 --retry-connrefused --retry-delay 1 http://127.0.0.1:11434/api/version
  19. Check that the recovered model inventory matches the original inventory.
    $ ollama list
    NAME            ID              SIZE      MODIFIED    
    qwen2.5:0.5b    a8b0c5157701    397 MB    2 hours ago
  20. Run a model from the restored store.
    $ ollama run qwen2.5:0.5b "What is 17 plus 25? Answer in one short sentence."
    17 plus 25 equals 42.

    A generated answer confirms that Ollama can read and use the restored model; wording can vary. The protected archive, service records, and original data remain available for recovery.

Share this guide