Faster Ollama Model Downloads by Using a Backup

I have a few computers running ollama, and was not enjoying downloading models to each one, so this is a backup script that backs up the blobs directory, and also syncs the latest backup to the blobs directory.

To create this, make a directory named “ollama-models” on an external backup disk that you can carry from computer to computer, and copy these files into it:

# README

Before running backup.sh, make sure you run
the install.sh command.

Ollama must be installed before using the
backup script.

-----

This is a copy of the ollama models directory.

The backup script syncs the model blobs to blobs/
and syncs the blobs/ to the system's blobs directory.

This can save hours of downloading from the internet.

I'm using this on an external hard disk that's carried
from computer to computer.

------

Note that the blobs folder has backups for all the files,
but to get a model registered into the system's ollama,
you need to run the "ollama pull modelname" command.

If the model is in this backup, it'll install almost
instantly, saving minutes of downloading.

Then, create this installation script.

#!/bin/bash
# install.sh

# This is the standard Ollama installation command.
# Ollama should be installed before restoring the backup.

curl -fsSL https://ollama.com/install.sh | shCode language: PHP (php)

Then create this backup script:

#! /bin/bash

# backup.sh

echo WARNING
echo
echo Do not run this script when you are downloading a model.
echo Syncing /usr/share/ollama/.ollama/models/blobs/
echo
echo If you screw up the blobs directory, try running this command
echo from this directory:
echo
echo "    sudo rm blobs/*-partial*"
echo
echo This clears out partial files from the backup.
echo
echo To activate a model, use the ollama command:
echo
echo "    ollama pull modelname"
echo
echo If the model\'s blob is in the backup, and has been copied to the
echo blobs directory, the model\'s manifest will be downloaded
echo and the model will be included in installation instantly.

sudo rsync -rav /usr/share/ollama/.ollama/models/blobs/ blobs/
sudo rsync -rav blobs/ /usr/share/ollama/.ollama/models/blobs/
Code language: PHP (php)