1
0
Fork 0
pull-logs/disk-check.sh

51 lines
1.7 KiB
Bash

#!/bin/bash
echo "Starting disk space report... This may take a few minutes."
# Function to estimate the size of the apt cache
estimate_apt_cache_size() {
echo "Estimating the size of the apt cache:"
sudo du -sh /var/cache/apt
echo
}
# Function to estimate the size of old installed packages
estimate_old_packages_size() {
echo "Estimating the size of old installed packages:"
sudo du -sh /var/lib/apt/lists /var/lib/apt/lists/partial
echo
}
# Function to estimate the size of journal logs
estimate_journal_size() {
echo "Estimating the size of journal logs:"
sudo journalctl --disk-usage
echo
}
# Function to estimate the size of temporary files
estimate_tmp_size() {
echo "Estimating the size of temporary files:"
sudo du -sh /tmp /var/tmp
echo
}
# Function to estimate the size of unused Docker volumes
estimate_docker_volumes_size() {
echo "Estimating the size of unused Docker volumes:"
docker volume ls -qf dangling=true | xargs -I {} docker volume inspect --format '{{ .Mountpoint }}' {} | xargs -I {} du -sh {} | awk '{ sum += $1 } END { print sum "B" }'
echo
}
# Function to check and suggest logrotate for large Docker logs
check_docker_logs() {
echo "Checking Docker logs for large files..."
large_logs=$(docker ps -q --filter "status=exited" | xargs -I {} docker inspect --format '{{.LogPath}}' {} | xargs -I {} sudo find {} -type f -size +1G)
if [ -n "$large_logs" ]; then
echo "The following Docker logs are larger than 1GB:"
echo "$large_logs"
echo
echo "Consider setting up logrotate to manage Docker logs."
echo "To truncate all Docker logs, run:"
echo 'sudo find /var/lib/docker/containers/ -type f -name "*.