What Needs Backing Up in TYPO3?
We need to back up:
- The TYPO3 files
- A copy of the database
These two things make up our TYPO3 installation. We need the database as it contains the website's content and records of the website's users. We need the TYPO3 files as they contain the website's settings in the configuration files, copies of the website's design, and copies of data that has been cached by TYPO3.
Backing Up the TYPO3 Files
Depending on the operating system we are using, there are a number of different ways in which we can back up the files from TYPO3. In this article, we will look into backing up the files on Windows and on Linux. This is because Windows is the most used operating system, and Linux is the most popular hosting environment for websites.
Backing Up Our Files on Windows
In Windows, we can easily create a compressed file containing all the TYPO3 files (known as a ZIP file), using the Windows Compressed Folder tool, or a program such as WinZip.
Provided we've used the default installation path, TYPO3 will be located in the folder C:Program FilesTypo3_4.0.2Apache and the folder that we want to compress is typo3_src. We could just back up the fileadmin, typo3conf, and uploads folders. This way, should we lose our entire website, we can simply restore the whole thing instead of having to restore TYPO3 and then our extra TYPO3 files.
Now that we have a backup, we should copy it to a separate location (preferably on an external disk, or on another computer) for safe keeping.
Backing Up Our Files on Linux or Linux Hosting
We can create a complete backup of our home directory on a Linux hosting environment. This home directory contains all of our files on the hosting account. Alternatively, we can run a simple command to compress a particular folder.
If we have a web hosting account that provides us with access to the cPanel hosting control panel, we can use that to generate a backup of our entire website (except for the database—which is done separately via cPanel).
To access the backup utilities, we need to log in to cPanel, which is located at www.ourdomain.com/cpanel, and then enter our hosting account's username and password. In cPanel, we have the backup option on the main screen, as shown in the following screenshot:
The Backups section has a number of options, but the one that we want is the Download a home directory Backup. This will generate a backup of all the files of our website and allow us to download it.
In the previous screenshot, there is a warning message. This is because my web server does not have the option to back up the entire server, just an individual
The backup tool then takes a moment or two of processing, and then prompts us to download the backup file.
To create a backup via the command line, we need to have SSH access to the server that is hosting our website. SSH is a protocol that allows us to remotely administer another machine using the command line.
We can use a program such as Putty to connect to the server. We can download Putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/. Putty only needs to be downloaded, after which it can be run straight away, and does not require to be installed.
When we open the program, we are presented with a screen similar to the one shown in the following screenshot. We enter the server's address (i.e. the web address) into the Host Name box and then click on Open.
Putty will then try to connect to the server, and will prompt us to enter our username and password, as shown in the following screenshot:
Once we are connected, we can type two commands to back up our site. The first is to navigate to the folder that contains our TYPO3 installation. This depends entirely on the server's setup and your username, but is generally /home/the first 8 characters of your web address/public_html (you should contact your web host for more information or if you need help).
Once we are in the correct folder, we can use the tar command to compress our TYPO3 folder to a single file named TYPO3.
tar cvzf file.tar.gz typo3
Now that we have our backup created, we can download it from www.ourwebaddress.com/file.tar.gz (where we will be prompted to save the file). We should then delete this from our server once we have downloaded it.
Backing Up the Database
There are three simple ways to back up the database. We can either use the web-based interface, phpMyAdmin, or if we do not have phpMyAdmin and are using a Linux hosting environment, we can run a simple command to export the database to a file that we can download. The final option is to use the cPanel database backup tool on a Linux hosting platform.
phpMyAdmin is something that comes installed with the TYPO3 Winstaller and is installed on most hosting environments. The installation provided by the TYPO3 Winstaller is located at http://localhost/phpMyAdmin/.
From here, we can select the database that we want to back up from the left-hand side drop-down list, and then select the Export option.
We are then taken to a screen that details the structure of the database, and gives us a number of options at the top of the page (as shown in the following screenshot).
We want the Export option, as we are going to export the database to a file.
From the Export window, we can select the tables we wish to export. We should select all of them, and then select the Save as file option, and then either the zipped or gzipped option to save disk space, before pressing the Go button, which will then prompt us to download the database export file. The rest of the options should be left at their default values. If we are going to create a backup that we want to restore on top of an existing installation, we should use the Add DROP TABLE option (to remove the existing information from the database).
We can then save the file, and store it in a secure location, preferably on an external drive, or on a separate machine.
Using Simple Commands
Again using Putty, we can use some simple commands to export the database to a file. Once we have logged in to the server using Putty, we can use the following command:
mysqldump -u username -p databasename > /home/michaelp/public_html/backup.sql
We need to replace username with the MySQL username and databasename with the name of the database. Once we have entered the command and hit the Enter key, we will be prompted for our MySQL password.
The command takes the database and exports it to the file backup.sql in the public_html folder, so we can then download the file from http://www.ourdomain.com/backup.sql. Again, once we have downloaded this backup file we should delete it from the server.
Using the cPanel Utility
To access the backup utilities, we need to log in to cPanel, which is located at www.ourdomain.com/cpanel, and then enter our hosting account's username and password. From here, we have the backup option on the main screen.
The Backups section has a number of options. The one that we want is Download a MySQL Database Backup. Beneath that is a list of the available databases.
From the list, we can select the database that we want to download, and then we will be prompted to save the file at a secure location.
Restoring Your Site from a Backup
Now that we have learned how to back up our websites, we need to look into restoring them; otherwise the backups would be worthless.
Restoring the Files
There are two ways to restore your files: we can unzip them on our computer and import the home directory backup using our hosting control panel, or upload the ZIP file to our website and run a simple command to unpack the files.
Restoring the Files on Windows
We need to extract the files from our backup to our installation of TYPO3, which is at C:Program FilesTypo3_4.0.1Apachetypo3.
Restoring the Files on Linux or Linux Hosting
The easiest method for restoring our files is to restore a complete home directory backup that we have made on our hosting account.
Within the Backups section, we want the Restore a Home Directory Backup area, where we can browse for our backup file and then click on Upload.
This will then completely erase the content of the website, and replace it with that in the backup. It might be worth creating a backup just before we do this in case we restore the wrong thing.
The other option for restoring files on our Linux hosting environment is to upload the files to our server using FTP and then, using Putty (which we have discussed earlier), run a simple command to restore the files. The command is shown below, but we need to replace file.tar with the name of the file we have uploaded.
tar -xvf file.tar
Remember, restoring files is only half of the process; we still need to restore our database!
Restoring the Database
Similar to backing up the database, we can either use phpMyAdmin or some simple commands to restore the database.
If we log in to phpMyAdmin, which we have looked at earlier, and select the database from the left-hand drop-down list, we have some options at the top. We need the Import option shown in the following screenshot:
This takes us to the import page, where we can browse for our backup.
Once we have selected the backup, we can press the Go button. This will then upload our backup and execute the commands stored within, restoring our data.
Using Simple Commands
If phpMyAdmin is not available, we can upload the SQL file and restore it using a simple command (when logged into the server via Putty, which we have looked at earlier). The command is shown below:
mysql -u username -p typo3database < /home/michaelp/backup.sql
We need to replace username with our MySQL username, typo3database with the name of our TYPO3 database, and the present path with the correct path where we have uploaded our backup file.
Using our Hosting Control Panel
The easiest method for restoring our database is to restore a backup using the cPanel backup functions.
To access the restore utilities, we need to log in to cPanel, which is located at www.ourdomain.com/cpanel, and then enter our hosting account's username and password. From here, we have the backup option on the main screen, which contains the restore features as well as the backup features!
Within this section, we want the Restore a MySQL Database area, where we can browse for our backup file and then click on Upload.
This will then upload our file and restore the backup!
In this article, we have seen how to take a backup of a TYPO3 website and also how to restore our website from the backup we have taken. The two things to back up in a TYPO3 website are TYPO3 files and the database. We have also seen the different tools, which can take a backup of the database and restore them. TYPO3 files can be easily backed up and restored using the operating system tools