Several of my Web sites are implemented using the Joomla! content management system.

Unfortunately support for Joomla! 3.x is coming to an end. Upgrading to Joomla! 4.x is not trivial.

To this effect, I wanted to make sure that I have a reliable way to create a test copy of the site before messing with the "production" site. I thought this was going to be difficult but no, it was reasonably straightforward.

First, in MySQL, I created an alternate database for testing.

CREATE DATABASE joomla_test;

Next I used mysqldump from the command line to dump the tables with the right prefix from the old database. Say, the site's tables started with "mysite_":

mysqldump -u root -p joomla $(mysql -u root -p joomla -Nse "SHOW TABLES LIKE 'mysite_%'") > dump.sql

Next, I loaded these tables into the new database:

mysql -u root -p joomla_test < dump.sql

Going back to mysql, I created a new user and assigned to this user the requisite privileges to access to new database (NB: In my case, I just reused the existing password hash used for the "production" user ID):

GRANT USAGE ON *.* TO `joomlatest`@`%` IDENTIFIED BY PASSWORD '*...';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX,
ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW,
SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE ON `joomla_test`.* TO `joomlatest`@`%`;
FLUSH PRIVILEGES;

Next, I actually copied the entire site from the command line, e.g.,:

cp -avi CMS/ CMSTEST/

Finally, I went into the Joomla configuration file (configuration.php) and changed these two lines:

public $user = 'joomlatest';
public $db = 'joomla_test';

That's it! The backup site was ready for testing.