Difference between fsfreeze and lvm snapshot

6,433

From man fsfreeze:

-f, --freeze

This option requests the specified a filesystem to be frozen from new 
modifications. When this is selected, all ongoing transactions in the filesystem 
are allowed to complete, new write system calls are halted, other calls which 
modify the filesystem are halted, and all dirty data, metadata, and log information 
are written to disk. Any process attempting to write to the frozen filesystem will 
block waiting for the filesystem to be unfrozen.

To make a backup, from a mounted file system getting random modifications all the time, freezing the I/O for the duration of the backup is only part of the job to do. That's because unless the file system is really small, or you have an extremely fast backup device, you will most certainly be unable to afford to freeze the whole file system for the entire duration of making the backup.

So, fsfreeze alone is most likely not enough to do what you want. On the other hand, LVM snapshot is exactly what is needed for this job: it takes only a few seconds to "make the backup", then you can take your time to actually copy that backup (the snapshot) to some slow backup device as the LVM snapshot will handle file system blocks getting changed during this long backup process. The only part where fsfreeze would be needed is the snapshot creation part but that part is already handled by LVM itself transparently, so, altogether, all you need to pay attention to is the LVM snapshot.

Backups made by using similar file system freeze or block device snapshot features are considered consistent enough for a well-behaved RDBMS (such as Oracle and its cousins), however, you have to ensure that all the database files get frozen/snapshot at the same point in time. If multiple file systems/LVM volumes are affected, this may neccessitate the help of the RDBMS. Oracle, for instance, provides a BACKUP MODE, which is there to implement a freeze similar to what fsfreeze does, but at the database level.

Share:
6,433

Related videos on Youtube

S edwards
Author by

S edwards

Nice person willing to save the Universe...

Updated on September 18, 2022

Comments

  • S edwards
    S edwards over 1 year

    I heard recently about fsfreeze and I'm very interested in making snapshots of my VM with VMware and get a consistent state of disk using quiescence. All my file-systems are LVM volumes, and man fsfreeze mentions:

    fsfreeze is unnecessary for device-mapper devices. The device-mapper (and LVM) automatically freezes filesystem on the device when a snapshot creation is requested. For more details see the dmsetup(8) man page.

    But I find fsfreeze much more easy to use than a complex LVM tool where you need to evaluate your snapshot size.

    Questions

    • Is there a difference?
    • Can I still use the command for a LVM volume? Or maybe a physical LVM volume?
    • Or am I forced to use the lvm command?

    Additional question for the bounty

    Does the fsfreeze or lvm snapshot insure a consistent snapshot if used to backup a mysql/oracle/postgrSQL DB?

    Some more information

    The case here is simple but you need to understand all the concept.
    VMWare is capable of taking vm snapshot pretty quickly (less than 5 seconds), and before and after that snapshot executing script to stabilize the vm state and get a consistent vm snaphot. I don't care being able to mount in read-only a lvm snapshot and I don't want to because they are limited to disk size and more-over . What I want is to fsfreeze my filesystems and snapshot the vm and release the lock.
    In that case could it be possible to use fsfreeze instead of the lvm snapshot (which are more complex and disk space linked.

  • YoloTats.com
    YoloTats.com over 9 years
    @Kiwy No, fsfreeze stops effectively all processes, which want to write during the freeze, it does not store modifications in RAM in the meantime (of course every I/O goes normally through buffers in the RAM, but their size is limited).
  • S edwards
    S edwards over 9 years
    some more information in my question
  • golem
    golem over 9 years
    @Kiwy please clarify what VMWare solution you are using.
  • S edwards
    S edwards over 9 years
    Vmware esx snapshot
  • golem
    golem over 9 years
    There is an option of installing VMWare Tools on your guest system. Then according to this VMWare KB article VMWare can quiesce (what fsfreeze does) the system for you when the snapshot is taken. If installing VMWare Tools is not an option then from definition of fsfreeze it sounds like it should do the job for you. But this is by no means an expert or experience-based statement.