Automation of snapshotting a zfs pool and sending it to S3, destroy the pool, recreate, and import the snapshot in order to fix ZFS Fragmentation
While this script does everything it can to ensure your data's integrety, this IS a destructive operation. Please make sure you have valid backups before beginning as we can not be responsible if something were to go wrong.
ZFS is a copy-on-write filesystem so when you edit a file, when it is saved it copies the entire file to another location on the disk. This prevents traditional fragmentation by keeping the entire file together. The issue is now your free space is fragmented so the OS and filesystem need to work harder to find places to put files. Currently ZFS has no plans to fix this and there is some further documentation here in ZFS Issue 3582 which itself has multiple links showing the issues. The long term fix is BPR (Block Pointer Rewrite) which is not currently on the roadmap.
You must have the following installed:
Run s3cmd --configure to setup your keys and connection to AWS S3.
Edit zfs_defrag.sh to point to the correct file which defaults to /root/.s3cmd.cfg
This will also work for any internally hosted S3 compliant service such as Riak, Ceph, LeoFS, etc.
On your server ensure all services which access you ZFS pools are stopped. To find out which mount points are ZFS pools run:
$ zfs list -o mountpoint
MOUNTPOINT
/data
/opt
Then simply ensure there are no open files on each one:
lsof /data
lsof /opt
At this time this script does not support ZVOLs. To quote Jim Salter
If you have a dataset that’s occupying 85% of your pool, you can snapshot that dataset any time you like. If you have a ZVOL that’s occupying 85% of your pool, you cannot snapshot it, period. This is one of those things that both tyros and vets tend to immediately balk at – I must be misunderstanding something, right? Surely it doesn’t work that way? Afraid it does. To see if you are currently using a zvol simply run :
zfs list -t volume
no datasets available
This is what you want to see.
Your options are as follows:
zfs-defrag.sh -c "zpool create -f data sdb log sdc1 cache sdc2"zfs-defgrag.sh -x "-o ashift=12"In general if you want your zfs pool to be setup exactly as it was you don't need any options: zfs-defrag.sh
zfs list and checks each one for open files.
zfs history ${POOL} to get the original create command in order to re-create it as is (unless one of the above options are given)zfs mount -aShell
100.0%
Automation of snapshotting a zfs pool and sending it to S3, destroy the pool, recreate, and import the snapshot in order to fix ZFS Fragmentation
While this script does everything it can to ensure your data's integrety, this IS a destructive operation. Please make sure you have valid backups before beginning as we can not be responsible if something were to go wrong.
ZFS is a copy-on-write filesystem so when you edit a file, when it is saved it copies the entire file to another location on the disk. This prevents traditional fragmentation by keeping the entire file together. The issue is now your free space is fragmented so the OS and filesystem need to work harder to find places to put files. Currently ZFS has no plans to fix this and there is some further documentation here in ZFS Issue 3582 which itself has multiple links showing the issues. The long term fix is BPR (Block Pointer Rewrite) which is not currently on the roadmap.
You must have the following installed:
Run s3cmd --configure to setup your keys and connection to AWS S3.
Edit zfs_defrag.sh to point to the correct file which defaults to /root/.s3cmd.cfg
This will also work for any internally hosted S3 compliant service such as Riak, Ceph, LeoFS, etc.
On your server ensure all services which access you ZFS pools are stopped. To find out which mount points are ZFS pools run:
$ zfs list -o mountpoint
MOUNTPOINT
/data
/opt
Then simply ensure there are no open files on each one:
lsof /data
lsof /opt
At this time this script does not support ZVOLs. To quote Jim Salter
If you have a dataset that’s occupying 85% of your pool, you can snapshot that dataset any time you like. If you have a ZVOL that’s occupying 85% of your pool, you cannot snapshot it, period. This is one of those things that both tyros and vets tend to immediately balk at – I must be misunderstanding something, right? Surely it doesn’t work that way? Afraid it does. To see if you are currently using a zvol simply run :
zfs list -t volume
no datasets available
This is what you want to see.
Your options are as follows:
zfs-defrag.sh -c "zpool create -f data sdb log sdc1 cache sdc2"zfs-defgrag.sh -x "-o ashift=12"In general if you want your zfs pool to be setup exactly as it was you don't need any options: zfs-defrag.sh
zfs list and checks each one for open files.
zfs history ${POOL} to get the original create command in order to re-create it as is (unless one of the above options are given)zfs mount -aShell
100.0%