| Locally mirror your Joomla website |
|
| Sunday, 18 October 2009 08:41 |
|
In much the same way as I used scripts to mirror my WordPress blog to my local machine, I use the following procedure to backup the Joomla folders on my remote VPS and restore them to my local system. Before you start, you'll need two pre-requisites to make sure the process is smooth.
The backupOn the server machine, you'll need the following script called "backup-joomla", which I've placed in a folder called scripts under the home folder of the backup user account. Replace <root> with the root password for the MySQL database, <password> with the password and finally <database> with the name of the joomla database, most likely "joomla". #!/usr/bin/env bash This uses mysqldump to write the joomla database to an SQL file, then creates two bzip2 compressed files, on containing the SQL we've just dumped and the second the complete directory structure for the joomla web application. Both files are placed into the /tmp folder with known filenames where the client machine can find them to download in the second part of the backup process. Don't forget to set the execute using the following command. chmod u+x backup-joomla On the client machine, you'll need the following script also called backup-joomla, which I've placed into the scripts folder under my home account. Replace <user> with the name of the user that you've shared the SSH public key with on the server, and <server> with the URL or IP address of your remote machine, and <backup folder> with the folder on your local machine that you want to store your backups in. #!/usr/bin/env bash The script simply executes backup-joomla on the server then copies the resulting bzip2 files to the local temp folder using scp. I chose bzip2 from amongst tar's support compression algorithms because it compresses better than the others on offer, though it is potentially slower to compress and more taxing on the CPU. The final step is to rename the files to include the create date and time as part of the file in order to keep multiple snapshots of the database in the same location. The restoreWith the backup safely copied to your local machine, it's now time to restore it, which involves adding the following script, restore-joomla, to your scripts folder. As with the previous scripts, <backup_path> is the folder where you store your joomla backup files, <local www> is the folder into which you'd like your local copy of Joomla to be installed, while <db_user>, <db_password> and <db_name> are the credentials necessary to connect to your local MySQL install. #!/usr/bin/env bash This script will find the most recent database and Joomla files that have been downloaded from the server, then extract and install them. The latter part of the script is used to tweak the Joomla configuration.php file so that it doesn't use "pretty" URLs, and to re-point the log and tmp folders to their new locations. There are still additional things that could be done, such as disabling any plugins that might send data to online servers, but apart from that, you've now got a local mirror of your Joomla server, which you can use to develop, debug or just try things out on. If you now navigate to your local Joomla folder in your browser of choice, you should be looking at a clone of your remote server. blog comments powered by Disqus |
