Last active
November 12, 2020 07:25
-
-
Save benformosa/4516af31bf2fec2210dd2c88c86c8b67 to your computer and use it in GitHub Desktop.
Estimate the size of a Red Hat Satellite backup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/bash | |
| set -o errexit # -e | |
| set -o pipefail | |
| # Estimate the size of a Red Hat Satellite backup | |
| # Based on https://access.redhat.com/documentation/en-us/red_hat_satellite/6.3/html/administering_red_hat_satellite/chap-red_hat_satellite-administering_red_hat_satellite-backup_and_disaster_recovery#sect-Red_Hat_Satellite-Administering_Red_Hat_Satellite-Backing_up_Satellite_Server_or_Capsule_Server-Estimating_the_Size_of_a_Backup | |
| # Author: Ben Formosa | |
| # Copyright 2018, Commonwealth of Australia | |
| # Provided under the GNU GPLv3 license | |
| HUMAN="FALSE" | |
| if [ '-h' == "${1}" ] || [ '--help' == "${1}" ]; then | |
| echo "Displays an estimated size of a backup of Red Hat Satellite 6. The estimated size after compression is shown as a range between the values under Higher and Lower." | |
| echo "For human-readable sizes, pass an argument." | |
| echo "" | |
| echo "Usage:" | |
| echo "satellite_backup_estimate.sh [1]" | |
| exit 0 | |
| elif [ "${1}" ]; then | |
| HUMAN="TRUE" | |
| fi | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "This script must be run as root" | |
| exit 1 | |
| fi | |
| function compressed_size { | |
| # $1 original size | |
| # $2 compression ratio (percent) | |
| echo "${1} / 100 * (100 - ${2})" | bc | |
| } | |
| function print_compressed { | |
| # $1 Name | |
| # $2 Paths | |
| # $3 compression ration - low | |
| # $4 compression ration - high | |
| # shellcheck disable=SC2086 | |
| ORIG=$(du -s $2 | tail -n1 | cut -f1) | |
| COMP_L=$(compressed_size "${ORIG}" "${3}") | |
| COMP_H=$(compressed_size "${ORIG}" "${4}") | |
| printf "%s,%s,%s,%s\\n" "${1}" "${ORIG}" "${COMP_H}" "${COMP_L}" | |
| } | |
| function print_human { | |
| # $1 output of print_compressed | |
| echo "${1}" | numfmt --from-unit=1024 --to=iec-i -d',' --field 2 | numfmt --from-unit=1024 --to=iec-i -d',' --field 3 | numfmt --from-unit=1024 --to=iec-i -d',' --field 4 | |
| } | |
| MGDB=$(print_compressed "MongoDB" "/var/lib/mongodb" 10 15) | |
| PSQL=$(print_compressed "PostgreSQL" "/var/lib/pgsql/data" 15 20) | |
| PULP=$(print_compressed "Pulp" /var/lib/pulp 0 0) | |
| # PULP="Pulp,0,0,0" # Pulp is the largest. Comment out the above line and uncomment this line for testing | |
| CONF=$(print_compressed "Config" "/etc /root/ssl-build /var/www/html/pub /opt/puppetlabs" 5 10) | |
| TOTAL_O=$(echo "$(echo "${MGDB}" | cut -f2 -d',') + $(echo "${PSQL}" | cut -f2 -d',') + $(echo "${PULP}" | cut -f2 -d',') + $(echo "${CONF}" | cut -f2 -d',')" | bc) | |
| TOTAL_H=$(echo "$(echo "${MGDB}" | cut -f3 -d',') + $(echo "${PSQL}" | cut -f3 -d',') + $(echo "${PULP}" | cut -f3 -d',') + $(echo "${CONF}" | cut -f3 -d',')" | bc) | |
| TOTAL_L=$(echo "$(echo "${MGDB}" | cut -f4 -d',') + $(echo "${PSQL}" | cut -f4 -d',') + $(echo "${PULP}" | cut -f4 -d',') + $(echo "${CONF}" | cut -f4 -d',')" | bc) | |
| echo "Type,Original,Higher,Lower" | |
| if [ "TRUE" == "${HUMAN}" ]; then | |
| print_human "${MGDB}" | |
| print_human "${PSQL}" | |
| print_human "${PULP}" | |
| print_human "${CONF}" | |
| print_human "Total,${TOTAL_O},${TOTAL_H},${TOTAL_L}" | |
| else | |
| echo "${MGDB}" | |
| echo "${PSQL}" | |
| echo "${PULP}" | |
| echo "${CONF}" | |
| echo "Total,${TOTAL_O},${TOTAL_H},${TOTAL_L}" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment