Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Say I have a dataset with 100 snapshots and want to rm -rf all folders named "cache" in all snapshots.

I want to actually free up the space, not just hide it away in layers of snapshots, so making a clone and removing from that and then taking a new snapshot doesn't seem to do what I want.

Any semi-automatical way do that? Some wrapping around zfs list -t snapshot, zfs clone, zfs promote, zfs snapshot?

(cross-posting from http://superuser.com/questions/313197 since I see this has more ZFS stuff)

share|improve this question
3  
Please do not crosspost, but wait for your question to be migrated. –  SvW Jul 22 '11 at 12:16
    
Also, I am not sure this is at all possible: Snapshots are read-only, and if you use the clone/promote pair, you will reverse the dependency between the cloned snapshot and the "HEAD" dataset, which is likely not what you want. See the doc here: download.oracle.com/docs/cd/E19253-01/819-5461/gbcxz/index.html –  SvW Jul 22 '11 at 12:33
    
I would wait for migration, but seemed to be a fair amount of ZFS questions on SU as well so I doubted it would be automatically moved...it fits in both places, so I followed a meta guide for how to be nice about cross-posting. –  Tino Didriksen Jul 22 '11 at 13:50
    
@TinoDidriksen could you provide a reference to that meta post please? I'd like to see it. Thanks. –  nhinkle Jul 22 '11 at 23:19
2  
The post you referenced is not an official policy. There is an FAQ on MSO explaining how to handle questions the user thinks are on topic for multiple sites. To summarize, cross posting is disallowed. If you decide after you post that it would be better elsewhere and you haven't gotten good answers, you can flag it to be migrated or you can delete it and re-ask, but you must tailor the post to the site you're asking on. You reposted the exact same question word-for-word without waiting, which fails the guidelines in both meta posts about cross posting. –  nhinkle Jul 23 '11 at 21:34
show 1 more comment

3 Answers

up vote 4 down vote accepted

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.

share|improve this answer
2  
The real bummer with this solution is that you now have to store every bit of data n times for real, while a snapshot would only store modified blocks. This way, you likely end up with much more space needed than you saved with deleting the caches from the tar files. –  SvW Jul 22 '11 at 12:51
    
Dedupe would help with that, but your are correct. I'm fairly sure there isn't any way of modifying those snapshots the way he wants though. –  Chris S Jul 22 '11 at 12:54
    
I have both gzip-1 compression and dedup on, so copying around identical data only takes up bookkeeping space. But I would of course like some way to avoid copying at all. –  Tino Didriksen Jul 22 '11 at 13:55
    
I doubt that in case of multiple tar files of nearly the same data dedup would help that much, as adding or subtracting only one byte at the beginning of the file would mean that no block would be identical to another, rendering dedup useless. –  SvW Jul 22 '11 at 14:15
    
@SvenW After rereading the question I see he's doing this to try and save space; which my answer really isn't helping with unless he moves the tar files off the computer, which he could just export the snapshots anyway. Sounds like he's stuck all around. –  Chris S Jul 22 '11 at 14:35
show 1 more comment

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.

share|improve this answer
add comment

The ZFS snapshots for a particular ZFS filesystem can be found under the .zfs/snapshotsdirectory in the root of the filesystem. You should be able to write a script that traverses this folder and rm's the files that you need, which should delete it from the snapshots themselves.

share|improve this answer
2  
ZFS snapshots are read-only. You can't delete from them. –  SvW Jul 22 '11 at 12:17
    
My bad, not sure where I'd got the impression you could :( –  growse Jul 22 '11 at 14:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.