diff --git a/src/metabase/cmd/copy.clj b/src/metabase/cmd/copy.clj
index e313a698e9ae3810139200a84fa2995565f981be..a3677eb44be93d5557fe88df56c1a2480be8fb7a 100644
--- a/src/metabase/cmd/copy.clj
+++ b/src/metabase/cmd/copy.clj
@@ -158,11 +158,11 @@
     ;; Sample Database, the correct details are reset automatically on every
     ;; launch (see [[metabase.sample-data/update-sample-database-if-needed!]]), and we don't support connecting other H2
     ;; Databases in prod anyway, so this ultimately shouldn't cause anyone any problems.
-    (if *copy-h2-database-details*
-      identity
-      (map (fn [database]
-             (cond-> database
-               (= (:engine database) "h2") (assoc :details "{}")))))
+    (map (fn [database]
+           (cond-> database
+             (or (:is_attached_dwh database)
+                 (and (not *copy-h2-database-details*)
+                      (= (:engine database) "h2"))) (assoc :details "{}"))))
     :model/Setting
     ;; Never create dumps with read-only-mode turned on.
     ;; It will be confusing to restore from and prevent key rotation.
diff --git a/test/metabase/cmd/dump_to_h2_test.clj b/test/metabase/cmd/dump_to_h2_test.clj
index 884a12cbade4df8cb2ea7d7944af1cb488d54bbe..710b8c7906b4dfd26364c3b3ef4208d6243c28f5 100644
--- a/test/metabase/cmd/dump_to_h2_test.clj
+++ b/test/metabase/cmd/dump_to_h2_test.clj
@@ -107,3 +107,38 @@
                   (is (not (= "{\"db\":\"/tmp/test.db\"}"
                               (:details (first (jdbc/query {:connection target-conn}
                                                            "select details from metabase_database where id=1;")))))))))))))))
+
+(deftest dump-to-h2-dump-is-attached-dwh-test
+  (testing "dump-to-h2 --dump-plaintext with is_attached_dwh"
+    (let [h2-fixture-db-file @cmd.test-util/fixture-db-file-path
+          db-name            (str "test_" (mt/random-name))]
+      (mt/with-temp-file [h2-file (format "out-%s.db" (mt/random-name))]
+        (mt/test-drivers #{:h2 :postgres :mysql}
+          (with-redefs [i18n.impl/site-locale-from-setting (constantly nil)]
+            (binding [config/*disable-setting-cache*  true
+                      mdb.connection/*application-db* (mdb.connection/application-db
+                                                       driver/*driver*
+                                                       (persistent-data-source driver/*driver* db-name))]
+              (when-not (= driver/*driver* :h2)
+                (tx/create-db! driver/*driver* {:database-name db-name}))
+              (binding [copy/*copy-h2-database-details* true]
+                (load-from-h2/load-from-h2! h2-fixture-db-file)
+                (encryption-test/with-secret-key "89ulvIGoiYw6mNELuOoEZphQafnF/zYe+3vT+v70D1A="
+                  (t2/insert! Database {:engine          "h2"
+                                        :name            "normal-db"
+                                        :details         {:db "/tmp/test.db"}
+                                        :is_attached_dwh false})
+                  (t2/insert! Database {:engine          "h2"
+                                        :name            "attached-dwh"
+                                        :details         {:db "/tmp/test.db"}
+                                        :is_attached_dwh true})
+                  (dump-to-h2/dump-to-h2! h2-file {:dump-plaintext? true})))
+              (with-open [target-conn (.getConnection (copy.h2/h2-data-source h2-file))]
+                (testing "preserves details when is_attached_dwh is not set"
+                  (is (= "{\"db\":\"/tmp/test.db\"}"
+                         (:details (first (jdbc/query {:connection target-conn}
+                                                      "select details from metabase_database where name='normal-db';"))))))
+                (testing "preserves details when is_attached_dwh is not set"
+                  (is (= "{}"
+                         (:details (first (jdbc/query {:connection target-conn}
+                                                      "select details from metabase_database where name='attached-dwh';"))))))))))))))