ZFS: Removing files from snapshots?

Solution 1:

Snapshots are read-only. If you need those folders gone then you have to delete the whole snapshot.

You can make a backup (with something like tar), excluding the offending folders, then delete the snapshot. Obviously the backup is now in tar, or whatever, format; but at least you still have a backup copy.

Solution 2:

You could try the following:

  1. Clone the oldest snapshot into a new filesystem (call it fsnew).
  2. Promote the clone (fsnew) to allow you to destroy the snapshot the filesystem is based on.
  3. Remove the offending files.
  4. Create a snapshot of fsnew.

Now foreach snapshot after, rsync with the --inplace flag from the snapshot to fsnew skipping over files you do not want. The --inplace flag reduces the number of writes and allows for smaller snapshots.

  1. Create a snapshot of fsnew.
  2. Destroy the original snapshot.

When this is done, you should have a snapshot on fsnew that corresponds to the snapshots from the original filesystem with the offending files removed.

If you have the space on the drive, you may want to skip the "destroy" command until you have got your script working right.

Solution 3:

  1. Destroy the original snapshot.

You cannot destroy orig snapshot after promote action. Only if so destroy parent dataset.

example (after promote clone).

zfs destroy media1/cheers/[email protected]

cannot destroy 'media1/cheers/[email protected]': snapshot has dependent clones

use '-R' to destroy the following datasets:

media1/media/[email protected]

media1/media/backup

zfs destroy media1/media/[email protected]

zfs destroy media1/cheers/[email protected]

cannot destroy 'media1/cheers/[email protected]': snapshot has dependent clones

use '-R' to destroy the following datasets:

media1/media/backup

After that "funny" operation, I must make next ones

zfs snapshot media1/media/backup@1

zfs send media1/media/backup@1 | pv | zfs receive media1/media/backupnew

zfs destroy media1/media/backup@1

zfs destroy -R media1/media/backup

zfs rename media1/media/backupnew media1/media/backup

OR invert promote one. zfs promote media1/media/backup and after it delete clone anuway, because you will be have a big snapshot in src place))

Only rsync/backup can help here.