Skip to content

[5.x]: Database Backup (Postgres) fails if password contains special characters. #17158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FabianRutishauser opened this issue Apr 23, 2025 · 2 comments
Labels

Comments

@FabianRutishauser
Copy link

FabianRutishauser commented Apr 23, 2025

What happened?

Description

When generating a database backup from the ui and the CRAFT_DB_PASSWORD is set to a string containing "!" (exlamation mark) or "`" (backtick), then the backup (in the admin ui) fails. In the logs we can find the reason:

2025-04-23 12:34:00 [web.ERROR] [yii\base\Exception] Could not create backup: The shell command "PGPASSWORD="password-containing-backtick-or-!-somewhere" pg_dump '--dbname'='db-name' '--host'='host' '--port'='5432' '--username'='user' '--if-exists' '--clean' '--no-owner' '--no-privileges' '--no-acl' '--file'='filepath' '--schema'='public' '--exclude-table-data' 'public.assetindexdata' '--exclude-table-data' 'public.cache' '--exclude-table-data' 'public.imagetransformindex' '--exclude-table-data' 'public.resourcepaths' '--exclude-table-data' 'public.phpsessions' '--exclude-table-data' 'public.sessions'" failed with exit code 2: sh: 1: Syntax error: EOF in backquote substitution {"trace":["#0 [internal function]: craft\\controllers\\UtilitiesController->actionDbBackupPerformAction()","#1 /home/site/wwwroot/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)","#2 /home/site/wwwroot/vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams(Array)","#3 /home/site/wwwroot/vendor/yiisoft/yii2/base/Module.php(552): yii\\base\\Controller->runAction('db-backup-perfo...', Array)","#4 /home/site/wwwroot/vendor/craftcms/cms/src/web/Application.php(361): yii\\base\\Module->runAction('utilities/db-ba...', Array)","#5 /home/site/wwwroot/vendor/craftcms/cms/src/web/Application.php(660): craft\\web\\Application->runAction('utilities/db-ba...', Array)","#6 /home/site/wwwroot/vendor/craftcms/cms/src/web/Application.php(323): craft\\web\\Application->_processActionRequest(Object(craft\\web\\Request))","#7 /home/site/wwwroot/vendor/yiisoft/yii2/base/Application.php(384): craft\\web\\Application->handleRequest(Object(craft\\web\\Request))","#8 /home/site/wwwroot/web/index.php(12): yii\\base\\Application->run()","#9 {main}"],"memory":2918072,"exception":"[object] (yii\\base\\Exception(code: 0): Could not create backup: The shell command \"PGPASSWORD=\"password-containing-backtick-or-!-somewhere\" pg_dump '--dbname'='db-name' '--host'='host' '--port'='5432' '--username'='user' '--if-exists' '--clean' '--no-owner' '--no-privileges' '--no-acl' '--file'='filename' '--schema'='public' '--exclude-table-data' 'public.assetindexdata' '--exclude-table-data' 'public.cache' '--exclude-table-data' 'public.imagetransformindex' '--exclude-table-data' 'public.resourcepaths' '--exclude-table-data' 'public.phpsessions' '--exclude-table-data' 'public.sessions'\" failed with exit code 2: sh: 1: Syntax error: EOF in backquote substitution at /home/site/wwwroot/vendor/craftcms/cms/src/controllers/UtilitiesController.php:256)"}

The backtick triggers this error. When i remove it then i face another problem: the exclamation mark: In bash this is interpreted as event. If i enter "!Test" as password, then i get the error -bash: !Test: event not found

Steps to reproduce

  1. Setup craft with a postgres-db
  2. Choose a password with backtick or exclamation mark
  3. Do a database-backup via admin-ui

Expected behavior

The special characters should be escaped properly when the command is concatinated.

Actual behavior

The special characters are not properly escaped.

Craft CMS version

5.7.2

PHP version

8.2

Operating system and version

Debian GNU/Linux 11 (bullseye)

Database type and version

Postgres 15.12

Image driver and version

No response

Installed plugins and versions

  • craftcms/ckeditor: 4.7.0
  • verbb/field-manager: 4.0.3
  • verbb/zen 2.0.4
@brandonkelly
Copy link
Member

Thanks for reporting that! Craft 4.15.2 and 5.7.3 are out with a fix.

@FabianRutishauser
Copy link
Author

Successfully tested :) Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants