My current project is to learn to set up the whole Drupal installation again from scratch It is vital that anyone running a Drupal installation knows how to do this. I am currently learning it now, so will blog my progress.
There are four main reasons why you should know how to restore a Drupal installation:
- If you upgrade your Drupal CMS to the latest version, it is advisable to create a copy that you can use if the upgrade goes disastrously wrong – i.e. you lose your database and old files.
- If your server dies, or you decide to change webhost, then you will have to know how to do this, otherwise you will be paying someone a lot of money to install your Drupal CMS site for you.
- If hackers destroy your site, you will need to be able to quickly revert to a previous saved version.
- If you wish to create a test site of your Drupal installation, for testing new modules and templates, then making a copy is essential. Really your should never test in a live environment.
I seen several examples of one of the above happening at some point during my short time playing about on the web. I have seen a well respected SEO Forum disappear due to lack of backup. I have seen a Drupal install destroyed by hackers – at least the database was taken down, and with such a CMS, the database is everything.
So, how do you backup Drupal and then install?
Currently for backup, I am using a module which backs up all the files and the database into one tar.gz file. The easiest way to restore the files, is simply to FTP the gar.tz file to the server, then SSH using PuTTy to the command directory, and type in the command line:
tar -xvvzf drupalbackup.tar.gz
This will extract all the files, and also the drupal-backup.sql.gz
If you are only moving the location of you site, i.e. moving from domain1 to domain2, or from www.domain to subdomain.domain, then this is all that is actually required, as the same database will be used. Go to the new domain, and your site should be working as normal, just under a different name. Remember that now you have two domains using the same database.
Things to consider:
- Ensure that you do not link to the site anywhere, and if you have Google Adsense on the site, remove it for now. If the search engines find the new site, then you will be penalised for having duplicate content. When not testing / using the site, put it into Site maintenance. If you are restoring a whole site after a host move, this is obviously not required.
- Also remember that both domains are usign the same database at the moment, so don’t get excited and start installing and testing new modules yet!
However, if you lost your database, or have moved to a new host, then you will need to now extract and import the database files also. I have used phpmyadmin for importing database files in the past, but there are often problems for larger files. So I plan to master the mysql command line also, but first, I wish to see if I can do it with phpmyadmin.
First, in phpmyadmin, create a new database. Then, edit the Drupal config files to read the new database.
This file may have been set to read-only by the Drupal installation program. If you make changes to this file, be sure to protect it again after making your modifications. Failure to remove write permissions to this file is a security risk. i.e. it should be read–read–read, or 444.
The file only has two lines (apart from the comments, which make up most of the file).
$db_url = ‘mysql://account:password@localhost/dbname’;
$db_prefix = ”;
All you need to do is change he dbname to the newly created database that you have just made in phpmyadmin. The account and password will obviously be your MySQL account and password.
Be sure that you have uploaded your new settings.php file. As the file is set to read only, then you may not be able to simply FTP the new one over and replace. First, delete the file on the server. If you refresh your test/new website at this point, you will see “Unsupported database type” in the browser. On uploading the new settings.php file, and refreshing the browser, you should now see a blank page. This is proof that the database is not being read.
So, now we are ready to import the new database (the backup). Once this is done, you have a playground for testing, or a new permanent home for your site.