Hello community, here is the log from the commit of package btrfsmaintenance for openSUSE:Factory checked in at 2018-01-20 11:28:12 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/btrfsmaintenance (Old) and /work/SRC/openSUSE:Factory/.btrfsmaintenance.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "btrfsmaintenance" Sat Jan 20 11:28:12 2018 rev:14 rq:567779 version:0.4 Changes: -------- --- /work/SRC/openSUSE:Factory/btrfsmaintenance/btrfsmaintenance.changes 2017-12-22 12:21:33.447842581 +0100 +++ /work/SRC/openSUSE:Factory/.btrfsmaintenance.new/btrfsmaintenance.changes 2018-01-20 11:28:15.560032082 +0100 @@ -1,0 +2,28 @@ +Mon Jan 15 00:00:00 CET 2018 - dsterba@suse.cz + +- update to version 0.4 + - add support for systemd timers and use them by default; the alternative + cron scripts are still present (#29, #36) + - add automatic monitoring (via systemd.path) of the config file, + no manual updates by btrfsmaintenance-refresh.service needed (#38) + - fix RPM database path detection + - spec file cleanups + - documentation updates +- removed patches: + - btrfsmaintenance-0.3.1-fix-rpm-db-path.patch (upstream) + - btrfsmaintenance-switch-to-timer.patch (upstream) + - pull-request-36.patch (upstream) + +------------------------------------------------------------------- +Fri Dec 22 18:42:10 UTC 2017 - antoine.belvire@opensuse.org + +- Fix systemd timers enabled even if period is set to none: + * Micro change in pull-request-36.patch (bsc#1075884) +- Clean spec file: + * Removed support for suse_version <= 1210. + * Removed call to btrfsmaintenance-refresh-cron.sh upon deletion + (not needed anymore since we use systemd timers which are + handled by macros). + * Ran spec-cleaner. + +------------------------------------------------------------------- Old: ---- btrfsmaintenance-0.3.1-fix-rpm-db-path.patch btrfsmaintenance-0.3.1.tar.bz2 btrfsmaintenance-switch-to-timer.patch pull-request-36.patch New: ---- btrfsmaintenance-0.4.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ btrfsmaintenance.spec ++++++ --- /var/tmp/diff_new_pack.wwZzjn/_old 2018-01-20 11:28:16.251999720 +0100 +++ /var/tmp/diff_new_pack.wwZzjn/_new 2018-01-20 11:28:16.255999534 +0100 @@ -1,7 +1,7 @@ # # spec file for package btrfsmaintenance # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -22,28 +22,20 @@ %endif Name: btrfsmaintenance -Version: 0.3.1 +Version: 0.4 Release: 0 Summary: Scripts for btrfs periodic maintenance tasks License: GPL-2.0 Group: System/Base Url: https://github.com/kdave/btrfsmaintenance Source0: %{name}-%{version}.tar.bz2 -# PATCH-FIX-OPENSUSE btrfsmaintenance-0.3.1-fix-rpm-db-path.patch -- Fix RPM database path for Tumbleweed -Patch0: btrfsmaintenance-0.3.1-fix-rpm-db-path.patch -Patch1: pull-request-36.patch -Patch2: btrfsmaintenance-switch-to-timer.patch +BuildRequires: systemd +Requires: btrfsprogs Requires: zypp-plugin-python Requires: libzypp(plugin:commit) -#Recommends: cron Supplements: btrfsprogs -Requires: btrfsprogs -BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch %{?systemd_requires} -%if 0%{?suse_version} >= 1210 -BuildRequires: systemd -%endif %description Scripts for btrfs maintenance tasks like periodic scrub, balance, trim or defrag @@ -51,20 +43,11 @@ %prep %setup -q -%if 0%{?suse_version} > 1320 -%patch0 -%endif -%patch1 -p1 -%patch2 -p0 %build %install -# fix build error on openSUSE and SLE -mkdir -p %{buildroot}%{_sysconfdir}/cron.daily/ -mkdir -p %{buildroot}%{_sysconfdir}/cron.weekly/ -mkdir -p %{buildroot}%{_sysconfdir}/cron.monthly/ - +# scripts install -m 755 -d %{buildroot}%{_datadir}/%{name} install -m 755 btrfs-defrag.sh %{buildroot}%{_datadir}/%{name} install -m 755 btrfs-balance.sh %{buildroot}%{_datadir}/%{name} @@ -73,7 +56,7 @@ install -m 755 btrfsmaintenance-refresh-cron.sh %{buildroot}%{_datadir}/%{name} install -m 644 btrfsmaintenance-functions %{buildroot}%{_datadir}/%{name} -%if 0%{?suse_version} >= 1210 +# systemd services and timers install -m 755 -d %{buildroot}%{_unitdir} install -m 644 -D btrfsmaintenance-refresh.service %{buildroot}%{_unitdir} install -m 644 -D btrfs-balance.service %{buildroot}%{_unitdir} @@ -86,62 +69,40 @@ install -m 644 -D btrfs-trim.timer %{buildroot}%{_unitdir} install -m 755 -d %{buildroot}%{_sbindir} ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcbtrfsmaintenance-refresh -%else -# just a hack, but sufficient -install -m 755 -d %{buildroot}%{_sysconfdir}/cron.hourly -ln -s %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh %{buildroot}%{_sysconfdir}/cron.hourly/ -%endif -install -m 755 -d %{buildroot}/usr/lib/zypp/plugins/commit -install -m 755 -D btrfs-defrag-plugin.py %{buildroot}/usr/lib/zypp/plugins/commit +# zypp plugin +install -m 755 -d %{buildroot}%{_libexecdir}/zypp/plugins/commit +install -m 755 -D btrfs-defrag-plugin.py %{buildroot}%{_libexecdir}/zypp/plugins/commit +# config install -m 755 -d %{buildroot}%{_fillupdir} install -m 644 -D sysconfig.btrfsmaintenance %{buildroot}%{_fillupdir} -%post -%service_add_post btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer -%{fillup_only btrfsmaintenance} - -%if 0%{?suse_version} >= 1210 - %pre # if the new service files don't exist, we migrate from # old version with old script, remove cron symlinks [ ! -f %{_unitdir}/btrfs-balance.timer -a -f %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh ] && %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh uninstall %service_add_pre btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer +%post +%service_add_post btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer +%{fillup_only btrfsmaintenance} + %preun %service_del_preun btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer -if [ $1 -eq 0 ]; then - # Remove cron files in %%preun only if it's a package removal. - # If it's an upgrade, the %%post section of the new package has - # already refreshed the cron links, so we shall not remove them. - %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh systemd-timer uninstall -fi %postun %service_del_postun btrfsmaintenance-refresh.service btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer -%endif - -%if 0%{?suse_version} < 1210 - -%preun -if [ $1 -eq 0 ]; then - %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh uninstall -fi -%endif %files -%defattr(-,root,root) %doc COPYING README.md %{_fillupdir}/sysconfig.btrfsmaintenance %dir %{_datadir}/%{name} %{_datadir}/%{name}/* -%dir /usr/lib/zypp/ -%dir /usr/lib/zypp/plugins -%dir /usr/lib/zypp/plugins/commit -/usr/lib/zypp/plugins/commit/btrfs-defrag-plugin.py -%if 0%{?suse_version} >= 1210 +%dir %{_libexecdir}/zypp/ +%dir %{_libexecdir}/zypp/plugins +%dir %{_libexecdir}/zypp/plugins/commit +%{_libexecdir}/zypp/plugins/commit/btrfs-defrag-plugin.py %{_unitdir}/btrfsmaintenance-refresh.service %{_unitdir}/btrfs-balance.service %{_unitdir}/btrfs-defrag.service @@ -152,8 +113,5 @@ %{_unitdir}/btrfs-scrub.timer %{_unitdir}/btrfs-trim.timer %{_sbindir}/rcbtrfsmaintenance-refresh -%else -%{_sysconfdir}/cron.hourly/btrfsmaintenance-refresh-cron.sh -%endif %changelog ++++++ btrfsmaintenance-0.3.1.tar.bz2 -> btrfsmaintenance-0.4.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/README.md new/btrfsmaintenance-0.4/README.md --- old/btrfsmaintenance-0.3.1/README.md 2017-04-07 14:41:46.299279436 +0200 +++ new/btrfsmaintenance-0.4/README.md 2018-01-15 17:40:06.397987125 +0100 @@ -1,6 +1,11 @@ Btrfs maintenance toolbox ========================= +Table of contents: +* [Quick start](#quick-start) +* [Distro integration](#distro-integration) +* [Tuning periodic snapshotting](#tuning-periodic-snapshotting) + This is a set of scripts supplementing the btrfs filesystem and aims to automate a few maintenance tasks. This means the *scrub*, *balance*, *trim* or *defragmentation*. @@ -109,27 +114,49 @@ convenience and not necessary as defragmentation needs are usually different for various types of data. +Please note that the defragmentation process does not descend to other mount +points and nested subvolumes or snapshots. All nested paths would need to be +enumerated in the respective config variable. The command utilizes `find +-xdev`, you can use that to verify in advance which paths will the +defragmentation affect. + __Special case:__ There's a separate defragmentation task that happens automatically and -defragments only the RPM database files in */var/lib/rpm*. This is done via a -*zypper* plugin and the defrag pass triggers at the end of the installation. +defragments only the RPM database files. This is done via a *zypper* plugin +and the defrag pass triggers at the end of the installation. This improves reading the RPM databases later, but the installation process fragments the files very quickly so it's not likely to bring a significant speedup here. -## Other ## +## Periodic scheduling ## + +There are now two ways how to schedule and run the periodic tasks: cron and +systemd timers. Only one can be active on a system and this should be decided +at the installation time. + +### Cron ### Cron takes care of periodic execution of the scripts, but they can be run any time directly from `/usr/share/btrfs/maintenance/`, respecting the configured values in `/etc/sysconfig/btrfsmaintenance`. -If the period is changed manually, the cron symlinks have to be refreshed, use -`systemctl restart btrfsmaintenance-refresh` (or the -`rcbtrfsmaintenance-refresh` shortcut). Changing the period via *yast2* sysconfig -editor triggers the refresh automatically. +The changes to configuration file need to be refleced in the `/etc/cron` +directories where the scripts are linked for the given period. + +If the period is changed, the cron symlinks have to be refreshed: + +* manually -- use `systemctl restart btrfsmaintenance-refresh` (or the `rcbtrfsmaintenance-refresh` shortcut) +* in *yast2* -- sysconfig editor triggers the refresh automatically +* using a file watcher -- if you install `btrfsmaintenance-refresh.path`, this will utilize the file monitor to detect changes and will run the refresh + +### Systemd timers ### + +There's a set of timer units that run the respective task script. The periods +are configured in the `/etc/sysconfig/btrfsmaintenance` file as well. The +timers have to be installed using a similar way as cron. ## Quick start ## @@ -146,7 +173,7 @@ ### Installation ### -For debian based systems, run `debian-install.sh` as root. +For debian based systems, run `dist-install.sh` as root. For non-debian based systems, check for distro provided package or do manual installation of files as described below. @@ -170,6 +197,10 @@ configuration tool if it's capable of running post-change scripts or services. In that case there's `btrfsmaintenance-refresh.service` systemd service. +This service can also be automatically started upon any modification of the +configuration file in `/etc/sysconfig/btrfsmaintenance` by installing the +`btrfsmaintenance-refresh.path` systemd watcher. + ### Post-update defragmentation ### The package database files tend to be updated in a random way and get @@ -298,6 +329,7 @@ TIMELINE_LIMIT_HOURLY="12" TIMELINE_LIMIT_DAILY="5" + TIMELINE_LIMIT_WEEKLY="2" TIMELINE_LIMIT_MONTHLY="1" TIMELINE_LIMIT_YEARLY="0" @@ -315,6 +347,7 @@ TIMELINE_LIMIT_HOURLY="12" TIMELINE_LIMIT_DAILY="7" + TIMELINE_LIMIT_WEEKLY="4" TIMELINE_LIMIT_MONTHLY="6" TIMELINE_LIMIT_YEARLY="1" @@ -327,6 +360,7 @@ TIMELINE_LIMIT_HOURLY="12" TIMELINE_LIMIT_DAILY="7" + TIMELINE_LIMIT_WEEKLY="4" TIMELINE_LIMIT_MONTHLY="6" TIMELINE_LIMIT_YEARLY="0" @@ -351,9 +385,19 @@ TIMELINE_LIMIT_HOURLY="12" TIMELINE_LIMIT_DAILY="7" + TIMELINE_LIMIT_WEEKLY="1" TIMELINE_LIMIT_MONTHLY="0" TIMELINE_LIMIT_YEARLY="0" +### Summary + +| Type | Hourly | Daily | Weekly | Monthly | Yearly | +--- | ---: | ---: | ---: | ---: | ---: | +| Rolling | 12 | 5 | 2 | 1 | 0 | +| Regular | 12 | 7 | 4 | 6 | 1 | +| Big files | 12 | 7 | 4 | 6 | 0 | +| Mixed | 12 | 7 | 1 | 0 | 0 | + ## About ## The goal of this project is to help administering btrfs filesystems. It is not diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-balance.service new/btrfsmaintenance-0.4/btrfs-balance.service --- old/btrfsmaintenance-0.3.1/btrfs-balance.service 1970-01-01 01:00:00.000000000 +0100 +++ new/btrfsmaintenance-0.4/btrfs-balance.service 2018-01-15 17:40:06.389987125 +0100 @@ -0,0 +1,10 @@ +[Unit] +Description=Balance block groups on a btrfs filesystem +Documentation=man:btrfs-balance +After=fstrim.service btrfs-trim.service btrfs-scrub.service + +[Service] +Type=oneshot +ExecStart=/usr/share/btrfsmaintenance/btrfs-balance.sh +IOSchedulingClass=idle +CPUSchedulingPolicy=idle diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-balance.sh new/btrfsmaintenance-0.4/btrfs-balance.sh --- old/btrfsmaintenance-0.3.1/btrfs-balance.sh 2017-04-07 14:41:46.271278542 +0200 +++ new/btrfsmaintenance-0.4/btrfs-balance.sh 2018-01-15 17:40:06.385987125 +0100 @@ -1,12 +1,7 @@ #!/bin/sh # -# Copyright (c) 2014 SuSE Linux AG, Nuernberg, Germany. -# -# please send bugfixes or comments to http://www.suse.de/feedback. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. -# -# paranoia settings -# umask 022 PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-balance.timer new/btrfsmaintenance-0.4/btrfs-balance.timer --- old/btrfsmaintenance-0.3.1/btrfs-balance.timer 1970-01-01 01:00:00.000000000 +0100 +++ new/btrfsmaintenance-0.4/btrfs-balance.timer 2018-01-15 17:40:06.389987125 +0100 @@ -0,0 +1,11 @@ +[Unit] +Description=Balance block groups on a btrfs filesystem +Documentation=man:btrfs-balance + +[Timer] +OnCalendar=monthly +AccuracySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-defrag-plugin.py new/btrfsmaintenance-0.4/btrfs-defrag-plugin.py --- old/btrfsmaintenance-0.3.1/btrfs-defrag-plugin.py 2017-04-07 14:41:46.267278415 +0200 +++ new/btrfsmaintenance-0.4/btrfs-defrag-plugin.py 2018-01-15 17:40:06.381987125 +0100 @@ -2,9 +2,9 @@ # This plugin defragments rpm files after update. # -# If the filesystem is btrfs, run defrag command in /var/lib/rpm, set the -# desired extent size to 64MiB, but this may change in the result depending -# on the fragmentation of the free space +# If the filesystem is btrfs, run defrag command in the RPM database +# folder, set the desired extent size to 64MiB, but this may change in the +# result depending on the fragmentation of the free space. # # Why 64MB: # - the worst fragmentation has been observed on Packages @@ -24,7 +24,7 @@ DEBUG=False EXTENT_SIZE=64*1024*1024 LOGFILE='/tmp/btrfs-defrag-plugin.log' -PATH='/var/lib/rpm' +PATH=subprocess.check_output(["rpm", "--eval", "%_dbpath"]).strip() def dbg(args): if not DEBUG: return diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-defrag.service new/btrfsmaintenance-0.4/btrfs-defrag.service --- old/btrfsmaintenance-0.3.1/btrfs-defrag.service 1970-01-01 01:00:00.000000000 +0100 +++ new/btrfsmaintenance-0.4/btrfs-defrag.service 2018-01-15 17:40:06.389987125 +0100 @@ -0,0 +1,10 @@ +[Unit] +Description=Defragment file data on a mounted filesystem +Documentation=man:btrfs-filesystem +After=fstrim.service btrfs-trim.service btrfs-scrub.service + +[Service] +Type=oneshot +ExecStart=/usr/share/btrfsmaintenance/btrfs-defrag.sh +IOSchedulingClass=idle +CPUSchedulingPolicy=idle diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-defrag.sh new/btrfsmaintenance-0.4/btrfs-defrag.sh --- old/btrfsmaintenance-0.3.1/btrfs-defrag.sh 2017-04-07 14:41:46.275278670 +0200 +++ new/btrfsmaintenance-0.4/btrfs-defrag.sh 2018-01-15 17:40:06.385987125 +0100 @@ -1,12 +1,7 @@ #!/bin/sh # -# Copyright (c) 2014 SuSE Linux AG, Nuernberg, Germany. -# -# please send bugfixes or comments to http://www.suse.de/feedback. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. -# -# paranoia settings -# umask 022 PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-defrag.timer new/btrfsmaintenance-0.4/btrfs-defrag.timer --- old/btrfsmaintenance-0.3.1/btrfs-defrag.timer 1970-01-01 01:00:00.000000000 +0100 +++ new/btrfsmaintenance-0.4/btrfs-defrag.timer 2018-01-15 17:40:06.389987125 +0100 @@ -0,0 +1,11 @@ +[Unit] +Description=Defragment file data and/or directory metadata +Documentation=man:btrfs-filesystem + +[Timer] +OnCalendar=monthly +AccuracySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-scrub.service new/btrfsmaintenance-0.4/btrfs-scrub.service --- old/btrfsmaintenance-0.3.1/btrfs-scrub.service 1970-01-01 01:00:00.000000000 +0100 +++ new/btrfsmaintenance-0.4/btrfs-scrub.service 2018-01-15 17:40:06.389987125 +0100 @@ -0,0 +1,10 @@ +[Unit] +Description=Scrub btrfs filesystem, verify block checksums +Documentation=man:fstrim +After=fstrim.service btrfs-trim.service + +[Service] +Type=oneshot +ExecStart=/usr/share/btrfsmaintenance/btrfs-scrub.sh +IOSchedulingClass=idle +CPUSchedulingPolicy=idle diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-scrub.sh new/btrfsmaintenance-0.4/btrfs-scrub.sh --- old/btrfsmaintenance-0.3.1/btrfs-scrub.sh 2017-04-07 14:41:46.275278670 +0200 +++ new/btrfsmaintenance-0.4/btrfs-scrub.sh 2018-01-15 17:40:06.385987125 +0100 @@ -1,12 +1,7 @@ #!/bin/sh # -# Copyright (c) 2014 SuSE Linux AG, Nuernberg, Germany. -# -# please send bugfixes or comments to http://www.suse.de/feedback. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. -# -# paranoia settings -# umask 022 PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-scrub.timer new/btrfsmaintenance-0.4/btrfs-scrub.timer --- old/btrfsmaintenance-0.3.1/btrfs-scrub.timer 1970-01-01 01:00:00.000000000 +0100 +++ new/btrfsmaintenance-0.4/btrfs-scrub.timer 2018-01-15 17:40:06.389987125 +0100 @@ -0,0 +1,11 @@ +[Unit] +Description=Scrub btrfs filesystem, verify block checksums +Documentation=man:btrfs-scrub + +[Timer] +OnCalendar=monthly +AccuracySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-trim.service new/btrfsmaintenance-0.4/btrfs-trim.service --- old/btrfsmaintenance-0.3.1/btrfs-trim.service 1970-01-01 01:00:00.000000000 +0100 +++ new/btrfsmaintenance-0.4/btrfs-trim.service 2018-01-15 17:40:06.389987125 +0100 @@ -0,0 +1,10 @@ +[Unit] +Description=Discard unused blocks on a mounted filesystem +Documentation=man:fstrim +Conflicts=fstrim.service + +[Service] +Type=oneshot +ExecStart=/usr/share/btrfsmaintenance/btrfs-trim.sh +IOSchedulingClass=idle +CPUSchedulingPolicy=idle diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-trim.sh new/btrfsmaintenance-0.4/btrfs-trim.sh --- old/btrfsmaintenance-0.3.1/btrfs-trim.sh 2017-04-07 14:41:46.279278798 +0200 +++ new/btrfsmaintenance-0.4/btrfs-trim.sh 2018-01-15 17:40:06.385987125 +0100 @@ -1,12 +1,7 @@ #!/bin/sh # -# Copyright (c) 2014 SuSE Linux AG, Nuernberg, Germany. -# -# please send bugfixes or comments to http://www.suse.de/feedback. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. -# -# paranoia settings -# umask 022 PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfs-trim.timer new/btrfsmaintenance-0.4/btrfs-trim.timer --- old/btrfsmaintenance-0.3.1/btrfs-trim.timer 1970-01-01 01:00:00.000000000 +0100 +++ new/btrfsmaintenance-0.4/btrfs-trim.timer 2018-01-15 17:40:06.389987125 +0100 @@ -0,0 +1,11 @@ +[Unit] +Description=Discard unused blocks on a mounted filesystem +Documentation=man:fstrim + +[Timer] +OnCalendar=monthly +AccuracySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfsmaintenance-refresh-cron.sh new/btrfsmaintenance-0.4/btrfsmaintenance-refresh-cron.sh --- old/btrfsmaintenance-0.3.1/btrfsmaintenance-refresh-cron.sh 2017-04-07 14:41:46.275278670 +0200 +++ new/btrfsmaintenance-0.4/btrfsmaintenance-refresh-cron.sh 2018-01-15 17:40:06.385987125 +0100 @@ -1,32 +1,16 @@ #!/bin/sh # -# Copyright (c) 2014 SuSE Linux AG, Nuernberg, Germany. -# -# please send bugfixes or comments to http://www.suse.de/feedback. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. # Adjust symlinks of btrfs maintenance services according to the configs. # Run with 'uninstall' to remove them again -# -# paranoia settings -# umask 022 PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH SCRIPTS=/usr/share/btrfsmaintenance -if [ "$1" = 'uninstall' ]; then - for SCRIPT in btrfs-scrub.sh btrfs-defrag.sh btrfs-balance.sh btrfs-trim.sh; do - for PERIOD in daily weekly monthly; do - LINK="${SCRIPT%.*}" - FILE="/etc/cron.$PERIOD/$LINK" - rm -f "$FILE" - done - done - exit 0 -fi - if [ -f /etc/sysconfig/btrfsmaintenance ]; then . /etc/sysconfig/btrfsmaintenance fi @@ -35,7 +19,18 @@ . /etc/default/btrfsmaintenance fi -refresh_period() { +case "$1" in + cron) + BTRFS_TIMER_IMPLEMENTATION="cron" + shift + ;; + systemd-timer|timer) + BTRFS_TIMER_IMPLEMENTATION="systemd-timer" + shift + ;; +esac + +refresh_cron() { EXPECTED="$1" SCRIPT="$2" echo "Refresh script $SCRIPT for $EXPECTED" @@ -52,7 +47,59 @@ done } -refresh_period "$BTRFS_SCRUB_PERIOD" btrfs-scrub.sh -refresh_period "$BTRFS_DEFRAG_PERIOD" btrfs-defrag.sh -refresh_period "$BTRFS_BALANCE_PERIOD" btrfs-balance.sh -refresh_period "$BTRFS_TRIM_PERIOD" btrfs-trim.sh +refresh_timer() { + PERIOD="$1" + SERVICE="$2" + echo "Refresh timer $SERVICE for $PERIOD" + + case "$PERIOD" in + uninstall|none) + systemctl stop "$SERVICE".timer &> /dev/null + systemctl disable "$SERVICE".timer &> /dev/null + rm -rf /etc/systemd/system/"$SERVICE".timer.d + ;; + *) + mkdir -p /etc/systemd/system/"$SERVICE".timer.d/ + cat << EOF > /etc/systemd/system/"$SERVICE".timer.d/schedule.conf +[Timer] +OnCalendar=$PERIOD +EOF + systemctl enable "$SERVICE".timer &> /dev/null + systemctl start "$SERVICE".timer &> /dev/null + ;; + esac +} + +if [ "$1" = 'uninstall' ]; then + for SCRIPT in btrfs-scrub btrfs-defrag btrfs-balance btrfs-trim; do + case "$BTRFS_TIMER_IMPLEMENTATION" in + systemd-timer) + refresh_timer uninstall ${SCRIPT} + ;; + *) + refresh_cron uninstall ${SCRIPT}.sh + ;; + esac + done + exit 0 +fi + +case "$BTRFS_TIMER_IMPLEMENTATION" in + systemd-timer) + # Deinstall cron jobs, don't run it twice. + for SCRIPT in btrfs-scrub btrfs-defrag btrfs-balance btrfs-trim; do + refresh_cron uninstall ${SCRIPT}.sh + done + refresh_timer "$BTRFS_SCRUB_PERIOD" btrfs-scrub + refresh_timer "$BTRFS_DEFRAG_PERIOD" btrfs-defrag + refresh_timer "$BTRFS_BALANCE_PERIOD" btrfs-balance + refresh_timer "$BTRFS_TRIM_PERIOD" btrfs-trim + ;; + *) + refresh_cron "$BTRFS_SCRUB_PERIOD" btrfs-scrub.sh + refresh_cron "$BTRFS_DEFRAG_PERIOD" btrfs-defrag.sh + refresh_cron "$BTRFS_BALANCE_PERIOD" btrfs-balance.sh + refresh_cron "$BTRFS_TRIM_PERIOD" btrfs-trim.sh + ;; +esac + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfsmaintenance-refresh.path new/btrfsmaintenance-0.4/btrfsmaintenance-refresh.path --- old/btrfsmaintenance-0.3.1/btrfsmaintenance-refresh.path 1970-01-01 01:00:00.000000000 +0100 +++ new/btrfsmaintenance-0.4/btrfsmaintenance-refresh.path 2018-01-15 17:40:06.393987125 +0100 @@ -0,0 +1,8 @@ +[Unit] +Description=Watch /etc/sysconfig/btrfsmaintenance + +[Path] +PathChanged=/etc/sysconfig/btrfsmaintenance + +[Install] +WantedBy=multi-user.target diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/btrfsmaintenance-refresh.service new/btrfsmaintenance-0.4/btrfsmaintenance-refresh.service --- old/btrfsmaintenance-0.3.1/btrfsmaintenance-refresh.service 2017-04-07 14:41:46.283278925 +0200 +++ new/btrfsmaintenance-0.4/btrfsmaintenance-refresh.service 2018-01-15 17:40:06.389987125 +0100 @@ -3,8 +3,9 @@ After=local-fs.target [Service] -ExecStart=/usr/share/btrfsmaintenance/btrfsmaintenance-refresh-cron.sh +ExecStart=/usr/share/btrfsmaintenance/btrfsmaintenance-refresh-cron.sh systemd-timer Type=oneshot [Install] +Also=btrfsmaintenance-refresh.path WantedBy=multi-user.target diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/btrfsmaintenance-0.3.1/sysconfig.btrfsmaintenance new/btrfsmaintenance-0.4/sysconfig.btrfsmaintenance --- old/btrfsmaintenance-0.3.1/sysconfig.btrfsmaintenance 2017-04-07 14:41:46.291279180 +0200 +++ new/btrfsmaintenance-0.4/sysconfig.btrfsmaintenance 2018-01-15 17:40:06.393987125 +0100 @@ -10,7 +10,9 @@ ## Type: string ## Default: "" # -# Run periodic defrag on selected paths. +# Run periodic defrag on selected paths. The files from a given path do not +# cross mount points or other subvolumes/snapshots. If you want to defragment +# nested subvolumes, all have to be listed in this variable. # (Colon separated paths) BTRFS_DEFRAG_PATHS=""