23

Is there any way we can take a snapshot of an ext4 filesystem so that we can revert back to it later?

bRuta
  • 391
  • 2
  • 3
  • 6
  • 2
    Not an answer, but if snapshots on file level are sufficient, you could try [rsnapshot](http://rsnapshot.org/). For real filesystem snapshot, you might consider moving to [btrfs](https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Managing_Snapshots). – basic6 Aug 08 '16 at 14:36

1 Answers1

24

The ext4 filesystem has no built-in snapshot feature.

The generic way to make snapshots under Linux is at the level of the storage volume. Your filesystem must be on an LVM logical volume, which is Linux's own partition system, as opposed to directly on a platform-native disk partition.

To create a snapshot of a logical volume, run lvcreate --snapshot. You need to have enough space for the snapshot on the same volume group. Keep in mind that the snapshot volume will grow as the master filesystem gets modified, since it stores the difference between the master filesystem and the snapshot state.

To restore a snapshot to the original, run lvconvert --merge on the snapshot volume.

You can find more detailed walkthroughs in Setting up LVM Snapshot as a backup/restore point in ubuntu and How to Take ‘Snapshot of Logical Volume and Restore’ in LVM.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • Thanks a lot for explaining this. It is more clearer now. I am actually more specifically looking to do this. Take snapshot of the current state of the filesystem, do some changes and then be able to restore the system to its original state i.e. to the snapshot I took before. I have CentOS 6.5 with an ext4 file system and the file system is not on an LVM logical volume. This is an enterprise system so I cannot make any changes to the configuration. – bRuta Aug 28 '15 at 17:11
  • @bRuta Since ext4 doesn't have a snapshot feature, you'll have to find some other method. You can of course make a backup and restore it, but these are not atomic operations. Another approach could be to run the application that would make the changes you want to revert on a union filesystem where everything it changes is written to another filesystem; this way the application thinks it modified things but the system actually remains unchanged. I suggest you ask a new question where you explain very precisely what you want to do. – Gilles 'SO- stop being evil' Aug 28 '15 at 17:49
  • 1
    http://serverfault.com/questions/481506/how-to-hot-backup-snapshot-an-ext4-partition-in-the-absence-of-lvm – Emer Nov 15 '15 at 11:54