Replies: 5 comments 1 reply
-
Here's a fourth method. It stops the app and accessory containers so nothing is connected to the new database, then uses a temporary container (so we can access the named volume) to remove the new database and copy in the existing one.
|
Beta Was this translation helpful? Give feedback.
-
I'd like to use an approach based on restoring the database from backup.
The restored database will be owned by
Finally:
|
Beta Was this translation helpful? Give feedback.
-
It would be nice to have the Rails app's Docker entrypoint restore the database if none is present. However it doesn't have access to litestream which is in its own container. |
Beta Was this translation helpful? Give feedback.
-
After a lot of trial and error, I have found it much simpler to run litestream in the app container. It's not really in the spirit of Docker, but litestream supports it and it eliminates file ownership problems. It also makes it simple to automatically restore the database from backup if it's missing when the container starts. The one gotcha which took me an embarrassing amount of time to solve was needing to re-quote the passthrough arguments in the Docker entrypoint script. Initially I tried this: - exec "${@}"
+ exec litestream replicate -exec "${@}" However that doesn't work: the This was the solution: - exec "${@}"
+ exec litestream replicate -exec "$(printf '%q ' "${@}")" |
Beta Was this translation helpful? Give feedback.
-
I love the thoughts here and on a non-ruby project I wrote a backup script and restore script I could fire. After a search I found your discussion here. I'm new to rails and just figuring it out and kamal2 out and all that. That being said, I think Litestream is nice but it's a lot of overhead for essentially copying files over from one place to another. The way I've done this in a nodejs context was a scheduled job to run `sqlite3 path/to/db .backup '/path/to/backup', then connect to an s3 compatible bucket, push it up there. Then have a script to allow pulling the file from the backup, and if missing a param show you the last 5 created backups. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a Rails 8 app with a sqlite database, deployed on a single server. I want to move everything to a new server and retire the old one. What's the recommended way to copy the existing database across?
(I should mention that the database on the old server is Postgres. As part of the migration I am exporting the data from Postgres and importing it to sqlite. As a consequence I don't have any backups of the sqlite database yet.)
My Kamal setup has a single accessory, litestream, for database backups.
I have come up with three approaches but none feels right.
First method
kamal setup
. This creates a new, empty database.scp
existing database to new server.kamal server exec docker cp production.sqlite3 APP_CONTAINER_ID:/rails/storage/
.kamal app reboot
.I worry that simply copying the old database over the top of the new database, while Rails has a connection to it, could corrupt it. Especially as the
-wal
and-shm
files won't correspond to the new database.Second method
files
entry to the litestream accessory inconfig/deploy.yml
:- storage/production.sqlite3:/data/production.sqlite3
./data
is a path in the container corresponding to the same named volume as the app's.kamal accessory boot litestream
.files
entry fromconfig/deploy.yml
.kamal app boot
.I worry here that:
/data
in the litestream container before it is mounted as a volume, not after (is that correct? I can't find the place in the code where accessories are set up). If so, I believe the file will be obscured once the volume is created.root
(since it is put there by the litestream container) notrails
(the first user in my app container).kamal setup
?Third method
kamal setup
. This creates a new, empty database.kamal app stop
.kamal accessory stop litestream
.kamal app exec rm storage/production.sqlite3*
.kamal accessory exec litestream restore /data/production.sqlite3
kamal app boot
.kamal accessory start litestream
.What's the recommended way to do this?
Beta Was this translation helpful? Give feedback.
All reactions