forked from kdave/btrfsmaintenance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btrfs-trim.sh
executable file
·49 lines (42 loc) · 1020 Bytes
/
btrfs-trim.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
#
# Copyright (c) 2014 SuSE Linux AG, Nuernberg, Germany.
#
# please send bugfixes or comments to http://www.suse.de/feedback.
#
# paranoia settings
#
umask 022
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
if [ -f /etc/sysconfig/btrfsmaintenance ] ; then
. /etc/sysconfig/btrfsmaintenance
fi
if [ -f /etc/default/btrfsmaintenance ] ; then
. /etc/default/btrfsmaintenance
fi
LOGIDENTIFIER='btrfs-trim'
. $(dirname $(realpath $0))/btrfsmaintenance-functions
{
evaluate_auto_mountpoint BTRFS_TRIM_MOUNTPOINTS
OIFS="$IFS"
IFS=:
exec 2>&1 # redirect stderr to stdout to catch all output to log destination
for MNT in $BTRFS_TRIM_MOUNTPOINTS; do
IFS="$OIFS"
if [ $(stat -f --format=%T "$MNT") != "btrfs" ]; then
echo "Path $MNT is not btrfs, skipping"
continue
fi
echo "Running fstrim on $MNT"
fstrim "$MNT"
done
} | \
case "$BTRFS_LOG_OUTPUT" in
stdout) cat;;
journal) systemd-cat -t "$LOGIDENTIFIER";;
syslog) logger -t "$LOGIDENTIFIER";;
none) cat >/dev/null;;
*) cat;;
esac
exit 0