✍ Run memos on fly.io. Backup the memos DB to cloud storage with litestream.
English | 中文
Deploy the self-hosted memo service, memos, on fly.io. Automate database backups to B2 using litestream.
Acknowledgments to linkding-on-fly for inspiring this project.
To deploy memos without litestream on fly.io (Memos Official images), refer to README_no_litestream for instructions. Skip the remainder of this README document.
hu3rror/memos-on-fly-build is deprecated. Maintenance has moved to hu3rror/memos-litestream.
If you previously used this image, change the build image section in your fly.toml to the new image:
[build]
- image = "hu3rror/memos-fly:latest"
+ image = "ghcr.io/hu3rror/memos-litestream:stable"
The new image is universal for both fly.io and local runs.
flyctl
.flyctl auth login
Do not set up Postgres and do not deploy yet!
flyctl launch
This command creates a fly.toml
file.
fly.toml
Use fly.with.litestream.example.toml in this repository as a reference and modify according to the comments.
build
section.[build]
image = "ghcr.io/hu3rror/memos-litestream:stable"
env
section.[env]
LITESTREAM_REPLICA_BUCKET = "<filled_later>" # change to your litestream bucket name
LITESTREAM_REPLICA_ENDPOINT = "<filled_later>" # change to your litestream endpoint URL
LITESTREAM_REPLICA_PATH = "memos_prod.db" # keep the default or change to whatever path you want
ℹ️ If you want to use another storage provider, check litestream's "Replica Guides" section and adjust the config as needed.
fly.toml
.LITESTREAM_REPLICA_ENDPOINT
and LITESTREAM_REPLICA_BUCKET
to your [env]
section.<
and >
).flyctl secrets set LITESTREAM_ACCESS_KEY_ID="<keyId>" LITESTREAM_SECRET_ACCESS_KEY="<applicationKey>"
3GB
of storage across your VMs. Since memos
is very light on storage, a 1GB
volume will be more than enough for most use cases. Change the volume size later if needed. Find instructions in the "scale persistent volume" section below.flyctl volumes create memos_data --region <your_region> --size <size_in_gb>
For example:
flyctl volumes create memos_data --region hkg --size 1
mounts
section to fly.toml
.[[mounts]]
source = "memos_data"
destination = "/var/opt/memos"
internal_port
to [[services]]
[http_service]
internal_port = 5230 # change to 5230
flyctl deploy
If all is well, access memos by running flyctl open
. You should see its login page.
🎊 Enjoy using memos!
Check the status of memos's docker image built by GitHub Actions.
If the latest docker image is on Docker Hub, upgrade memos with flyctl deploy
in your project's folder.
If desired, configure a custom domain for your install.
Litestream continuously backs up your database by persisting its WAL to B2, once per second.
Two ways to verify backups:
Focus on 2 as it simulates an actual data loss scenario. This procedure can also scale your volume to a different size.
Start by making a manual backup of your data:
List all fly volumes and note the id of the memos_data
volume. Then, delete the volume.
flyctl volumes list
flyctl volumes delete <id>
This will result in a dead VM after a few seconds. Create a new memos_data
volume. Your application should automatically attempt to restart. If not, restart it manually.
When the application starts, you should see the successful restore in the logs.
[info] No database found, attempt to restore from a replica.
[info] Finished restoring the database.
[info] Starting litestream & memos service.
Assuming one 256MB VM and a 3GB volume, this setup fits within Fly's free tier. [^0] Backups with B2 are free as well. [^1]
[^0]: Otherwise, the VM is ~$2 per month. $0.15/GB per month for the persistent volume.' [^1]: The first 10GB are free, then $0.005 per GB.
Check that your B2 secrets and environment variables are correct.
fly ssh console
does not connectCheck the output of flyctl doctor
. Every line should be marked as PASSED. If Pinging WireGuard
fails, try flyctl wireguard reset
and flyctl agent restart
.
Run flyctl deploy --no-cache
.
Due to the fly.toml v2 update, modify your fly.toml like:
[http_service]
auto_stop_machines = false # change to `false` if you use the Telegram bot