We use cookies to make your viewing experience better. By accepting you consent, you agree to our Cookie policy

Accept
Improve your Craft CMS skills

A Guide To Backups With Craft CMS

10 min read
Andy Golpys, Co-Founder of MadeByShape

Backups make or break a Craft CMS website. One late night mishap could bring your whole site crashing down. Without recent backups, data loss and prolonged downtime become inevitable. This guide provides Craft users with invaluable techniques to setup bulletproof backups. Learn to configure automated schedules, test restoration, choose backup software, optimize performance and recover quickly when disaster strikes. With a sound backup strategy, your Craft CMS site and business will keep running no matter what life throws your way.

We will help Craft CMS admins implement robust backups. We will cover backup types, software, locations, frequencies, restoration, troubleshooting and best practices. The optimized, data-driven guide helps prevent data loss and ensure business continuity.

Importance of Backups for Craft CMS

Preventing Data Loss and Downtime

Regular backups are absolutely vital for any Craft CMS website to prevent the headaches of data loss and downtime. Without proper backups in place, even a small hiccup could bring your entire site crashing down.

Just imagine the fallout if your site experienced an unexpected server failure or a malicious attack wiped out your database. Without backups, recovering your content would be impossible.

Your site would remain offline indefinitely, leading to a massive loss in traffic, sales and credibility with your users.

By taking regular backups, you ensure that you always have a lifeline to revert back to a working state should disaster strike. Your developers can quickly restore from a recent backup to get your site back up and running with minimal downtime.

For example, a popular UK fashion e-commerce site relying on Craft CMS had their database corrupted during a routine server upgrade. Thankfully, they had daily backups in place. The developers were able to restore the database within hours and avoided what could have been weeks of downtime during peak sales season.

Recovering from Disasters

Regularly scheduled backups are the backbone of any disaster recovery plan for a Craft CMS website. They serve as a safety net to bounce back from catastrophic failures, data corruption, security breaches and any other disasters that may hit your site.

Without backups, recovery from disasters like server crashes or malicious data deletion is virtually impossible. When your website is down, you are bleeding money every second it remains offline. Backups let you quickly rollback your site to a working state.

For example, a UK university website built on Craft CMS experienced complete data loss after a junior developer accidentally dropped the production database. Fortunately, the university had daily off-site backups as part of their disaster recovery plan. The team was able to restore the database within a day, avoiding prolonged downtime of their website.

Backups give you the ability to recover from both man-made and natural disasters. Whether it's a botched update, corrupted files, malicious attacks, or server failures - having regular backups means reliable recovery.


Ensuring Business Continuity

At the end of the day, the purpose of backups is to minimize disruption and downtime in case of disasters - ensuring the continuity of your business operations.

Well-planned backups provide much needed resilience against data loss. Your site can experience hardware failures, hacks, and human errors. But with proper backups, you can ensure that your site remains continuously operational throughout it all.

Instead of experiencing prolonged downtime waiting for data recovery, your developers can promptly restore recent backups and normal operations can resume quickly. Your business won't miss a beat.

Things like user sessions, cached content and indexes can be rebuilt easily. But your actual content - entries, assets, fields etc. can only be recovered from a backup. Backups are an insurance policy for business continuity and the availability of your Craft CMS website.

Backup Frequencies for Craft CMS

Incremental vs Full Backups

When creating a backup strategy for Craft CMS, a key decision is whether to use incremental or full backups.

Incremental backups only capture files and data that have changed since the last backup. This saves a tremendous amount of time and storage space compared to full backups. However, incremental backups rely on a complete full backup as the baseline.

Full backups capture the entire Craft CMS installation - including all files, databases, plugins, configuration etc. This provides a complete snapshot of the site that can be directly restored. The downside is full backups take longer and require more storage.

Typically an ideal strategy combines both incremental and full backups. Taking frequent incremental backups minimizes size and disruption, while periodic full backups provide a comprehensive baseline recovery point.

Recommended Backup Frequency

Determining the ideal backup frequency depends on factors like rate of content changes, criticality of data and overhead limitations.

For sites with frequent content updates, daily incremental backups are recommended at a minimum. This protects against losing more than one day's worth of changes. Weekly full backups provide an additional layer of protection.

For low-change, less critical sites, weekly or even monthly full backups may be sufficient.

Backup overhead can be minimized on these sites.

In general, weekly full backups combined with daily incremental backups is a good starting point for most Craft CMS sites. More frequent backups may be warranted for high-traffic sites with constant updates.

Critical production sites demand the most stringent backups to minimize potential data loss. For example, an e-commerce site may require daily full backups with incremental backups every 2-4 hours.

Balancing Backup Overhead

While frequent backups provide more protection, there is a cost in overhead. Making backups too often can impact site performance and consume exorbitant storage.

For busy sites with constant content updates, daily incremental backups strike a balance between protection and overhead. Full weekly backups supplement these.

For low-change sites like blogs, weekly full backups are likely adequate since not much changes day-to-day. This minimizes backup overhead.

