Migrating from a docker container with SQLite to the TrueNAS SCALE TrueCharts enterprise-train app #3805
Lockszmith-GH
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Migrating from a docker container with SQLite to the TrueNAS SCALE TrueCharts enterprise-train app
Why is this posted here?
I'll cross post this to the TrueCharts community as well, but they don't have a forum or discussion board like this, only discord - this seems like `more stable` choice.I've finally successfully completed this migration which I've been putting off for a very long time, and am documenting it here.
There were a few trial-and-error iterations, and I hoped to capture this to share with anyone else who was struggling with this type of migration.
Goal
Migrate from a docker container (docker-compose) based install of vaultwarden with SQLite (running on Linux - In my case an Ubuntu 20.04 host where the
vaultwarden/server:latest
image, is currently at 1.29.1), to a TrueNAS SCALE server, running the TrueCharts helm chart for Vaultwarden.Challange
In TrueNAS SCALE, the concept of Apps is implemented as deployment of specialized Helm charts on a k3s cluster. These are deployed and managed via the TrueNAS SCALE's Web UI.
TrueCharts - a community repository of TrueNAS SCALE Apps, specifically their Enterprise train, introduce very robust implementations relying (among other things) of CloudNative PostgreSQL databases, with very robust and stable database deployments, even when running on a single node.
One of those apps, is Vaultwarden.
When migrating data from external sources, this presents challanges, as external access to these databases isn't straigh forward, and mainpulating k3s directly, isn't officially supported.
The migration process below was adapted from the steps published in the migration guide in the wiki while addressing the requirements of this envronment without breaking any rules that would deem the installation unsupported.
Migration process
Overview of the process:
vaultwarden
app on TrueNAS SCALE.Full details are provided below.
Tools / Prerequisites
The prerequisites for a successful process:
pgloader
installedheavyscript
installed - this is used to start and stop TrueChart apps.(back to overview)
Step 1: Install a fresh
vaultwarden
app on TrueNAS SCALEtcdbinfo.sh
script to extract the db credentials. Here is an adapted version I made for myself, it is based on TrueChart's tcdbinfo.sh.* When using
--force
with my version, you can use the superadmin user (named postgres), instead of just app user.cnpg
going forward) and perform a Backup of thevaultwarden
database (namedcnpg-blank-backup-db
in this doc), as well as the server's globals* (namedcnpg-backup-globals
) (the globals define the roles assigned to thecnpg
).* will require connecting with
postgres
user (see # 2 above).(back to overview)
Step 2: Create a temporary PostgreSQL and initialize it
Start a PostgreSQL container (name in doc:
temp-pg
) with the following command:* NOTE:
cpgn
runs PostgreSQL 15.3, that's why I've chosenpostgres:15.3
From pgAdmin, connect to
temp-pg
.[optional] Restore the roles* from the globals backup - this is a manual process of loading the backup file into the Query Tool when connected to the postgres database on
temp-pg
.* Will require
postgress
user, see # 2.* NOTE: This will reset the password of the users, and you'll need to disconnect and reconnect using the
cpng
credentials from this point forward.Created a new
tmp-vw-db
db, assigned to thevaultwarden
role. (role assignment is optional)Restore
cnpg-blank-backup
intotmp-vw-db
, using the following options:Privileges + Comments + Subscriptions + Table access methods
At this point, You should have an initialized vaultwarden PostgreSQL database that is accessible from the old host.
(back to overview)
Step 3: Migrate the SQLite db into the temporary PostgreSQL database
Per the migration wiki, it time to use
pgloader
.Prep a
migration.pgloader
file with the following content:* NOTE: change the
from
andinto
to match your deployment.Stop the source vaultwarden docker container.
Run
pgloader ./migration.pgloader
. (See Appendix section below for example output)(back to overview)
Step 4: Migrate the data from the temporary PostgreSQL db into the app's database
With the data in the
tmp-vw-db
PostgreSQL db, it's time to transfer everything to thevaultwarden
db oncnpg
.This involved using
pgAdmin
again.tmp-vw-db
, named ittmp-vw-db-backup
__diesel_schema_migrations
fromtmp-vw-db
(per migration wiki we don't load it anyways, and if it is preset during restore, the restore breaks).tmp-vw-db
, named itvw-migration
vaultwarden
oncpng
fromvw-migration
, using the following options:Privileges + Comments + Subscriptions + Table access methods
(back to overview)
Step 5: Finalize migration
(back to overview)
Appendix
example pgloader output
(click to expand)Beta Was this translation helpful? Give feedback.
All reactions