Restore database #1138

Closed
opened 2026-02-05 00:04:07 +03:00 by OVERLORD · 8 comments
Owner

Originally created by @gkl1368 on GitHub (Oct 25, 2021).

Today I backup the database from the lastest test docker image, and restore the sql file to other docker. But it always show
the username and password is not correct in the web ui.
And I found it is many errors as below when I restore sql file. Please help.

Warning (Code 150): Create table vaultwarden.folders with foreign key folders_ibfk_1 constraint failed. Field type or character set for column 'user_uuid' does not mach referenced column 'uuid'.
Error (Code 1005): Can't create table vaultwarden.folders (errno: 150 "Foreign key constraint is incorrectly formed")
Warning (Code 1215): Cannot add foreign key constraint for folders
ERROR 1146 (42S02) at line 291: Table 'vaultwarden.folders' doesn't exist
ERROR 1146 (42S02) at line 292: Table 'vaultwarden.folders' doesn't exist
ERROR 1146 (42S02) at line 293: Table 'vaultwarden.folders' doesn't exist
ERROR 1146 (42S02) at line 294: Table 'vaultwarden.folders' doesn't exist
ERROR 1005 (HY000) at line 353: Can't create table vaultwarden.org_policies (errno: 150 "Foreign key constraint is incorrectly formed")
Warning (Code 150): Create table vaultwarden.org_policies with foreign key org_policies_ibfk_1 constraint failed. Field type or character set for column 'org_uuid' does not mach referenced column 'uuid'.
Error (Code 1005): Can't create table vaultwarden.org_policies (errno: 150 "Foreign key constraint is incorrectly formed")
Warning (Code 1215): Cannot add foreign key constraint for org_policies
ERROR 1146 (42S02) at line 369: Table 'vaultwarden.org_policies' doesn't exist
ERROR 1146 (42S02) at line 370: Table 'vaultwarden.org_policies' doesn't exist
ERROR 1146 (42S02) at line 371: Table 'vaultwarden.org_policies' doesn't exist
ERROR 1005 (HY000) at line 381: Can't create table vaultwarden.organizations (errno: 150 "Foreign key constraint is incorrectly formed")
Error (Code 1005): Can't create table vaultwarden.organizations (errno: 150 "Foreign key constraint is incorrectly formed")
Warning (Code 1215): Cannot add foreign key constraint for organizations
ERROR 1146 (42S02) at line 395: Table 'vaultwarden.organizations' doesn't exist
ERROR 1146 (42S02) at line 396: Table 'vaultwarden.organizations' doesn't exist
ERROR 1146 (42S02) at line 397: Table 'vaultwarden.organizations' doesn't exist
ERROR 1146 (42S02) at line 398: Table 'vaultwarden.organizations' doesn't exist
ERROR 1005 (HY000) at line 408: Can't create table vaultwarden.sends (errno: 150 "Foreign key constraint is incorrectly formed")
Warning (Code 150): Create table vaultwarden.sends with foreign key sends_ibfk_1 constraint failed. Field type or character set for column 'user_uuid' does not mach referenced column 'uuid'.