The sweet spot is the minimum frequency that provides adequate protection based on how often content changes. Assessing the criticality of the site also factors in - backups for a Fortune 500 site need to be more robust than a personal blog.

With a strategic schedule, both data protection and backup overhead can be optimized. For example, configuring backups to run at night or during low-traffic periods reduces impact. Leveraging incremental backups also keeps storage needs reasonable.

Backup Locations for Craft CMS

On-Site vs Off-Site Backups

When backing up a Craft CMS site, a key decision is whether to store backups on-site or off-site.

On-site backups like local disks, NAS and SAN provide quick recovery access since they are on the same network. However, they are vulnerable to site-wide failures like fires, floods or malicious attacks.

Off-site backups involve storing copies externally on disconnected media or locations. Popular options include external HDDs, cloud storage, co-location facilities etc. Off-site backups provide an added layer of protection if disaster strikes the primary site.

A hybrid approach combining both on-site and off-site backups is recommended for comprehensive Craft CMS protection. Quick recovery comes from local backups, while off-site backups guard against catastrophic site failures.

Cloud Backups

Cloud backup services like AWS S3, Backblaze and Google Drive offer a convenient and scalable off-site option for backing up Craft CMS installs.

Benefits include limitless capacity, encryption, data durability and availability from any location with an internet connection. Most services offer versioning as well for easy point-in-time restores.

Pricing is based on storage volume and features. Backblaze offers unlimited storage for a low monthly fee, while AWS S3 charges for what you use. Assessing storage needs and budget is important in choosing a provider.

One downside of cloud backups is the time required for the initial upload and subsequent updates across the internet. An incremental/full backup strategy minimizes this by only sending changes.

Overall, cloud services now make off-site backups incredibly simple and cost-effective for backing up production Craft CMS sites with crucial data.

Securing Backup Locations

Since backups contain sensitive and proprietary data, securing and controlling access is crucial.

For on-site backups, storing media in locked fireproof safes and restricting network access provides basic protection. Encryption adds an extra layer of security.

With cloud services, enabling encryption in transit and at rest is critical. Access should also be limited to only essential personnel through restricted logins or VPCs/VNETs.

Ideally, backups should exist on isolated networks with firewall protection. This prevents them being compromised in the event of an attack or breach on the primary infrastructure.

Following the 3-2-1 rule (3 copies, 2 media types, 1 off-site copy) for Craft CMS backups provides optimal redundancy with both physical and logical separation for maximum security.

Backups contain the keys to your kingdom. Securing them via redundancy, encryption and access controls is just as important as creating them.

Configuring Backups in Craft CMS

Control Panel Backup Settings

The Craft CMS control panel provides configurable settings for database and asset backups.

Under Utilities, administrators can schedule automated database backups with custom filenames. Backup frequency, send method and backup location can be specified.

For assets, administrators can enable volume backups from the Assets utility. Backup frequency is configurable and backups can be sent via email or saved locally.

Control panel settings provide a handy way to set up basic automated database and asset backups without coding. The limitations are less flexibility and no plugins/config backups.

config.php Backup Configuration

For advanced backup configuration, the config.php file is where all the magic happens in Craft CMS.

Here you can define granular schedules, backup types, locations and notifications for each environment. For example:


'backups' => [

'myBackup' => [

'schedule' => '*/20 * * * *',

'type' => 'db',

'location' => '@webroot/backups/db',

'filename' => 'database_{date}.sql',

'emailOnError' => '[email protected]'

],

],

This creates a database backup every 20 minutes into the webroot, naming the backup file with the date. Email notifications on errors provide alerting.

config.php gives complete control over all aspects of Craft CMS backups for precise management.

Custom Scripting for Automation

For additional automation, custom scripts extend backup capabilities.

Scripts can validate backup integrity, purge old backups based on retention policies, sync backups to remote servers, etc. The sky's limit.

For example, a PHP script could compare the current DB checksum to the backup checksum to verify integrity. Another script could periodically cull backups older than 30 days.

The Craft CLI provides access for powerful automation like optimizing databases after backup. Backup plugins like UpSync also leverage webhooks for triggering scripts.

With custom scripting, nearly any type of backup automation is possible - remote transfers, clean up, testing, notifications etc. This takes Craft backups to the next level.

Best Practices for Backups

Backup Validation and Testing

Simply creating backups is not enough - they need to be validated and tested regularly.

Restoring backups on a staging environment provides assurance the backup is not corrupted and can actually be recovered when needed. This also reveals any gaps in the backup process.

For mission critical Craft CMS sites, performing test restores monthly is recommended. For less critical sites, quarterly or bi-yearly may suffice. New backups should always be tested initially.

Restoration testing will reveal if files, database or plugins are missing from the backup. Test on a clone of the live site to avoid disrupting operations. Analyze any issues and refine the backup process accordingly.

Testing backup recovery procedures is equally crucial. This helps identify bottlenecks or gaps in documentation so teams can restore quickly when needed.

