# along with this program; if not, write the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
scrub_all=0
+snap_size_mb=256
conffile="@root_sysconfdir@/e2scrub.conf"
test -f "${conffile}" && . "${conffile}"
print_help() {
echo "Usage: $0 [OPTIONS]"
- echo " -A: Scrub all ext[234] filesystems even if not mounted."
+ echo " -n: Show what commands e2scrub_all would execute."
echo " -r: Remove e2scrub snapshots."
+ echo " -A: Scrub all ext[234] filesystems even if not mounted."
echo " -V: Print version information and exit."
}
exit "${ret}"
}
-while getopts "ArV" opt; do
+while getopts "nrAV" opt; do
case "${opt}" in
- "A") scrub_all=1;;
+ "n") DBG="echo Would execute: " ;;
"r") scrub_args="${scrub_args} -r";;
+ "A") scrub_all=1;;
"V") print_version; exitcode 0;;
*) print_help; exitcode 2;;
esac
done
shift "$((OPTIND - 1))"
+# If some prerequisite packages are not installed, exit with a code
+# indicating success to avoid spamming the sysadmin with fail messages
+# when e2scrub_all is run out of cron or a systemd timer.
+
+if ! type lsblk >& /dev/null ; then
+ echo "e2scrub_all: can't find lsblk --- is util-linux installed?"
+ exitcode 0
+fi
+
+if ! type lvcreate >& /dev/null ; then
+ echo "e2scrub_all: can't find lvcreate --- is lvm2 installed?"
+ exitcode 0
+fi
+
# Find scrub targets, make sure we only do this once.
ls_scrub_targets() {
lsblk -o NAME,FSTYPE,MOUNTPOINT -p -P -n | while read vars; do
eval "${lvm_vars}"
echo "${LVM2_LV_ROLE}" | grep -q "snapshot" && continue
+ free_space="$(vgs -o vg_free --units m --noheadings --no-suffix "${LVM2_VG_NAME}" 2> /dev/null | sed -e 's/\..*//')"
+ test "${snap_size_mb}" -gt "${free_space}" && continue
+
if [ -n "${MOUNTPOINT}" ]; then
echo "${MOUNTPOINT}"
else