ZFS: Rollback snapshot but keep newer snapshots [closed]
Asked Answered
C

1

9

I have following ZFS Snapshots:

data/server/dev1@snap1
data/server/dev1@snap2
data/server/dev1@snap3

If i want to rollback to snap1, i would do the following:

zfs rollback data/server/dev1@snap1

but ZFS returns:

more recent snapshots or bookmarks exist
use '-r' to force deletion..

I know there is the possibility to simply copy the files out of /data/server/dev1/.zfs/snapshot/snap1 into /data/server/dev1 but that takes much longer than a zfs rollback.

Is there a way to do the rollback AND keep the newer snapshots snap2 & snap3?

Update 21/11/2016

It looks like there is a way to do this. I read about working with zfs promote and zfs clone but I could not figure out how it exactly works.

Courteous answered 17/11, 2016 at 15:37 Comment(3)
The only ways I can think of would involve cloning the snapshot you want to roll back to. See this zfsonlinux thread: list.zfsonlinux.org/pipermail/zfs-discuss/2015-July/022805.htmlFransiscafransisco
Thanks. How is that done? I can create a clone with zfs clone data/server/dev1@snap1 data/server/dev1-temp for example. How can I rollback from that? A simple zfs rollback returns operation not applicable to datasets of this typeCourteous
This question should be on Server Fault as it's not related to programming.Merengue
T
13

I think your comment is pretty close to getting you what you want. However, you could rename the file system before cloning then clone to the name of the original file system. For example:

zfs rename data/server/dev1 data/server/dev2 
zfs clone data/server/dev2@snap1 data/server/dev1

You don't have to worry about promoting until you need to delete data/server/dev2@snap1

The zfs man page has a more complete example that may or may not address your needs more specifically:

The following commands illustrate how to test out changes to a file system, and then replace the original file system with the changed one, using clones, clone promotion, and renaming:

     # zfs create pool/project/production
       populate /pool/project/production with data
     # zfs snapshot pool/project/production@today
     # zfs clone pool/project/production@today pool/project/beta
     make changes to /pool/project/beta and test them
     # zfs promote pool/project/beta
     # zfs rename pool/project/production pool/project/legacy
     # zfs rename pool/project/beta pool/project/production
     once the legacy version is no longer needed, it can be destroyed
     # zfs destroy pool/project/legacy
Tonne answered 11/1, 2017 at 19:15 Comment(2)
Thank you. Your solution seems to work. Meanwhile, I managed it by copying the files. As it's already used in a script on production environment, I first have to take a further look at it.Courteous
Glad it seems to work...good luck with the production environment implementation!Tonne

© 2022 - 2024 — McMap. All rights reserved.