Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Root check
- if [[ $EUID -ne 0 ]]; then
- echo "Este script debe ejecutarse con permisos root."
- exit 1
- else
- # Argument loop
- for USERNAME in "$@"; do
- CURRENT_USER="/Users/$USERNAME"
- # Check if dir exists
- if [ -d "$CURRENT_USER" ]; then
- echo "########## USUARARIO: $USERNAME ##########"
- TODAY=$(date "+%Y-%m-%d_%H%M%S")
- DESTINATION="/tmp/${USERNAME}_home_${TODAY}.tar.gz"
- TOTAL_FILES=$(find "$CURRENT_USER" -type f | wc -l)
- TOTAL_DIRS=$(find "$CURRENT_USER" -type d | wc -l)
- echo "Archivos a ser incluidos $TOTAL_FILES"
- echo "Directorios a ser incluidos $TOTAL_DIRS"
- tar -czf "$DESTINATION" -P "$CURRENT_USER"
- TAR_FILE_INFO=$(ls -la $DESTINATION)
- TOTAL_GZFILES=$(tar -tvf "$DESTINATION" | grep -E "^[^d]" | wc -l)
- TOTAL_GZDIRS=$(tar -tvf "$DESTINATION" | grep -E "^d" | wc -l)
- echo "Archivos archivados: $TOTAL_GZFILES"
- echo "Directorios archivados: $TOTAL_GZDIRS"
- echo "Backup $CURRENT_USER completado!"
- echo "Detalles del archivo de backup generado:"
- echo $TAR_FILE_INFO
- else
- # Report user not found
- echo "El usuario \"$USERNAME\" no existe."
- fi
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment