Vaultwarden fails to start after update – DB migration error (SSO)
-
Hello @apesorguk
I have merged your new topic into this one, since it is a duplication.
The fix has already been provided, see above https://forum.cloudron.io/post/117779@james I get this problem.
root@bf8db951-7632-4ddf-bf9b-8b58cd65ffe5:/app/code# bash /app/data/fix_db.sh /app/data/fix_db.sh: line 2: $'\r': command not found => Checking if DEFAULT_CHARACTER_SET_NAME and DEFAULT_COLLATION_NAME are set to utf8mb4 and utf8mb4_unicode_ci /app/data/fix_db.sh: line 4: $'\r': command not found /app/data/fix_db.sh: line 8: $'\r': command not found /app/data/fix_db.sh: line 22: syntax error near unexpected token `$'in\r'' 'app/data/fix_db.sh: line 22: ` case $yn in root@bf8db951-7632-4ddf-bf9b-8b58cd65ffe5:/app/code# -
Hello @factord
This looks like a copy-paste issue from Windows.
\rin line 2 is a blank line, so a line break.
When you copy and pasted, it pasted the line breaks windows style.Please describe how you have copy and pasted the code into the
/app/data/fix_db.shfile.@apesorguk looks like you've hit the same copy-paste issue @james described here:
@james said in Vaultwarden fails to start after update – DB migration error (SSO):
This looks like a copy-paste issue from Windows.
\rin line 2 is a blank line, so a line break.
When you copy and pasted, it pasted the line breaks windows style.Please describe how you have copy and pasted the code into the
/app/data/fix_db.shfile. -
Thanks all fixed now. I found this worked even with the line brake.
I have run the command sed -i 's/\r$//g' /app/data/fix_db.sh to fix the new line characters and then run bash /app/data/fix_db.sh again and it ran as expected. Disabled recover mode and confirmed things are back to working as expected. -
-
@overholt Very likely you've hit the same thing as this thread. Solution here https://forum.cloudron.io/post/117779
-
I used this issue to improve my aidevops cloudron subagent, and it managed to fix the issue on all instances. More info here for anyone interested to add this to your toolkit:
-
I have run the command
sed -i 's/\r$//g' /app/data/fix_db.shto fix the new line characters and then runbash /app/data/fix_db.shagain and it ran as expected. Disabled recover mode and confirmed things are back to working as expected.@ChristopherMag Thanks, this fixed my issue.
-
I have run the command
sed -i 's/\r$//g' /app/data/fix_db.shto fix the new line characters and then runbash /app/data/fix_db.shagain and it ran as expected. Disabled recover mode and confirmed things are back to working as expected.@ChristopherMag
That worked for me, Thanks. -
Hello @vaultwarden users
Since users have voiced their concerns about manually editing the database I have created a bash script that does it for you.
Please follow these steps if you have this issue:- create an app backup of your @vaultwarden Cloudron app
- put the erroring @vaultwarden app in recovery mode
- open the File Manager of your @vaultwarden app and create a
fix_db.shfile - copy and paste the following script into the just created
fix_db.shfile:#!/bin/bash echo "=> Checking if DEFAULT_CHARACTER_SET_NAME and DEFAULT_COLLATION_NAME are set to utf8mb4 and utf8mb4_unicode_ci" CURRENT_DEFAULT_CHARACTER_SET_NAME=$(mysql --silent --skip-column-names --user=${CLOUDRON_MYSQL_USERNAME} --password=${CLOUDRON_MYSQL_PASSWORD} --host=${CLOUDRON_MYSQL_HOST} ${CLOUDRON_MYSQL_DATABASE} -e "SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = '${CLOUDRON_MYSQL_DATABASE}';" 2>/dev/null) CURRENT_DEFAULT_COLLATION_NAME=$(mysql --silent --skip-column-names --user=${CLOUDRON_MYSQL_USERNAME} --password=${CLOUDRON_MYSQL_PASSWORD} --host=${CLOUDRON_MYSQL_HOST} ${CLOUDRON_MYSQL_DATABASE} -e "SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = '${CLOUDRON_MYSQL_DATABASE}';" 2>/dev/null) FIX_NEEDED=0 if [ "${CURRENT_DEFAULT_CHARACTER_SET_NAME}" != "utf8mb4" ] || [ "${CURRENT_DEFAULT_COLLATION_NAME}" != "utf8mb4_unicode_ci" ]; then echo "=> DEFAULT_CHARACTER_SET_NAME or DEFAULT_COLLATION_NAME is not set to utf8mb4 or utf8mb4_unicode_ci." echo "==> Current values are: DEFAULT_CHARACTER_SET_NAME=${CURRENT_DEFAULT_CHARACTER_SET_NAME}, DEFAULT_COLLATION_NAME=${CURRENT_DEFAULT_COLLATION_NAME}" FIX_NEEDED=1 else echo "=> DEFAULT_CHARACTER_SET_NAME is ${CURRENT_DEFAULT_CHARACTER_SET_NAME} and DEFAULT_COLLATION_NAME is ${CURRENT_DEFAULT_COLLATION_NAME}" echo "=> Nothing to do - quitting." FIX_NEEDED=0 exit 0 fi if [ ${FIX_NEEDED} -eq 1 ]; then read -p "Have you created a backup of your Cloudron Vaultwarden app? (y/N): " yn case $yn in [Yy]* ) echo "=> Setting database character set and collation to utf8mb4 and utf8mb4_unicode_ci." mysql --user=${CLOUDRON_MYSQL_USERNAME} --password=${CLOUDRON_MYSQL_PASSWORD} --host=${CLOUDRON_MYSQL_HOST} ${CLOUDRON_MYSQL_DATABASE} -e "ALTER DATABASE \`${CLOUDRON_MYSQL_DATABASE}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null echo "=> Converting all tables to character set utf8mb4 and collation utf8mb4_unicode_ci." mysql --silent --skip-column-names \ --user="${CLOUDRON_MYSQL_USERNAME}" \ --password="${CLOUDRON_MYSQL_PASSWORD}" \ --host="${CLOUDRON_MYSQL_HOST}" \ "${CLOUDRON_MYSQL_DATABASE}" \ -e "SELECT CONCAT('ALTER TABLE \`', TABLE_NAME,'\` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;') AS CharSetConvert FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='${CLOUDRON_MYSQL_DATABASE}' AND TABLE_TYPE=\"BASE TABLE\";" 2>/dev/null | while read -r sql_command; do echo "==> Executing: ${sql_command}" mysql --user=${CLOUDRON_MYSQL_USERNAME} --password=${CLOUDRON_MYSQL_PASSWORD} --host=${CLOUDRON_MYSQL_HOST} ${CLOUDRON_MYSQL_DATABASE} -e "SET foreign_key_checks=0; ${sql_command} SET foreign_key_checks=1;" 2>/dev/null done ;; [Nn]* ) echo "=> Please create a backup of your database before proceeding with the fix. Exiting." exit 1 ;; * ) echo "=> Invalid response. Please answer with y or n. Exiting." exit 1 ;; esac fi - open the Web Terminal of your @vaultwarden Cloudron app
- execute the following command:
bash /app/data/fix_db.sh - Execute the following command to start @vaultwarden:
/app/pkg/start.sh - Validate if your @vaultwarden is now working correctly
- If validated working, you can delete the
fix_db.shfile and disable the recovery mode of your @vaultwarden Cloudron app
If you run into any issues, copy the output of the terminal, post it here and restore your app from the backup created.
-
I have run the command
sed -i 's/\r$//g' /app/data/fix_db.shto fix the new line characters and then runbash /app/data/fix_db.shagain and it ran as expected. Disabled recover mode and confirmed things are back to working as expected.@ChristopherMag Thank you ! It worked for me