Prepare your website for a disaster before you lose it all. A few different methods to backup your MODx driven website. Don't let disaster surprise you!

You just spend several hours working on a new MODx powered website, but unlike normal websites there are no files for each page. The question now is how do we ensure all your hard work is protected from disaster? The answer is very simple, you backup your website. There are several methods to backup a MODx driven website, the question is which method works best for you.

There are two key aspects you need to backup:

  • Files
  • Database

There are several methods you can use to backup a MODx site each having pros and cons. Pick the method that best meets your needs and rest easy knowing your site is safe from a server disaster. Please keep in mind these methods are based on my experience so your results may vary based on host, server configuration, or other variables. All methods require you know how to login to your server via ssh or a control panel along with using an FTP or SFTP client.

1. Direct Backup

A direct backup is done using the standard tools found on most servers and can actually be done several ways depending on the time you want to invest. The concept is very simple we are going to save a copy of all the files on your site along with a copy of your database. This can all be done using shell commands, but as my shell skills are lacking I will stick using cpanel as is found with most hosting companies.

The general process is as follows:

  1. Login to cpanel
  2. Open phpMyAdmin
  3. Select the Database containing your MODx install
  4. Click the Export tab
  5. Select all the tables for your MODx install
  6. Select SQL as the export type
  7. Check save as file (Pick a compression format if desired)
  8. Click Start/Export and save the file
  9. Log off cpanel

The file you saved above is your database which store all the content from your site. You can find your chunks, snippets, users, pages, etc. store in this file and as such I suggest backing it up on a more regular basis depending on how often your site changes.

The next item we need to backup is the files related to your site which would include documents, images, template styles, javascript files, and such. This can be done one of two ways depending on your connection speed and/or personal preference. The first method you download a compressed zip (faster if you have a slow connection) the second is downloading the files using your FTP/SFTP client.

  1. Login to cpanel
  2. Open the File Manager
  3. Navigate to the folder containing your MODx install
  4. Select the files/folders for your install
  5. Click Compress to generate a zip
  6. Select the zip file and click download
  7. Log off cpanel

Using your FTP/SFTP client:

  1. Open your FTP/SFTP client
  2. Navigate to the folder containing your MODx install
  3. Select the files/folders for your install
  4. Download the files/folder to a location of your choice
  5. Exit your FTP/SFTP client
You could also use a combination of the two methods the first to compress the site the second to download the zip using your FTP/SFTP client. Compressing the site to a single file will speed the download process as one large file is faster to download than lots of small files.

This method requires you go through several steps and as such will take longer to complete. It's only recommended if your site changes infrequently or you only manage a couple sites. The other methods are suggested if you have a few sites and/or wish to speed the process.

2. Direct Backup with Automation

If your site changes on a regular basis or you manage a few websites, the above method isn't for you. The key to making backups a success is doing them regularly, so with this progression we eliminate a good deal of the work and automate it using cron jobs (scheduled tasks). I may be good with HTML and CSS, but you wouldn't want to rely on scripting skills.

I recommend using the backup scripts provided by B&T here: tips-scripts.com (Automated File Backup | Automated Database Backup) These are both provided free of charge and work well for any website, not just MODx powered websites.

You can read more about setting up these scripts on B&T's website so I will skip ahead some. I would recommend running the database backup script daily and the file backup script on a bi-weekly or monthly basis depending on how often your site changes. I only use the database script as you will learn later.

The end result after the scripts have run are two compressed zip files so for the second half of this backup method we just need to retrieve these files from the server. This can be done with cpanel, but personally I find it easier to just use a FTP/SFTP client so here are the steps:

  1. Open your FTP/SFTP client
  2. Navigate to the folder containing your backups
  3. Select the files
  4. Download the files to a location of your choice
  5. Exit your FTP/SFTP client
This method has the best balance between time spent and ease of restoration. The problem with this method is if you use automated file backups and forget to delete old backups you will quick run out of server space and your backups could backup your backups thus making some large backup files. Database backups can also be bad, but with most databases being 1-2MB it will take longer to fill your server.

3. Control Panel Backups (Cpanel)

If you use cpanel you have a great built in backup utility that will gather all your files, databases, email address, and other settings in one zip file. This is known as a Full Backup which can be used to move between hosting companies or recover from a full server failure among other things. I use automated database backups in addition to control panel backup as most updates on my sites are done in the database.

Generating a cpanel backup is rather simple:

  1. Login to cpanel
  2. Select Backup
  3. Click Generate Full Backup
  4. Enter an email address as directed
  5. Click generate
  6. Log off cpanel

Depending on the size of your site it will take about 10-20 mins to generate a backup, this is also directly affected by your current server load so it's best to do this off peak hours. After you get the email you need to login and download the backup. You can go through the above steps and click the link when your backup finishes instead of generate, or you can download the file using your FTP/SFTP client as follows:

  1. Open your FTP/SFTP client
  2. Navigate to the folder containing your backups
  3. Select the files
  4. Download the files to a location of your choice
  5. Exit your FTP/SFTP client

4. MODx Module

If you are looking for a more built in system for MODx, you may want to have a look at ModBak. It's a module you can install that automates the process of backing up your site. It wraps up the database and files for your install and provides them in an easy to download zip file. This can all be done in one place quickly. The last time I used this system it was tricky to setup, but once working it did a great job.

Summary

The best backup method isn't the one I use, but the one that works best for you. Yes, I can suggest different options, but if you don't follow through with these methods they are worthless. I've seen my fair (or unfair) share of business owners in tears... Why? They just lost everything on their main business computer due to a hard drive crashing, virus infestation, or user error. The killer is until they lost everything they never thought about backups even if they had a drive for backups.

I can't stress this point enough as I would rather avoid another crying adult... Backup, Backup, Backup!

The easiest method to backup a site is by using the cPanel backup system, it saves everything, but restoring files can be tricky as this method is likely designed for server transfers or full server recovery. The next best method would be the Direct Backups with Automation so you just download a few files on a regular basis. It's far easier to restore the Direct Backups, but it takes a good deal of time.

Suggestions

This information is hardly a definitive guide and I am hardly an expert on the subject. If you have any suggestions on how I can improve this information then please let me know!

7/16/2015 - The tips-scripts.com website is no longer available, the links have been updated to use the internet archive.


Tags: