The database backup runs at night and, the next day, someone complains that the system “froze for a few minutes” or that an order didn’t save. It is almost always the lock. To copy a MySQL database, the standard tool, mysqldump, needs a consistent snapshot: it can’t copy half a table before a change and the other half after it. On InnoDB tables, MySQL’s default for years and what WordPress uses today, it manages that without locking anything. On MyISAM tables, the old format still common in older systems, there is no way around it: the table becomes read-only while it is copied, and anyone trying to write to it waits. The question for this lab: on a real database, large and full of MyISAM, how long does the site wait during the backup? And can it be copied without locking, without losing the guarantee that the database comes back whole?
Why it matters to whoever runs the server
- The site’s wait. While a MyISAM table is locked for the backup, anyone trying to write to it waits: the store order, the sign-up, the login. With every table locked together, that wait reached minutes. Now the longest was 0.2 s.
- Trust in what was copied. Copying without a lock is easy; the hard part is making sure the copy came out consistent. Salvo checks every table before and after the copy, and on this very server that caught a table that changed halfway through.
- The server’s disk. One of our versions locked the database less, but wrote so much to the disk that every write from the site took 70 times longer. We fixed it before it became the default, and we show it here because it is exactly the kind of trade-off nobody sees in the panel.
- Time and storage. A 6.4 GB database that barely changes doesn’t need to be copied whole every night. With the differential on, its backup took 47 s and sent 9.5 MB to the storage.
- WordPress databases are almost always InnoDB, which already copies without locking. To restore a single WordPress table, see:See:Lab 22
How to read it: each bar is the longest time the customer’s system waited to write to the big database while the backup ran. In the old format, the 56 MyISAM tables stayed locked together for their whole copy; that wait wasn’t measured separately, and the bar shows the ceiling, the time of the whole database. JetBackup, with the configuration on that server, locks nothing, but it also doesn’t check whether the copy came out consistent.
How to read it: latency is how long the server’s disk takes to confirm each write, and the site feels it on every write. It is the median of one point per minute during the run. The first version of “one table per file” wrote the backup to the server’s disk before sending it to the storage, and latency reached 278 ms. The new version sends straight to the storage and went back near the idle server.
How to read it: the gray line is the first version, which wrote the backup to the server’s disk before sending it; the blue one is the new version, which sends straight to the storage. One point per minute, from the start of the run. The new version had one isolated higher minute at the end (79 ms), still under investigation.
How to read it: the backup time of the big 6.4 GB database alone, in each version. The first run of the new version was the slowest of all: a table changed during the copy and the database was copied twice, and the files changed names, so nothing from the previous backup was reused. Both causes were fixed. With the differential on, the 53 MyISAM tables that didn’t change weren’t even read.
| Old format | 1st version | New version | New + differential | JetBackup | |
|---|---|---|---|---|---|
| Longest wait to write | up to 216–281 s | 78.9 s | 0.2 s | 0.2 s | 0 (no check) |
| Write latency (median) | 3.3–3.5 ms | 256–278 ms | 6.7 ms | 6.4 ms | 15–77 ms |
| Worst minute | 6.4–134 ms | 570–713 ms | 128 ms | 79 ms | 163–273 ms |
| The 17 databases | 5:39m – 7:05m | 6:13m – 6:21m | 13:35m | 3:51m | 5:53m – 6:22m |
| Big database | 216–281 s | 189–218 s | 601 s | 47 s | 340 s |
| Sent to the storage | 51 MB | 9–69 MB | 4.6 GB | 9.5 MB | — |
Method
A customer’s production server, with MySQL 5.7, 6 accounts and 17 databases, about 7.6 GB copied per run. The main character is a 6.4 GB database with 38 InnoDB tables (671 MB) and 56 MyISAM tables (5.3 GB); the biggest table is 1.9 GB and the second, 1.8 GB. The customer’s system writes to this database all day, including at night.
Same server, same storage, the same 17 databases, always at a low-traffic time. Each run is a full backup of the databases, started from Salvo’s screen.
We compared four ways: Salvo’s old format, one file per database (two runs); the first version of one table per file (two runs); the new version, straight to the storage (one run with the differential off and one with it on); and JetBackup, on the same server and storage, with the daily backup it already ran there, four days in a row.
The server was measured the whole time by the monitoring: disk write latency, writes per second, CPU and network, one point per minute.
What we changed in Salvo
One table per file, and lock one at a time. In the old format, Salvo copied the database into a single file and the 56 MyISAM tables stayed locked together from the start to the end of their copy. The first change was to copy each table into its own file, locking only the one being copied: the longest wait dropped to 78.9 s, the time of the biggest table, 1.9 GB. But that version wrote everything to the server’s disk before sending it to the storage, and the disk suffered (chart above). Straight to the storage, and no lock when the table didn’t change. In the new version, each table goes from mysqldump straight to the storage, without touching the server’s disk. And a MyISAM table that wasn’t changed in the last hour is copied without a lock: Salvo records its signature before the copy (last change time, row count, size and a checksum) and checks it again at the end. If it changed during the copy, that copy doesn’t count: the table is copied again, with a short lock on it alone. This really happened: in the first run, a small 3.5 MB table changed mid-copy because of a scheduled job in the customer’s own system. Salvo noticed and copied it again, locking only that table for 0.2 s. Salvo now remembers which tables already changed during a copy, and they get a short lock from the start. The differential, optional. If a MyISAM table’s signature hasn’t changed since the previous backup, Salvo doesn’t even read it: the new backup points to the copy already on the storage. Once a week (configurable), it rereads everything and compares byte by byte; if a table changed without its signature changing, it leaves the differential for good and the run warns you. The differential is off by default: the admin turns it on. InnoDB tables are always copied whole, without a lock.