Originally created by @gkl1368 on GitHub (Oct 25, 2021). Today I backup the database from the lastest test docker image, and restore the sql file to other docker. But it always show the username and password is not correct in the web ui. And I found it is many errors as below when I restore sql file. Please help. Warning (Code 150): Create table `vaultwarden`.`folders` with foreign key `folders_ibfk_1` constraint failed. Field type or character set for column 'user_uuid' does not mach referenced column 'uuid'. Error (Code 1005): Can't create table `vaultwarden`.`folders` (errno: 150 "Foreign key constraint is incorrectly formed") Warning (Code 1215): Cannot add foreign key constraint for `folders` ERROR 1146 (42S02) at line 291: Table 'vaultwarden.folders' doesn't exist ERROR 1146 (42S02) at line 292: Table 'vaultwarden.folders' doesn't exist ERROR 1146 (42S02) at line 293: Table 'vaultwarden.folders' doesn't exist ERROR 1146 (42S02) at line 294: Table 'vaultwarden.folders' doesn't exist ERROR 1005 (HY000) at line 353: Can't create table `vaultwarden`.`org_policies` (errno: 150 "Foreign key constraint is incorrectly formed") Warning (Code 150): Create table `vaultwarden`.`org_policies` with foreign key `org_policies_ibfk_1` constraint failed. Field type or character set for column 'org_uuid' does not mach referenced column 'uuid'. Error (Code 1005): Can't create table `vaultwarden`.`org_policies` (errno: 150 "Foreign key constraint is incorrectly formed") Warning (Code 1215): Cannot add foreign key constraint for `org_policies` ERROR 1146 (42S02) at line 369: Table 'vaultwarden.org_policies' doesn't exist ERROR 1146 (42S02) at line 370: Table 'vaultwarden.org_policies' doesn't exist ERROR 1146 (42S02) at line 371: Table 'vaultwarden.org_policies' doesn't exist ERROR 1005 (HY000) at line 381: Can't create table `vaultwarden`.`organizations` (errno: 150 "Foreign key constraint is incorrectly formed") Error (Code 1005): Can't create table `vaultwarden`.`organizations` (errno: 150 "Foreign key constraint is incorrectly formed") Warning (Code 1215): Cannot add foreign key constraint for `organizations` ERROR 1146 (42S02) at line 395: Table 'vaultwarden.organizations' doesn't exist ERROR 1146 (42S02) at line 396: Table 'vaultwarden.organizations' doesn't exist ERROR 1146 (42S02) at line 397: Table 'vaultwarden.organizations' doesn't exist ERROR 1146 (42S02) at line 398: Table 'vaultwarden.organizations' doesn't exist ERROR 1005 (HY000) at line 408: Can't create table `vaultwarden`.`sends` (errno: 150 "Foreign key constraint is incorrectly formed") Warning (Code 150): Create table `vaultwarden`.`sends` with foreign key `sends_ibfk_1` constraint failed. Field type or character set for column 'user_uuid' does not mach referenced column 'uuid'.
Author
Owner

@gkl1368 commented on GitHub (Oct 25, 2021):

And I have try add SET FOREIGN_KEY_CHECKS=OFF at top of sql file, and then the import has no errors. I have see the org and user in the admin page. And all item is right. But I can't login the webui and all client, It shows vaultwarden::api::identity][ERROR] Username or password is incorrect. Try again.

Your environment (Generated via diagnostics page)

  • Vaultwarden version: v1.22.2-f94ac6ca
  • Web-vault version: v2.23.0c
  • Running within Docker: true (Base: Debian)
  • Environment settings overridden: true
  • Uses a reverse proxy: true
  • IP Header check: true (X-Real-IP)
  • Internet access: true
  • Internet access via a proxy: false
  • DNS Check: true
  • Time Check: true
  • Domain Configuration Check: true
  • HTTPS Check: true
  • Database type: MySQL
  • Database version: 10.6.4-MariaDB-1:10.6.4+maria~focal
  • Clients used:
  • Reverse proxy and version:
  • Other relevant information:

Config (Generated via diagnostics page)

Show Running Config

Environment settings which are overridden: DOMAIN, SIGNUPS_ALLOWED, INVITATIONS_ALLOWED, ADMIN_TOKEN

