umbraco-cloud-fetch-database
v0.3.0
Published
Wizard-based CLI that downloads an Umbraco Cloud database and replaces the LocalDB .mdf/.ldf files in a local Umbraco ASP.NET Core project.
Downloads
780
Maintainers
Readme
umbraco-cloud-fetch-database
Wizard-based CLI for downloading a database from Umbraco Cloud and replacing the LocalDB .mdf / .ldf files of an existing local Umbraco ASP.NET Core project.
Windows-only. LocalDB is a Windows feature; the tool refuses to run elsewhere.
What it does
Run from inside your Umbraco web project (the folder that contains *.csproj):
npx umbraco-cloud-fetch-database@latestThe wizard:
- Verifies you are inside an Umbraco web project.
- Lets you pick an
appsettings.*.json(defaultappsettings.Development.json). - Detects how LocalDB is configured:
- via
ConnectionStrings:umbracoDbDSNcontaining(LocalDB)andAttachDbFileName=..., or - via
Umbraco:Deploy:Settings:PreferLocalDbConnectionString = true(expectsumbraco/Data/Umbraco.mdf).
- via
- Verifies the existing
.mdf/.ldffiles exist and are not locked. - Prompts for server / login / password / database of the source (cloud) database.
- Shows a summary and asks for confirmation.
- Ensures
sqlpackageis available (auto-downloads to%USERPROFILE%\.umbraco-cloud-fetch-database\bin\sqlpackage\if not in PATH). - Backs up the existing files to
<dataDir>/backup/<timestamp>/(keeps the 3 most recent backup folders). - Detaches the local database from
(LocalDB)\MSSQLLocalDB. - Exports a
.bacpacfrom the cloud server withsqlpackage /Action:Export. - Imports the bacpac into LocalDB under a temporary database name with
sqlpackage /Action:Import. - Detaches the temporary database and moves its
.mdf/.ldfto the project's expected paths. - Cleans up the bacpac on success.
Umbraco re-attaches the database on next start because of AttachDbFileName.
Prerequisites
- Windows with SQL Server Express LocalDB installed (
sqllocaldb.exe). sqlcmdin PATH (ships with SQL Server tooling / LocalDB).- Node.js 20+.
sqlpackageis auto-downloaded if not in PATH.- Your Umbraco project must already have a working LocalDB (the
.mdf/.ldfmust exist on disk). Start the project once if needed so Umbraco creates them.
What it changes
- Replaces the existing
.mdfand.ldffiles at the configured path. - Creates
<dataDir>/backup/<timestamp>/with the previous files. Keeps the latest 3. - Caches
sqlpackageunder%USERPROFILE%\.umbraco-cloud-fetch-database\bin\sqlpackage\.
The cloud database password is entered interactively and is never stored.
Releasing (maintainers)
CI is GitHub Actions:
ci.ymlruns build/typecheck on push and PR.release.ymlruns on push tomain. It uses npm Trusted Publishing (OIDC, noNPM_TOKENsecret) and only publishes if the version inpackage.jsonis not already on npm.
To release: bump the version in package.json in a commit, merge to main, done.
License
MIT
