Question abot lxc export and copy

Hi, I have a question about consistency of container archive and copy of container.
Does lxc export/copy command create something like a snapshot of container?
While lxc export/copy copies, data in container are changing instantly. For example container with sql database(mysql/pg). Can I make backups with lxc export or lxc copy to secondary lxd server, will be data ok? Or I can get corrupted database?

1 Like

No idea?

Hi, apologies for the delay in replying.

Currently today LXD will only take read-only snapshot (to provided a consistent backup) when performing an lxc export of a running instance that uses a ZFS or BTRFS storage pool.

For other storage pools the backup will be potentially inconsistent if the instance is running.

This was discussed quite a bit here:

Although I think that adding the instance “freeze” support (and optional --allow-inconsistent flag) to lxc export got lost in there.

Would you mind opening an issue at https://github.com/lxc/lxd/issues to pick this discussion back up again?

Currently today LXD will only take read-only snapshot (to provided a consistent backup) when performing an lxc export of a running instance that uses a ZFS or BTRFS storage pool.

Taking snapshots is a solution, but there is a problem. When copying an instance from snapshot, flag --refresh is not supported, so I can’t make incremental copies from snapshot.

Although I think that adding the instance “freeze” support (and optional --allow-inconsistent flag) to lxc export got lost in there.

instance “freeze” isn’t supported yet?
freezing instance also has a problem, while backup is being made, the instance doesn’t work

Would be great make support of incremental backups(flag --refresh) from snapshot

Well a snapshot doesn’t change, so copying from a snapshot wouldn’t need a --refresh option as it won’t change since last run.

Using lxc snapshot <instance> and then lxc copy <instance> backupserver: --refresh will (depending on storage driver) only sync the differences between the latest snapshot and the current root volume contents.

This is what BTRFS and ZFS drivers do and its what we refer to as “optimized refresh”.

Is there any difference in the actual commands being operated on that would prevent this also being applied to LVM? Seems like the same process to take a snapshot and then rsync it with --delete would apply?

I think this is the OPs point though. Rsync functions the same no matter the source, so could the --refresh option be supported in more cases?

Not all storage drivers, or even specific volume types use rsync, so any solution to implement --refresh from a snapshot would need to take a holistic view of all scenarios.

The lvm storage driver does use rsync for filesystem volumes and raw block transfer for block volumes.

Each storage driver has a property called RunningCopyFreeze which indicates whether running instances should be frozen when making (consistent, i.e when --allow-inconsistent isn’t specified) copies of them (be it for snapshots or for copying to another location).

The ZFS and BTRFS drivers have this set to false, because snapshots are deemed “cheap” enough that LXD can take a temporary one as the source of the copy to avoid needing to freeze the instance for the duration of the copy.

The LVM driver currently has RunningCopyFreeze set to true, but perhaps this could be relaxed to a conditional based on whether the pool is using LVM thin pool mode. Certainly for non-thin pools LVM snapshots incur quite an overhead so I can understand where this logic originally came from.

That being said I am not quite following the need for refreshing from a snapshot into a target instance, as this would then lose the historic snapshots on the target.

Instead you could do this:

lxc snapshot <instance> # For LVM this will briefly freeze the instance while taking the snapshot.
lxc copy <instance> backupserver: --refresh --allow-inconsistent

This will then copy the latest snapshot (which was taken consistently) and then copy the differences between that and the main volume in an inconsistent manner (to avoid freezing the instance).

You still have the latest snapshot and previous ones in a consistent manner though, and that means you can restore a specific snapshot from the backup target.