mirror of
https://github.com/mag37/dockcheck.git
synced 2026-04-19 10:57:45 +00:00
made a function out of the backup removal to be more modular
This commit is contained in:
43
dockcheck.sh
43
dockcheck.sh
@@ -231,6 +231,7 @@ choosecontainers() {
|
|||||||
while [[ -z "${ChoiceClean:-}" ]]; do
|
while [[ -z "${ChoiceClean:-}" ]]; do
|
||||||
read -r -p "Enter number(s) separated by comma, [a] for all - [q] to quit: " Choice
|
read -r -p "Enter number(s) separated by comma, [a] for all - [q] to quit: " Choice
|
||||||
if [[ "$Choice" =~ [qQnN] ]]; then
|
if [[ "$Choice" =~ [qQnN] ]]; then
|
||||||
|
[[ -n "${BackupForDays:-}" ]] && remove_backups
|
||||||
exit 0
|
exit 0
|
||||||
elif [[ "$Choice" =~ [aAyY] ]]; then
|
elif [[ "$Choice" =~ [aAyY] ]]; then
|
||||||
SelectedUpdates=( "${GotUpdates[@]}" )
|
SelectedUpdates=( "${GotUpdates[@]}" )
|
||||||
@@ -261,6 +262,27 @@ datecheck() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_backups() {
|
||||||
|
IFS=$'\n'
|
||||||
|
CleanupCount=0
|
||||||
|
for backup_img in $(docker images --format "{{.Repository}} {{.Tag}}" | sed -n '/^dockcheck/p'); do
|
||||||
|
repo_name=${backup_img% *}
|
||||||
|
backup_tag=${backup_img#* }
|
||||||
|
backup_date=${backup_tag%%_*}
|
||||||
|
# UNTAGGING HERE
|
||||||
|
if datecheck "$backup_date" "$BackupForDays"; then
|
||||||
|
[[ "$CleanupCount" == 0 ]] && echo "Removing backed up images older then $BackupForDays days."
|
||||||
|
docker rmi "${repo_name}:${backup_tag}" && ((CleanupCount+=1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
unset IFS
|
||||||
|
if [[ "$CleanupCount" == 0 ]]; then
|
||||||
|
printf "\nNo backup images to remove.\n"
|
||||||
|
else
|
||||||
|
printf "\n%b%s%b backup removed.%b\n" "$c_green" "$CleanupCount" "$c_teal" "$c_reset"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
progress_bar() {
|
progress_bar() {
|
||||||
QueCurrent="$1"
|
QueCurrent="$1"
|
||||||
QueTotal="$2"
|
QueTotal="$2"
|
||||||
@@ -677,25 +699,6 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up old backup image tags if -b is used
|
# Clean up old backup image tags if -b is used
|
||||||
if [[ -n "${BackupForDays:-}" ]]; then
|
[[ -n "${BackupForDays:-}" ]] && remove_backups
|
||||||
IFS=$'\n'
|
|
||||||
CleanupCount=0
|
|
||||||
for backup_img in $(docker images --format "{{.Repository}} {{.Tag}}" | sed -n '/^dockcheck/p'); do
|
|
||||||
repo_name=${backup_img% *}
|
|
||||||
backup_tag=${backup_img#* }
|
|
||||||
backup_date=${backup_tag%%_*}
|
|
||||||
# UNTAGGING HERE
|
|
||||||
if datecheck "$backup_date" "$BackupForDays"; then
|
|
||||||
[[ "$CleanupCount" == 0 ]] && echo "Removing backed up images older then $BackupForDays days."
|
|
||||||
docker rmi "${repo_name}:${backup_tag}" && ((CleanupCount+=1))
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
unset IFS
|
|
||||||
if [[ "$CleanupCount" == 0 ]]; then
|
|
||||||
printf "\nNo backup images to remove.\n"
|
|
||||||
else
|
|
||||||
printf "\n%b%s%b backup removed.%b\n" "$c_green" "$CleanupCount" "$c_teal" "$c_reset"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user