# OpenCart Backup: How to Set Up Store Backups and Test Them

> What exactly to copy from an OpenCart store, how to automate database and file backups, and how to make sure the copy actually restores.

Джерело: https://opencartcode.com/en/wiki/security/opencart-backup
Оновлено: 2026-11-28

A complete OpenCart backup consists of two parts: a database dump (products, orders, customers, settings) and a copy of the site files (images, theme, modules, configs). Copies should be created automatically, stored off the store's server, and checked regularly with a test restore. Without verification, a backup guarantees nothing.

## What exactly should you copy in an OpenCart store?

An OpenCart store keeps its data in two places, and losing either one is painful.

**The database** (MySQL or MariaDB) contains the catalog, prices, stock levels, orders, customers, coupons, SEO URLs, module settings, and all parameters from the «Settings» section. This is the most valuable part: you can't recreate last week's orders from scratch. Which tables are responsible for what is described in the article on the [OpenCart database table schema](https://opencartcode.com/en/wiki/dev-database/opencart-database-tables) (in the wiki: [OpenCart database table schema](https://opencartcode.com/en/wiki/dev-database/opencart-database-tables)).

**Files** include:

- `image/`: product photos, banners, logo. Usually the heaviest folder, from hundreds of megabytes to tens of gigabytes.
- `config.php` and `admin/config.php`: paths, site address, database access. What they contain is covered in the material on [OpenCart file configs](https://opencartcode.com/en/wiki/dev-architecture/opencart-config-php).
- Theme: `catalog/view/theme/` (in 3.0) or `catalog/view/template/` and `extension/{код}/` (in 4.1); installed modules: `extension/` (in 4.1) or module files in `admin/` and `catalog/` (in 3.0).
- The `storage` directory: modifications, files uploaded by customers, logs. There's no need to copy the cache. For details, see the article on the [storage directory](https://opencartcode.com/en/wiki/dev-architecture/opencart-storage).
- `.htaccess` and, if present, any custom core modifications.

A common mistake is copying only the database for years. After a crash or disk failure, the data is intact, but photos, the theme, and paid modules with your customizations are gone. Recovery then takes weeks.

## Is OpenCart's built-in backup enough?

The admin panel has a tool called «System → Maintenance → Backup / Restore». It works only with the database, and it behaves differently in the two branches.

In **3.0**, you check the tables with checkboxes, and the browser immediately downloads an SQL file. Everything happens in a single request, so on a large database (tens of thousands of products, years of orders) the process often breaks off because of the PHP execution time or memory limit. The file may turn out to be truncated, and nothing will warn you about it.

Backup in OpenCart 3.0: table selection and SQL file download · OpenCart 3.0.5.1

In **4.1**, the copy is created in parts via AJAX. The finished file is stored on the server in `storage/backup/`, and from the list you can download, restore, or delete it. This works more reliably with large databases, but the copy sits on the same server as the store.

Backup in OpenCart 4.1: list of saved copies with download and restore buttons · OpenCart 4.1.0.4

An important nuance: the built-in backup essentially exports data (emptying a table and inserting rows), not the full database structure. It can only be restored into a database where the OpenCart tables already exist. Such a file won't deploy onto an empty server «from scratch».

> The built-in tool is fine for a one-off copy before updating a module or running a mass import. It cannot serve as your main backup: it doesn't copy files, doesn't run on a schedule, and doesn't move the copy off the server.

## How do you set up automatic backups of the database and files?

A reliable option is a script on the server that runs via cron (the Linux task scheduler). It's needed on a VPS, and it also works on most hosting plans with SSH access. If there's no SSH, check whether your hosting control panel can make scheduled copies, and be sure to download them to your own machine (more on this below).

### Step 1. Store database access separately from the script

So that the password doesn't show up in the process list, put it in the `~/.my.cnf` file with permissions 600:

```bash
[mysqldump]
user=shop_user
password=ваш_пароль
```

### Step 2. The backup script

```bash
#!/bin/bash
DATE=$(date +%F_%H%M)
DIR=/home/user/backups
SITE=/home/user/public_html
DB=shop_db

mkdir -p "$DIR"

# База: --single-transaction дає цілісну копію для InnoDB (4.1)
mysqldump --single-transaction --quick --routines \
  --default-character-set=utf8mb4 "$DB" | gzip > "$DIR/db-$DATE.sql.gz"

# Файли без кешу
tar -czf "$DIR/files-$DATE.tar.gz" \
  --exclude="./system/storage/cache" \
  --exclude="./image/cache" \
  -C "$SITE" .

# Перевірка, що архів бази не битий
gzip -t "$DIR/db-$DATE.sql.gz" || echo "DB backup broken $DATE" >> "$DIR/errors.log"

# Видалити копії, старші за 14 днів
find "$DIR" -name "*.gz" -mtime +14 -delete
```

For 3.0, where tables are usually in MyISAM, `--single-transaction` does not guarantee consistency. Run the dump at night, when there are almost no orders, or remove this flag so that mysqldump locks the tables during copying. If storage is moved outside the site (which is recommended), add its path to the archive separately. `image/cache` is not copied: OpenCart will regenerate the thumbnails.

### Step 3. The cron schedule

```bash
30 3 * * * /home/user/bin/backup.sh >/dev/null 2>&1
```

This makes a copy every night at 3:30. For a store with dozens of orders a day, it's worth copying the database more often, for example every 4–6 hours, while files are fine once a day. OpenCart's internal tasks are described in the article on [cron in OpenCart](https://opencartcode.com/en/wiki/dev-extensions/cron-opencart), but for backups the system cron is more reliable: it doesn't depend on whether the PHP site is alive.

## Where should you store copies, and how many should you keep?

A copy on the same server protects you from a failed module update, but it won't help if the hosting account is hacked or suspended, the disk burns out, or the data center loses power. For stores in Ukraine, the last risk is quite real, so the plan for outages is covered separately in the security section. A proven rule is 3-2-1: three copies, on two different media, one off the main site.

| What | How often | Where to store | How long to keep |
| --- | --- | --- | --- |
| Database dump | 1–4 times a day, depending on the number of orders | Server + cloud storage | Daily for 14 days, monthly for half a year to a year |
| Files without cache | Daily or weekly | Cloud storage | 2–4 weeks |
| Full copy before an update | Before every change | Local + cloud | Until the next stable state |
| Host snapshot | Per plan | Host's infrastructure | As the plan allows |

For uploading to the cloud, a convenient utility is `rclone`. It works with Google Drive, Dropbox, and S3-compatible storage. Just add the `rclone copy "$DIR" remote:shop-backups --max-age 24h` line to the script. The storage account should be separate from the one you use to manage the site: if an attacker gains access to the server, they should not be able to delete the remote copies as well.

Long-term retention is needed because infections are often noticed late. Malicious code can sit in files for weeks, and then yesterday's copy will be infected too. Monthly copies are exactly what saves you in a [store hacking](https://opencartcode.com/en/wiki/security/opencart-security) scenario.

> The database holds customers' names, phone numbers, and addresses. Encrypt archives before sending them to the cloud (for example, with `gpg` or a password-protected archive), and limit the number of people who have access to the storage.

## How do you check that the backup actually restores?

Most owners find out their backup is unusable on the day of the disaster: the dump is truncated, the archive is empty, the encoding is broken, and nobody remembers the storage password. So once a month or quarter, run a test restore on a separate subdomain.

1. Create a subdomain such as `test.shop.ua` and a new empty database.
2. Download the latest archive from the *storage*, not from the server. This way you also verify the upload.
3. Import the dump: `gunzip -c db-....sql.gz | mysql test_db`.
4. Unpack the files and edit both `config.php`: the site address, the `DIR_*` paths, and access to the new database. What else to change when the address differs is described in the post on [changing the site address in OpenCart](https://opencartcode.com/en/blog/zmina-adresi-saitu-v-opencart-konfigi-baza-danix-i-301-redirekti).
5. Protect the test copy from indexing and outsiders: with a password via [.htaccess](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#htaccess) or by restricting by IP.
6. Turn off email sending and payment modules, so the test copy doesn't send emails to customers or connect to the acquirer.

### What to check on the restored copy

- The home page, a category, and a [product page](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#product-page) open, and photos load.
- Admin login works, and «Sales → Orders» (Sales → Orders) contains orders from the day before the backup.
- The number of products and customers matches the live site.
- Cyrillic in names and descriptions displays without garbled characters.
- In 3.0, modifications apply after «Refresh», and modules are in place under «[Extensions](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#extensions) → Extensions» (type «Modules»).

If the site shows a white screen, look for the causes in the guide on the [500 error in OpenCart](https://opencartcode.com/en/wiki/dev-practice/opencart-white-screen). The most common culprits are incorrect paths in the configs or a different [PHP version](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#php-version). Note how long the restore took: that is your real downtime during an emergency.

## When is an off-schedule backup essential?

Besides the daily schedule, there are moments when the risk rises sharply and a fresh copy is needed «right here and now»:

- before installing or updating a module, theme, or modification;
- before a mass import of products or prices, because a faulty column mapping can overwrite thousands of items;
- before updating OpenCart or the PHP version on the hosting;
- before moving to another host or domain (see the [store migration plan](https://opencartcode.com/en/wiki/migration/online-store-migration));
- before running manual SQL queries in [phpMyAdmin](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#phpmyadmin).

For such cases, the simplest approach is to run the same script manually and make sure the files appeared and have a reasonable size. A sharp drop in dump size compared to yesterday is a warning sign. On a small database, you can also use the built-in «Backup» in the admin panel, but only as a supplement.

Finally, write the restore procedure into a simple document: where the copies are, how to access the storage, who has SSH, and which steps to follow. Keep it not only on the store's server. In a stressful situation, such instructions save hours.

Other topics on protecting your store are collected in the section ["Security, Backups and Protection"](https://opencartcode.com/en/wiki/security).

## Summary

- An OpenCart backup always means the database **and** the files: `image/`, configs, theme, modules, storage without cache.
- The built-in "Backup" tool copies only database data and suits one-off copies before changes, but not as a primary system.
- Automate copies with mysqldump, tar, and cron, and for InnoDB in 4.1 use `--single-transaction`.
- Keep copies off the server, in a separate account, encrypted, with a history depth of at least several weeks.
- Regularly restore a copy on a test subdomain and note the time. Without this, you don't know whether you have a backup.

Next step: go through the general [OpenCart security checklist](https://opencartcode.com/en/wiki/security/opencart-security), so that your backup remains the last line of defense, not the only one.

## FAQ

**Can you rely only on the backups your hosting provider makes?**

They work as an extra layer, but not as the only one. These copies sit in the same provider's infrastructure, retention is often short, and if your account gets blocked you may lose access to them. Keep your own copy off the hosting.

**How much space do store backups take up?**

A compressed database dump usually takes from a few megabytes to a few hundred. Most of the volume comes from product photos in the image folder, ranging from hundreds of megabytes to tens of gigabytes. That's why files are often copied less frequently than the database or incrementally.

**How do you restore just one product or order instead of the whole database?**

Deploy the copy into a separate test database, find the needed rows in the relevant tables, and move them into the live database manually or through an export of individual rows. A full restore over the live database will wipe out everything that appeared after the backup was made.

**Do you need to stop the store while creating a backup?**

No. For InnoDB, mysqldump with the single-transaction flag makes a consistent copy without stopping the store. For MyISAM tables, they are locked briefly, so it's better to run the copy at night.