{
  "_duo_akey": null,
  "_enable_duo": false,
  "_enable_email_2fa": true,
  "_enable_smtp": true,
  "_enable_yubico": true,
  "_ip_header_enabled": true,
  "admin_token": "***",
  "allowed_iframe_ancestors": "",
  "attachments_folder": "data/attachments",
  "authenticator_disable_time_drift": false,
  "data_folder": "data",
  "database_max_conns": 10,
  "database_url": "*****://***********:****************@**************/***********",
  "db_connection_retries": 15,
  "disable_2fa_remember": false,
  "disable_admin_token": false,
  "disable_icon_download": false,
  "domain": "*****://*****.******.**",
  "domain_origin": "*****://*****.******.**",
  "domain_path": "",
  "domain_set": true,
  "duo_host": null,
  "duo_ikey": null,
  "duo_skey": null,
  "email_attempts_limit": 3,
  "email_expiration_time": 600,
  "email_token_size": 6,
  "emergency_access_allowed": true,
  "emergency_notification_reminder_schedule": "0 5 * * * *",
  "emergency_request_timeout_schedule": "0 5 * * * *",
  "enable_db_wal": true,
  "extended_logging": true,
  "helo_name": null,
  "hibp_api_key": null,
  "icon_blacklist_non_global_ips": true,
  "icon_blacklist_regex": null,
  "icon_cache_folder": "data/icon_cache",
  "icon_cache_negttl": 259200,
  "icon_cache_ttl": 2592000,
  "icon_download_timeout": 10,
  "invitation_org_name": "iKelly Corp.",
  "invitations_allowed": true,
  "ip_header": "X-Real-IP",
  "job_poll_interval_ms": 30000,
  "log_file": "/data/vaultwarden.log",
  "log_level": "warn",
  "log_timestamp_format": "%Y-%m-%d %H:%M:%S.%3f",
  "org_attachment_limit": null,
  "org_creation_users": "",
  "password_iterations": 100000,
  "reload_templates": false,
  "require_device_email": false,
  "rsa_key_filename": "data/rsa_key",
  "send_purge_schedule": "0 5 * * * *",
  "sends_allowed": true,
  "sends_folder": "data/sends",
  "show_password_hint": true,
  "signups_allowed": false,
  "signups_domains_whitelist": "",
  "signups_verify": false,
  "signups_verify_resend_limit": 6,
  "signups_verify_resend_time": 3600,
  "smtp_accept_invalid_certs": false,
  "smtp_accept_invalid_hostnames": false,
  "smtp_auth_mechanism": null,
  "smtp_debug": false,
  "smtp_explicit_tls": true,
  "smtp_from": "*********@******.**",
  "smtp_from_name": "Bitwarden_RS",
  "smtp_host": "**.******.**",
  "smtp_password": "***",
  "smtp_port": 465,
  "smtp_ssl": true,
  "smtp_timeout": 15,
  "smtp_username": "*****@******.**",
  "templates_folder": "data/templates",
  "trash_auto_delete_days": 30,
  "trash_purge_schedule": "0 5 0 * * *",
  "use_syslog": false,
  "user_attachment_limit": null,
  "web_vault_enabled": true,
  "web_vault_folder": "web-vault/",
  "websocket_address": "0.0.0.0",
  "websocket_enabled": true,
  "websocket_port": 3012,
  "yubico_client_id": "55250",
  "yubico_secret_key": "***",
  "yubico_server": null
}
@gkl1368 commented on GitHub (Oct 25, 2021): And I have try add SET FOREIGN_KEY_CHECKS=OFF at top of sql file, and then the import has no errors. I have see the org and user in the admin page. And all item is right. But I can't login the webui and all client, It shows vaultwarden::api::identity][ERROR] Username or password is incorrect. Try again. ### Your environment (Generated via diagnostics page) * Vaultwarden version: v1.22.2-f94ac6ca * Web-vault version: v2.23.0c * Running within Docker: true (Base: Debian) * Environment settings overridden: true * Uses a reverse proxy: true * IP Header check: true (X-Real-IP) * Internet access: true * Internet access via a proxy: false * DNS Check: true * Time Check: true * Domain Configuration Check: true * HTTPS Check: true * Database type: MySQL * Database version: 10.6.4-MariaDB-1:10.6.4+maria~focal * Clients used: * Reverse proxy and version: * Other relevant information: ### Config (Generated via diagnostics page) <details><summary>Show Running Config</summary> **Environment settings which are overridden:** DOMAIN, SIGNUPS_ALLOWED, INVITATIONS_ALLOWED, ADMIN_TOKEN ```json { "_duo_akey": null, "_enable_duo": false, "_enable_email_2fa": true, "_enable_smtp": true, "_enable_yubico": true, "_ip_header_enabled": true, "admin_token": "***", "allowed_iframe_ancestors": "", "attachments_folder": "data/attachments", "authenticator_disable_time_drift": false, "data_folder": "data", "database_max_conns": 10, "database_url": "*****://***********:****************@**************/***********", "db_connection_retries": 15, "disable_2fa_remember": false, "disable_admin_token": false, "disable_icon_download": false, "domain": "*****://*****.******.**", "domain_origin": "*****://*****.******.**", "domain_path": "", "domain_set": true, "duo_host": null, "duo_ikey": null, "duo_skey": null, "email_attempts_limit": 3, "email_expiration_time": 600, "email_token_size": 6, "emergency_access_allowed": true, "emergency_notification_reminder_schedule": "0 5 * * * *", "emergency_request_timeout_schedule": "0 5 * * * *", "enable_db_wal": true, "extended_logging": true, "helo_name": null, "hibp_api_key": null, "icon_blacklist_non_global_ips": true, "icon_blacklist_regex": null, "icon_cache_folder": "data/icon_cache", "icon_cache_negttl": 259200, "icon_cache_ttl": 2592000, "icon_download_timeout": 10, "invitation_org_name": "iKelly Corp.", "invitations_allowed": true, "ip_header": "X-Real-IP", "job_poll_interval_ms": 30000, "log_file": "/data/vaultwarden.log", "log_level": "warn", "log_timestamp_format": "%Y-%m-%d %H:%M:%S.%3f", "org_attachment_limit": null, "org_creation_users": "", "password_iterations": 100000, "reload_templates": false, "require_device_email": false, "rsa_key_filename": "data/rsa_key", "send_purge_schedule": "0 5 * * * *", "sends_allowed": true, "sends_folder": "data/sends", "show_password_hint": true, "signups_allowed": false, "signups_domains_whitelist": "", "signups_verify": false, "signups_verify_resend_limit": 6, "signups_verify_resend_time": 3600, "smtp_accept_invalid_certs": false, "smtp_accept_invalid_hostnames": false, "smtp_auth_mechanism": null, "smtp_debug": false, "smtp_explicit_tls": true, "smtp_from": "*********@******.**", "smtp_from_name": "Bitwarden_RS", "smtp_host": "**.******.**", "smtp_password": "***", "smtp_port": 465, "smtp_ssl": true, "smtp_timeout": 15, "smtp_username": "*****@******.**", "templates_folder": "data/templates", "trash_auto_delete_days": 30, "trash_purge_schedule": "0 5 0 * * *", "use_syslog": false, "user_attachment_limit": null, "web_vault_enabled": true, "web_vault_folder": "web-vault/", "websocket_address": "0.0.0.0", "websocket_enabled": true, "websocket_port": 3012, "yubico_client_id": "55250", "yubico_secret_key": "***", "yubico_server": null } ``` </details>
Author
Owner

