vstemen's picture

Hi.  After copying a backdrop site I get this error,

Exception: The configuration directory in settings.php is specified as './files/config_3eec97628240b19705913a4af7f7fac3/active', but this directory is either empty or missing crucial files. Check that the $config_directories variable is correct in settings.php. in _backdrop_bootstrap_configuration() (line 3020 of /data/htdocs/backdrop-sites/test2/core/includes/bootstrap.inc).

The site copy is done via a perl script, that I wrote, that I have been using for years for both drupal and backdropcms without problems. It makes an exact copy of all the site files to a new web root directory, updates the database setting in settings.php, and copies the database by dumping it from the src site and reading it back into the destination site's database.

I use it for staging production web sites sites and duplicating development sites.

settings.php contains

$config_directories['active'] = 'files/config_' . md5($database) . '/active';
$config_directories['staging'] = 'files/config_' . md5($database) . '/staging';

config_3eec97628240b19705913a4af7f7fac3/ is not the directory name of the config directory that gets copied. If I hard code settings.php on the new site with the $config_directories settings set to the actual directory name rather than using "md5($database)", the new site works just fine.

Apparently the md5() function is generating a new directory name hash and not using the existing one.

So my question is, why is it generating a new hash rather than continuing to run with the existing one on the new site while it works just fine on the old site? All the files are identical and the database is identical. I even dumped both databases and diffed them after doing the site copy to verify, and they are identical other than the database name defined at the top of the SQL dump file.

Software versions
------------------------
OS: FreeBSD 12.2-RELEASE
Backdrop version: 1.17.4
PHP version: 7.2.33
mysql version: 5.7.31
 

Accepted answer

If it's on the same server then I assume it's using a different database...? If so, that'll mean a different hash between the two sites.

When Backdrop is installed, it'll change the hash code in settings.php to be the hard-coded value of the hash. If your old site has a hard-coded value in settings.php then your script can copy that to the new site.

Alternatively, you can ditch the hashed config directory names altogether and set a different default value in the default settings.php if you like. Then your site migrations will be the same. We recently added .htaccess files to protect the config directory, so securing them by obscuring the directory name is no longer needed.

Comments

settings.php uses a hash of the database connection details for the config directory by default, but you can and should change this if you have an existing config directory already in-use. It sounds like you just need to update your Perl script to set the config directory as well as the database.

vstemen's picture

Thanks for the quick response.

Yes, that is what I was thinking that I may have to do. I wanted to make sure that I was not overlooking something before putting the work into doing that. What I was trying to understand is, with all the files and the database identical, what triggers it to create a new directory hash on the new site when it does not do that on the old site?

I can understand it generating a new hash on a new install where the config directory does not even exist yet. But with everything identical to the old site, how does it even know it is running on a new site? The only difference is that the web server is loading it from a different root directory.

If it's on the same server then I assume it's using a different database...? If so, that'll mean a different hash between the two sites.

When Backdrop is installed, it'll change the hash code in settings.php to be the hard-coded value of the hash. If your old site has a hard-coded value in settings.php then your script can copy that to the new site.

Alternatively, you can ditch the hashed config directory names altogether and set a different default value in the default settings.php if you like. Then your site migrations will be the same. We recently added .htaccess files to protect the config directory, so securing them by obscuring the directory name is no longer needed.

vstemen's picture

Ah!! Vince slaps his forehead. You are right. Thank you BWPanda. I had noticed the $database variable where it calls md5($database), but I didn't look at the $database string closely enough for it to click in my head that it's going to be different because of the different database name.

I run nginx, which does not support .htaccess files. So, I will modify my script to either generate the md5 hash and rename the config_ directory on destination site accordingly, or just make it a fixed name. I haven't decided yet.

Either way, problem solved. I feel a lot better knowing exactly what's happening. I didn't want to make the modifications to my script until I was sure I wasn't overlooking something silly.