Documentation and Monitoring

Maintaining documentation and monitoring logs is imperative for smooth backup and restoration procedures.

All backup schedules, scripts, locations, plugins and configuration should be thoroughly documented. This enables new team members to understand and manage backups.

Monitoring backup job logs for errors provides visibility into issues before they cause data loss. Integrating monitoring with alerts ensures problems are addressed promptly.

Logs also contain details critical for restores like backup dates, integrity checks, etc. Without proper logs, successfully restoring backups is difficult.

Backup Retention Policies

Balance backup storage needs with data protection by implementing retention policies.

Daily incremental backups may be retained for 1 month, weekly backups for 1 quarter and monthly backups for 1 year. Critical backups should be kept indefinitely. Test backups can be discarded after validation.

This balanced policy ensures sufficient point-in-time restore options are available for the last year while long term storage needs are minimized.

Alternatively, a GFS (Grandfather-Father-Son) scheme provides cascading restore points -

  • Daily backups for last 7 days

  • Weekly backups for last 4 weeks

  • Monthly backups for last 12 months

The right policy balances business needs, RPO/RTO, backup storage and costs. Properly purging outdated backups while retaining crucial restore points takes discipline.

Restoring Backups

Backup Restoration Process

When disaster strikes, having a streamlined restoration process is critical for minimizing Craft CMS downtime.

  1. Identify the most recent clean backup before the failure. Check logs for successful completion and integrity.

  2. Clone the current crippled production environment to create an isolated restoration environment.

  3. Delete all files and databases in the restoration environment to start fresh.

  4. Restore the database backup to the new database. Import the SQL file using a tool like phpMyAdmin.

  5. Copy all files from the file backup to the document root of the restoration environment. Preserve permissions and ownership.

  6. Update config files with new database credentials and other environment details.

  7. Test the restored site thoroughly to ensure it is operational before switching over.

  8. Finally, go live by redirecting traffic to the restored environment and decommission the old one.

Throughout, follow procedures rigorously and document each step. Validation is critical to avoid complications.

Restoring to Different Environments

A key benefit of backups is the ability to restore to different environments as needed:

  • Restore to a local environment for developers to debug errors in isolation.

  • Restore to a staging environment to test changes before going live.

  • Restore to production in disaster recovery scenarios to quickly regain functionality.

Adjusting config settings like database credentials allows the same backup to be restored across different environments.

Backup Migration

Backups can also be used to migrate Craft CMS sites to new infrastructure.

To migrate, first provision the new environment then restore the latest backup following the restoration steps above. With the site migrated, retire the old infrastructure.

This provides a quick migration method compared to replicating configuration manually. It also avoids downtime since the site remains functional on the old system until the new one is validated and switched over.

Migrating between local, dev, stage and production is supported by adjusting environment-specific config during restoration. Backups offer flexibility.

Troubleshooting Backups

Reviewing Backup Logs

When Craft CMS backups fail or have problems, the first stop is reviewing the backup logs.

The logs contain details on each backup task like date, files backed up, duration, errors, etc.

Grep through the logs to identify inconsistencies or failures.

Look for backup tasks that ran longer than usual which may indicate performance issues. Errors like timeout failures, storage full or connection issues will also appear.

Analyze the logs to pinpoint where things went wrong. Compare working and failing backups to isolate the problem.

Tools like Splunk provide additional ways to slice and dice backup logs to uncover patterns and anomalies. Trends in backup runtime or failures will emerge.

Reviewing logs helps troubleshoot backup issues and also identifies optimization opportunities before problems occur.

Fixing Common Backup Errors

Some common Craft CMS backup errors include:

  • Connection timeouts - Increase timeout thresholds in config and ensure stability of source/target.

  • Storage full - Add backup storage capacity or implement retention policies to delete old backups.

  • File permission issues - Validate permissions, ownership, and credentials for backup locations.

  • Database locks - Schedule backups during maintenance windows when database activity is minimal.

  • Memory exhaustion - Increase PHP memory allocation for backup jobs.

  • Corrupted backups - Review integrity check logs and validate backups more frequently.

Troubleshooting errors requires analyzing when and how they occur. Fix the underlying problem rather than just the symptom.

Improving Backup Performance

With large sites, backup performance may suffer from sluggishness, high failure rates and timeouts.

Optimizing endpoints, enabling compression and parallelization, scheduling intelligently and testing alternatives can significantly improve backup speeds and reliability.

For example, backing up databases and files in parallel accelerates the process compared to serial handling. Compression reduces transfer time by minimizing network and storage IO.

Performance testing various configurations isolates the optimal settings for infrastructure and site size. Faster, more resilient backups increase the availability of restore points.

Shape April 2022 HR 202
Andy Golpys
- Author

Andy has scaled multiple businesses and is a big believer in Craft CMS as a tool that benefits both Designer, Developer and Client. 

Share
Feedback
Show us some love
Email Us
We usually reply within 72 hours
Agency Directory
Submit your agency
Affiliate Partners
Let's chat