You see “could not change directory to “/root”: Permission denied” when you run zammad_db_user_helper.sh or zammad_restore.sh.
This error appears when you are the root user running a command as a substitute user from the root user’s environment. That command needs run within the substitute user’s environment.
Within “/opt/zammad/contrib/backup/functions”, there are two “su” commands; within “db_helper_alter_user” and “restore_zammad” functions. These commands do not start a new shell and run the commands within the substitute user’s environment. They issue the commands within the root user’s shell and environment.
To fix this, use the “-l” option to start a shell and run the commands in the substitute user’s environment. Change both “su” commands within “/functions”, like below:
function db_helper_alter_user () {
…
su -c "psql -c \"ALTER USER ${DB_USER} WITH PASSWORD '${DB_PASS}';\"" -l postgres
…
}
function restore_zammad () {
…
su -c "psql -c \"CREATE DATABASE ${DB_NAME} OWNER ${DB_USER};\"" -l postgres
…
}