Backing Up and Restoring TYPO3 Websites

Exclusive offer: get 50% off this eBook here
Building Websites with TYPO3

Building Websites with TYPO3 — Save 50%

A practical guide to getting your TYPO3 website up and running fast

$23.99    $12.00
by Michael Peacock | July 2008 | MySQL Content Management Open Source PHP

All web applications and web servers have security vulnerabilities and there is every chance that our website will be compromised. Most web hosts have their own backup procedures in place, but it is not uncommon for a web host to become victim to an attack, and have problems with a small percentage of its customer backups. Because of this it is very important that we keep backups of our website. In this article by Michael Peacock, we will see how to backup our website and restore it back gain from our backup.

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:

Backing Up and Restoring TYPO3 Websites

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.

Backing Up and Restoring TYPO3 Websites

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
user's webspace.

The backup tool then takes a moment or two of processing, and then prompts us to download the backup file.

Backing Up and Restoring TYPO3 Websites

Command-Line Backup

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.

Backing Up and Restoring TYPO3 Websites

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:

Backing Up and Restoring TYPO3 Websites

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.

cd /home/michaelp/public_html/
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.


Building Websites with TYPO3 A practical guide to getting your TYPO3 website up and running fast
Published: March 2007
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

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.

Using phpMyAdmin

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.

Backing Up and Restoring TYPO3 Websites

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).

Backing Up and Restoring TYPO3 Websites

We want the Export option, as we are going to export the database to a file.

Backing Up and Restoring TYPO3 Websites

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.

Backing Up and Restoring TYPO3 Websites

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.

Backing Up and Restoring TYPO3 Websites

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!

Building Websites with TYPO3 A practical guide to getting your TYPO3 website up and running fast
Published: March 2007
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

Restoring the Database

Similar to backing up the database, we can either use phpMyAdmin or some simple commands to restore the database.

Using phpMyAdmin

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:

Backing Up and Restoring TYPO3 Websites

This takes us to the import page, where we can browse for our backup.

Backing Up and Restoring TYPO3 Websites

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.

Backing Up and Restoring TYPO3 Websites

This will then upload our file and restore the backup!

Summary

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

About the Author :


Michael Peacock

Michael Peacock is a web developer from Newcastle, UK and has a degree in Software Engineering from the University of Durham. After meeting his business partner at Durham, he co-founded Peacock Carter, a Newcastle based creative consultancy specializing in web design, web development and corporate identity.

Michael loves working on web related projects. When he is not working on client projects, he is often tinkering with a web app of his own.

He has been involved with a number of books, having written two books himself (and working on his third): Selling online with Drupal e-Commerce Packt, and Building websites with TYPO3 Packt. He has also done technical reviews of two other books: Mobile Web Development Packt, and Drupal Education & E-Learning Packt.

You can follow Michael on Twitter.

Contact Michael Peacock

Books From Packt

Building Websites with TYPO3
Building Websites with TYPO3

Mastering TypoScript: TYPO3 Website, Template, and Extension Development
Mastering TypoScript: TYPO3 Website, Template, and Extension Development

TYPO3: Enterprise Content Management
TYPO3: Enterprise Content Management

OpenCms 7 Development
OpenCms 7 Development

Building Powerful and Robust Websites with Drupal 6
Building Powerful and Robust Websites with Drupal 6

Building Websites with Joomla! 1.5
Building Websites with Joomla! 1.5

WordPress Complete
WordPress Complete

Learning Website Development with Django
Learning Website Development with Django


 

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software