Manage old users that no longer uses any space
This commit is contained in:
parent
bc190d399c
commit
5719ee5466
|
@ -286,7 +286,7 @@ main() { # {{{
|
||||||
## If ZFS pool/dataset is not available {{{
|
## If ZFS pool/dataset is not available {{{
|
||||||
### Exit
|
### Exit
|
||||||
is_zfs_dataset_exists "${zfs_dataset}" \
|
is_zfs_dataset_exists "${zfs_dataset}" \
|
||||||
|| error_message "Please verify your ZFS pool (${zfs_dataset} doesn't seems available." 3
|
|| error_message "Please verify your ZFS pool (${zfs_dataset}) doesn't seems available." 3
|
||||||
## }}}
|
## }}}
|
||||||
|
|
||||||
## Try to get the user list of ZFS pool/dataset {{{
|
## Try to get the user list of ZFS pool/dataset {{{
|
||||||
|
@ -295,13 +295,19 @@ main() { # {{{
|
||||||
|| error_message "Can't get the user list of ${zfs_dataset} ZFS pool/dataset. Please use --debug option." 4
|
|| error_message "Can't get the user list of ${zfs_dataset} ZFS pool/dataset. Please use --debug option." 4
|
||||||
## }}}
|
## }}}
|
||||||
|
|
||||||
## If a previous list of users exists {{{
|
## Don't compare current user list with any previous list {{{
|
||||||
|
## 1. Cause the list of users might be the same ✅
|
||||||
|
## 2. But new quota might have been set for specific user ❎
|
||||||
|
## 3. And if a user no longer exists on the system, it will remains on ZFS quota/userspace ❎
|
||||||
|
|
||||||
|
## Disabled
|
||||||
|
## If a previous list of users exists
|
||||||
### If the two list are the same
|
### If the two list are the same
|
||||||
### Exit
|
### Exit
|
||||||
is_file_present "${zfs_previous_user_list_path}" \
|
#is_file_present "${zfs_previous_user_list_path}" \
|
||||||
&& is_file_similar "${zfs_user_list_path}" "${zfs_previous_user_list_path}" \
|
#&& is_file_similar "${zfs_user_list_path}" "${zfs_previous_user_list_path}" \
|
||||||
&& debug_message "main − No new user from previous run, no more actions required." \
|
#&& debug_message "main − No new user from previous run, no more actions required." \
|
||||||
&& exit 0
|
#&& exit 0
|
||||||
## }}}
|
## }}}
|
||||||
|
|
||||||
## Information message
|
## Information message
|
||||||
|
@ -309,17 +315,26 @@ main() { # {{{
|
||||||
|
|
||||||
## Read user one by one
|
## Read user one by one
|
||||||
while IFS= read -r zfs_username; do
|
while IFS= read -r zfs_username; do
|
||||||
### Define quota to use {{{
|
### If user uses more than 0B {{{
|
||||||
if [ "${QUOTA_FILE_MODE}" -eq "0" ] \
|
if ! zfs get -H -o value userused@"${zfs_username:-0}" "${zfs_dataset:-/dev/null}" | grep --only-matching --quiet -- "0B" ; then
|
||||||
&& grep --word-regexp -- "^${zfs_username}" "${quota_file}" | grep --only-matching --perl-regexp --quiet -- '[[:digit:].]*.$'; then
|
### Define quota to use {{{
|
||||||
### From quota file if any information for this user
|
if [ "${QUOTA_FILE_MODE}" -eq "0" ] \
|
||||||
user_zfs_quota="$(grep --word-regexp -- "^${zfs_username}" "${quota_file}" |
|
&& grep --word-regexp -- "^${zfs_username}" "${quota_file}" | grep --only-matching --perl-regexp --quiet -- '[[:digit:].]*.$'; then
|
||||||
grep --only-matching --perl-regexp -- '[[:digit:].]*.$' \
|
### From quota file if any information for this user
|
||||||
|| error_message "Can't get quota for ${zfs_username} user from ${quota_file} quota file." 5)"
|
user_zfs_quota="$(grep --word-regexp -- "^${zfs_username}" "${quota_file}" |
|
||||||
debug_message "Get specific quota (${RED}${user_zfs_quota}${COLOR_DEBUG}) for ${RED}${zfs_username}${COLOR_DEBUG} user from quota file (${RED}${quota_file}${COLOR_DEBUG})."
|
grep --only-matching --perl-regexp -- '[[:digit:].]*.$' \
|
||||||
|
|| error_message "Can't get quota for ${zfs_username} user from ${quota_file} quota file." 5)"
|
||||||
|
debug_message "Get specific quota (${RED}${user_zfs_quota}${COLOR_DEBUG}) for ${RED}${zfs_username}${COLOR_DEBUG} user from quota file (${RED}${quota_file}${COLOR_DEBUG})."
|
||||||
|
else
|
||||||
|
### Default quota by default
|
||||||
|
user_zfs_quota="${zfs_quota}"
|
||||||
|
fi
|
||||||
|
### }}}
|
||||||
|
### }}}
|
||||||
|
### If user don't uses any space, it has to be deleted from zfs userspace list {{{
|
||||||
else
|
else
|
||||||
### Default quota by default
|
### Set quota to "none" to remove this user from the list
|
||||||
user_zfs_quota="${zfs_quota}"
|
user_zfs_quota="none"
|
||||||
fi
|
fi
|
||||||
### }}}
|
### }}}
|
||||||
### Try to apply the quota to the user {{{
|
### Try to apply the quota to the user {{{
|
||||||
|
@ -329,7 +344,7 @@ main() { # {{{
|
||||||
### }}}
|
### }}}
|
||||||
done < "${zfs_user_list_path}"
|
done < "${zfs_user_list_path}"
|
||||||
|
|
||||||
## Rename user list for next run of the script
|
## Rename user list for log
|
||||||
## AND exit
|
## AND exit
|
||||||
mv --force -- "${zfs_user_list_path}" "${zfs_previous_user_list_path}" \
|
mv --force -- "${zfs_user_list_path}" "${zfs_previous_user_list_path}" \
|
||||||
&& exit 0
|
&& exit 0
|
||||||
|
|
Loading…
Reference in New Issue