What happens if file changes during backup?

#1

What would happen if a file changed while it was being backed up by Restic? In our case we are using Restic to move large (non-Restic) backup files to an offsite repository. These files can be 100-200GB in size.

What would happen if one of these files was altered/changed while a Restic backup was running? I suppose this question could also apply if we were backing up a live server and some changes were being written to a MySQL database, for example. How does Restic handle this?

Just trying to work out the best solution in terms of how/when to safely run Restic and ensure data consistency.

Thanks in advance.

0 Likes

#2

There’s nothing any backup client can do if your storage is not idle. Beside detecting that file changed or grew during backup, in which case you will be informed, here’s an example:

warning for /opt/observium/rrd/stats02/perf-pollermodule-status.rrd: file has changed
warning for /var/log/account/pacct: expected 122095744 bytes, saved 122098112 bytes

If you need 100% consistent backup, you need to provide idle storage during the backup run, typically with some kind of snapshotting (LVM or whatever).

Also databases should have their own backup procedures, and are best avoided when doing filesystem backup. You can for example do a mysqldump or xtrabackup dump, then backup this file/dump, and exclude /var/lib/mysql completely.

0 Likes

#3

@zcalusic is right: When the files change while restic reads them, you’ll get an inconsistent state for the file, and the backup is worthless (depending on how well the application can recover).

For databases like MySQL, you could use mysqldump [...] | restic backup --stdin --stdin-filename dump.sql to archive the raw SQL stream.

0 Likes

#4

@fd0, @zcalusic, or others:
In case a file / folder is inconsistent due to changes being made while restic backup is being run (e.g., via cron) – can the snapshot (and all the underlying folders) still be restored? Can the inconsistent files be restored (though into an inconsistent state of course)?

0 Likes

#5

Yes, but for the files which were changed while restic read them, you’ll end up with an inconsistent state. The other files (and the folders) are not affected.

Yes, restic will restore them as best as is can. How good that is (and how usable the result would be) depends on the file and format and the changes made during the backup.

1 Like