@topscoder commented on GitHub (Oct 25, 2021):

I was fighting with some sort of issue just yet. In my case:

  • Couldn't login anymore without any known reason
  • Vaultwarden logs said it couldn't open the sqlite file
  • Checked sqlite file local and had no issues
  • Found out /data/.env file was gone
  • Created .env file again, pasted the contents of .env.template from this repo and restarted server.

Et voila 🥳

Some exact log messages for future searches:
[vaultwarden::api::identity][ERROR] Username or password is incorrect. Try again.
[INFO] No .env file found.
[panic][ERROR] thread 'main' panicked at 'Failed to turn on WAL: DatabaseError(__Unknown, "unable to open database file")'

@topscoder commented on GitHub (Oct 25, 2021): I was fighting with some sort of issue just yet. In my case: * Couldn't login anymore without any known reason * Vaultwarden logs said it couldn't open the sqlite file * Checked sqlite file local and had no issues * Found out `/data/.env` file was gone * Created `.env` file again, pasted the contents of [`.env.template`](https://github.com/dani-garcia/vaultwarden/blob/main/.env.template) from this repo and restarted server. Et voila 🥳 Some exact log messages for future searches: `[vaultwarden::api::identity][ERROR] Username or password is incorrect. Try again.` `[INFO] No .env file found.` `[panic][ERROR] thread 'main' panicked at 'Failed to turn on WAL: DatabaseError(__Unknown, "unable to open database file")'`
Author
Owner

@gkl1368 commented on GitHub (Oct 25, 2021):

mylog is
vaultwarden | [2021-10-25 12:30:57.036][vaultwarden::api::identity][ERROR] Username or password is incorrect. Try again. IP: . Username:.
Vaultwarden | [2021-10-25 12:30:57.037][response][INFO] POST /identity/connect/token (login) => 400 Bad Request

All user collections and org is right.
image

@gkl1368 commented on GitHub (Oct 25, 2021): mylog is vaultwarden | [2021-10-25 12:30:57.036][vaultwarden::api::identity][ERROR] Username or password is incorrect. Try again. IP: . Username:. Vaultwarden | [2021-10-25 12:30:57.037][response][INFO] POST /identity/connect/token (login) => 400 Bad Request All user collections and org is right. ![image](https://user-images.githubusercontent.com/12904884/138698159-6df45488-2643-4aeb-a648-efc32b7b9905.png)
Author
Owner

@avoidik commented on GitHub (Oct 26, 2021):

same, all of a sudden getting invalid master password error for a perfectly valid master password on the latest vaultwarden install for new logins, while existing connections are fine (I now afraid to logout on mobile to not lose db)

@avoidik commented on GitHub (Oct 26, 2021): same, all of a sudden getting invalid master password error for a perfectly valid master password on the latest vaultwarden install for new logins, while existing connections are fine (I now afraid to logout on mobile to not lose db)
Author
Owner

@BlackDex commented on GitHub (Oct 26, 2021):

If using MySQL then there could be an issue with the charset and collation, see #1559 .

If using Sqlite and you get a WAL error after restoring the file from a backup, then it could be the backup is faulty, you should never just copy the file while it is in use. This could break the database, and thus could break your login.

@BlackDex commented on GitHub (Oct 26, 2021): If using MySQL then there could be an issue with the charset and collation, see #1559 . If using Sqlite and you get a WAL error after restoring the file from a backup, then it could be the backup is faulty, you should never just copy the file while it is in use. This could break the database, and thus could break your login.
Author
Owner

@gkl1368 commented on GitHub (Oct 26, 2021):

If using MySQL then there could be an issue with the charset and collation, see #1559 .

If using Sqlite and you get a WAL error after restoring the file from a backup, then it could be the backup is faulty, you should never just copy the file while it is in use. This could break the database, and thus could break your login.

I use MySQL,and SET FOREIGN_KEY_CHECKS=OFF before restore old MySQL backup, at this step, it's no error. I can see orgs,users and collections in admin page. But I can't login with all clients include Web.

@gkl1368 commented on GitHub (Oct 26, 2021): > If using MySQL then there could be an issue with the charset and collation, see #1559 . > > > > If using Sqlite and you get a WAL error after restoring the file from a backup, then it could be the backup is faulty, you should never just copy the file while it is in use. This could break the database, and thus could break your login. I use MySQL,and SET FOREIGN_KEY_CHECKS=OFF before restore old MySQL backup, at this step, it's no error. I can see orgs,users and collections in admin page. But I can't login with all clients include Web.
Author
Owner

@gkl1368 commented on GitHub (Oct 26, 2021):

same, all of a sudden getting invalid master password error for a perfectly valid master password on the latest vaultwarden install for new logins, while existing connections are fine (I now afraid to logout on mobile to not lose db)

I will try change to old docker image, It also don't work when use old image.

@gkl1368 commented on GitHub (Oct 26, 2021): > same, all of a sudden getting invalid master password error for a perfectly valid master password on the latest vaultwarden install for new logins, while existing connections are fine (I now afraid to logout on mobile to not lose db) I will try change to old docker image, It also don't work when use old image.
Author
Owner

@gkl1368 commented on GitHub (Oct 27, 2021):

I have restore a backup json file to new instance. It's worked good.

@gkl1368 commented on GitHub (Oct 27, 2021): I have restore a backup json file to new instance. It's worked good.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/vaultwarden#1138