I just wrote this litte scrip to help me create/list/restore/destroy
subvolumes and snapshots. It is a really simple bash script that uses
the btrfsctl commandline utility. Here is a transcript of a short session:
$ ./bsu.sh create /pool/subvol
$ echo 1 > /pool/subvol/file
$ sync
$ ./bsu.sh create /pool/subvol@snapshot
$ echo 2 > /pool/subvol/file
$ sync
$ ./bsu.sh create /pool/subvol@snapshot2
$ ./bsu.sh list /pool/subvol
snapshot
snapshot2
$ ./bsu.sh restore /pool/subvol@snapshot
$ cat /pool/subvol/file
1
$ ./bsu.sh list /pool/subvol
snapshot
snapshot2
$ ./bsu.sh destroy /pool/subvol@snapshot
$ ./bsu.sh destroy /pool/subvol@snapshot2
$ ./bsu.sh destroy /pool/subvol
How it works: subvolumes are created as usual, snapshots are created in
a separate subvolume which is saved as .btrfs in the original subvolume.
Because the snapshots are kept separate, reverting to an earlier
snapshot doesn''t destroy newer snapshots.
The script can create nested subvolumes and snapshots of those, but
unfortunately snapshots don''t preserve subvolumes which are contained
within the original filesystem:
/pool/foo # <- subvol
/pool/foo/bar # <- subvol
btrfsctl -s copy /pool/foo
# /pool/copy/bar is a normal directory, not a subvolume and can be
deleted with a simple ''rmdir''
I don''t know if that is a bug or btrfs working as intended. Either way,
don''t use my script to create such nested subvolumes. It might or might
not badly break and delete all your data.
A shell script can only do so much, so if it were to be extended, it
would probably be worth investigating if rewriting it in C is viable. I
think especially handling the recursive features would be easier from C.
The script is available in my btrfs-tools repository on github:
http://github.com/wereHamster/btrfs-tools
tom
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs"
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html