diff --git a/log-archive b/log-archive new file mode 100644 index 0000000..b473096 --- /dev/null +++ b/log-archive @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# ===== Colors ===== +GRAY="\e[1;30m" +RED="\e[1;31m" +GREEN="\e[1;32m" +BLUE="\e[1;34m" +WHITE="\e[1;37m" +RESET="\e[0m" + +# ===== Date and Time ===== +currentDate=$(date +"%Y%m%d_%H%M%S") + +# ===== Archiving ===== +if [ $# -eq 1 ] && [ -d "$1" ]; then + echo -e "${WHITE}Start archiving...${GRAY}" + sudo mkdir -p /var/log/log-archives + + archivePath="/var/log/log-archives/logs-archive_${currentDate}.tar.gz" + + if sudo -k tar -czvf "$archivePath" "$1"/*; then + echo -e "${GREEN}The archive has been saved successfully at${RESET} ${BLUE}$archivePath${RESET}" + else + echo -e "${RED}Archiving failed. Check permissions or disk space.${RESET}" + fi +else + echo -e "${GRAY}Usage:${RESET} ${WHITE}log-archive${RESET} ${BLUE}${RESET}" +fi +exit 0 \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..404bedc --- /dev/null +++ b/setup.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# ===== Colors ===== +GRAY="\e[1;30m" +GREEN="\e[1;32m" +BLUE="\e[1;34m" +WHITE="\e[1;37m" +RESET="\e[0m" + +# ===== Create directory ===== +echo -e "${GRAY}Creating${RESET} ${BLUE}/var/log/log-archives${RESET} ${GRAY}directory..." +sudo mkdir -p /var/log/log-archives + +# ===== Installation ===== +echo -e "${GRAY}Installing${RESET} ${WHITE}log-archive${RESET} ${GRAY}tool..." +sudo cp ./log-archive /usr/bin/ +sudo chmod +x /usr/bin/log-archive + +# ===== Output ===== +echo -e "${GREEN}Successfully installed!${RESET}" +echo -e "${GRAY}Usage:${RESET} ${WHITE}log-archive${RESET} ${BLUE}${RESET}" +echo -e "${GRAY}Stored logs directory:${RESET} ${BLUE}/var/log/logs-archives${RESET}" \ No newline at end of file