Merge pull request #1286 from bergware/master

Add scheduled trimming of ZFS pools
This commit is contained in:
tom mortensen
2023-03-17 15:22:34 -07:00
committed by GitHub
2 changed files with 12 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
<?PHP
/* Copyright 2005-2022, Lime Technology
* Copyright 2012-2022, Bergware International.
/* Copyright 2005-2023, Lime Technology
* Copyright 2012-2023, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
@@ -20,6 +20,8 @@ if ($_POST['mode']>0) {
$dotm = isset($_POST['dotm']) ? $_POST['dotm'] : '*';
$day = isset($_POST['day']) ? $_POST['day'] : '*';
$cron = "# Generated ssd trim schedule:\n$min $hour $dotm * $day /sbin/fstrim -a -v | logger &> /dev/null\n";
exec("/usr/sbin/zpool status|grep -Po 'pool: \K.+'",$zfs_pools);
foreach ($zfs_pools as $pool) if ($pool) $cron .= "$min $hour $dotm * $day /usr/sbin/zpool trim $pool 2> /dev/null\n";
} else {
$cron = "";
}

View File

@@ -38,8 +38,16 @@ function write(...$messages){
}
write(_("SSD Trim started").". "._("Please wait")." ...\n");
// trim btrfs pools
$trim = popen('fstrim -a -v','r');
while (!feof($trim)) write(fgets($trim));
pclose($trim);
// trim zfs pools
exec("/usr/sbin/zpool status|grep -Po 'pool: \K.+'",$zfs_pools);
foreach ($zfs_pools as $pool) if ($pool) {
exec("/usr/sbin/zpool trim $pool");
write("ZFS pool: $pool trimmed\n");
}
write('_DONE_','');
?>