Добавлено редактирование конфига
This commit is contained in:
parent
46cd117c79
commit
5151220a6a
21
backup.sh
21
backup.sh
@ -125,12 +125,20 @@ if [[ "$ENABLE_DIRS" == "true" ]]; then
|
|||||||
IFS=',' read -r -a DIR_ARRAY <<< "$DIRECTORIES"
|
IFS=',' read -r -a DIR_ARRAY <<< "$DIRECTORIES"
|
||||||
for DIR in "${DIR_ARRAY[@]}"; do
|
for DIR in "${DIR_ARRAY[@]}"; do
|
||||||
# Проверка на исключение директорий
|
# Проверка на исключение директорий
|
||||||
if [[ " ${SKIP_DIR_ARRAY[@]} " =~ " $DIR " ]]; then
|
if [[ " ${SKIP_DIR_ARRAY[*]} " =~ " $DIR " ]]; then
|
||||||
echo "Directory $DIR is in the skip list, skipping." >> "$LOG_FILE"
|
echo "Directory $DIR is in the skip list, skipping." >> "$LOG_FILE"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d "$DIR" ]; then
|
if [ -d "$DIR" ]; then
|
||||||
|
# Проверка наличия файлов и директорий для исключения в текущей директории
|
||||||
|
for EXCLUDED in "${SKIP_DIR_ARRAY[@]}"; do
|
||||||
|
if [ -e "$DIR/$EXCLUDED" ]; then
|
||||||
|
echo "Excluded item $EXCLUDED found in directory $DIR, skipping backup." >> "$LOG_FILE"
|
||||||
|
continue 2 # Пропускаем всю директорию, если найдено исключение
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
cp -r "$DIR" "$TEMP_DIR/" && echo "Copy directory $DIR completed." >> "$LOG_FILE" || echo "Error while copying directory $DIR." >> "$LOG_FILE"
|
cp -r "$DIR" "$TEMP_DIR/" && echo "Copy directory $DIR completed." >> "$LOG_FILE" || echo "Error while copying directory $DIR." >> "$LOG_FILE"
|
||||||
else
|
else
|
||||||
echo "Directory $DIR not found, skipping." >> "$LOG_FILE"
|
echo "Directory $DIR not found, skipping." >> "$LOG_FILE"
|
||||||
@ -146,7 +154,7 @@ if [[ "$ENABLE_FILES" == "true" ]]; then
|
|||||||
IFS=',' read -r -a FILE_ARRAY <<< "$FILES"
|
IFS=',' read -r -a FILE_ARRAY <<< "$FILES"
|
||||||
for FILE in "${FILE_ARRAY[@]}"; do
|
for FILE in "${FILE_ARRAY[@]}"; do
|
||||||
# Проверка на исключение файлов
|
# Проверка на исключение файлов
|
||||||
if [[ " ${SKIP_FILE_ARRAY[@]} " =~ " $FILE " ]]; then
|
if [[ " ${SKIP_FILE_ARRAY[*]} " =~ " $FILE " ]]; then
|
||||||
echo "File $FILE is in the skip list, skipping." >> "$LOG_FILE"
|
echo "File $FILE is in the skip list, skipping." >> "$LOG_FILE"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
@ -158,11 +166,12 @@ if [[ "$ENABLE_FILES" == "true" ]]; then
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "Backup of files is disabled."
|
echo "Backup of files is disabled." >> "$LOG_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Упаковываем временную директорию в tar.gz архив
|
# Упаковываем временную директорию в tar.gz архив
|
||||||
tar -czf "$WORK_DIR/$TAR_NAME" -C "$TEMP_DIR" . && echo "Created tar.gz archive: $(pwd)/$TAR_NAME" || { echo "Error while creating tar.gz archive."; rm -rf "$TEMP_DIR"; exit 1; }
|
tar -czf "$WORK_DIR/$TAR_NAME" -C "$TEMP_DIR" . && echo "Created tar.gz archive: $TAR_NAME" || { echo "Error while creating tar.gz archive."; rm -rf "$TEMP_DIR"; exit 1; }
|
||||||
|
|
||||||
# Проверяем наличие файлов
|
# Проверяем наличие файлов
|
||||||
if [[ ! -f "$TAR_NAME" ]]; then
|
if [[ ! -f "$TAR_NAME" ]]; then
|
||||||
@ -200,9 +209,9 @@ fi
|
|||||||
# Удаление временной директории и архива после завершения работы скрипта
|
# Удаление временной директории и архива после завершения работы скрипта
|
||||||
rm -rf "$TEMP_DIR" || { echo "Error while deleting temp directory."}
|
rm -rf "$TEMP_DIR" || { echo "Error while deleting temp directory."}
|
||||||
echo "Temp directory deleted."
|
echo "Temp directory deleted."
|
||||||
rm "$TAR_NAME" || { echo "Error while deleting tar.gz archive."}
|
rm "$WORK_DIR/$TAR_NAME" || { echo "Error while deleting tar.gz archive."}
|
||||||
echo "Tar.gz archive deleted."
|
echo "Tar.gz archive deleted."
|
||||||
rm "$LOG_FILE" || { echo "Error while deleting log file."}
|
rm "$WORK_DIR/$LOG_FILE" || { echo "Error while deleting log file."}
|
||||||
echo "Log file deleted."
|
echo "Log file deleted."
|
||||||
|
|
||||||
echo "Sending message..."
|
echo "Sending message..."
|
||||||
|
48
install.sh
48
install.sh
@ -1,48 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Проверка на выполнение скрипта с правами суперпользователя
|
|
||||||
if [ "$EUID" -ne 0 ]; then
|
|
||||||
echo "Error: the script must be run with superuser rights (sudo)."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
WORK_DIR="/opt/adminlabs_backup"
|
|
||||||
BACKUP_SCRIPT="$WORK_DIR/backup.sh"
|
|
||||||
BACKUP_CONFIG="$WORK_DIR/backup.ini"
|
|
||||||
SCRIPT_URL="http://files.adminlabs.space/scripts/backup.sh"
|
|
||||||
CONFIG_URL="http://files.adminlabs.space/scripts/backup.ini"
|
|
||||||
|
|
||||||
# Создание рабочей директории, если она не существует
|
|
||||||
if [ ! -d "$WORK_DIR" ]; then
|
|
||||||
mkdir -p "$WORK_DIR" || { echo "Error: Failed to create directory $WORK_DIR"; exit 1; }
|
|
||||||
echo "Created directory $WORK_DIR."
|
|
||||||
else
|
|
||||||
echo "Directory $WORK_DIR already exists."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Функция для скачивания файла
|
|
||||||
download_file() {
|
|
||||||
local url="$1"
|
|
||||||
local dest="$2"
|
|
||||||
|
|
||||||
echo "Downloading $url..."
|
|
||||||
curl -o "$dest" "$url" || { echo "Error: Failed to download $url"; exit 1; }
|
|
||||||
}
|
|
||||||
|
|
||||||
# Проверка и копирование скрипта
|
|
||||||
if [[ -f "$BACKUP_SCRIPT" ]]; then
|
|
||||||
mv "$BACKUP_SCRIPT" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_SCRIPT to $WORK_DIR"; exit 1; }
|
|
||||||
else
|
|
||||||
download_file "$SCRIPT_URL" "$BACKUP_SCRIPT"
|
|
||||||
mv "$BACKUP_SCRIPT" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_SCRIPT to $WORK_DIR"; exit 1; }
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Проверка и копирование конфигурационного файла
|
|
||||||
if [[ -f "$BACKUP_CONFIG" ]]; then
|
|
||||||
mv "$BACKUP_CONFIG" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_CONFIG to $WORK_DIR"; exit 1; }
|
|
||||||
else
|
|
||||||
download_file "$CONFIG_URL" "$BACKUP_CONFIG"
|
|
||||||
mv "$BACKUP_CONFIG" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_CONFIG to $WORK_DIR"; exit 1; }
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Installation complete."
|
|
148
install_backup.sh
Executable file
148
install_backup.sh
Executable file
@ -0,0 +1,148 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "
|
||||||
|
░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░
|
||||||
|
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
|
||||||
|
░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░
|
||||||
|
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
|
||||||
|
░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░░▒▓█▓▒░
|
||||||
|
|
||||||
|
|
||||||
|
░▒▓█▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░▒▓████████▓▒░▒▓██████▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░ ░▒▓████████▓▒░▒▓█▓▒░ ░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░
|
||||||
|
░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓████████▓▒░
|
||||||
|
"
|
||||||
|
sleep 2
|
||||||
|
clear
|
||||||
|
|
||||||
|
# Проверка на выполнение скрипта с правами суперпользователя
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "Error: the script must be run with superuser rights (sudo)."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
WORK_DIR="/opt/adminlabs_backup"
|
||||||
|
BACKUP_SCRIPT="$WORK_DIR/backup.sh"
|
||||||
|
BACKUP_CONFIG="$WORK_DIR/backup.ini"
|
||||||
|
SCRIPT_URL="http://files.adminlabs.space/scripts/backup.sh"
|
||||||
|
CONFIG_URL="http://files.adminlabs.space/scripts/backup.ini"
|
||||||
|
|
||||||
|
# Создание рабочей директории, если она не существует
|
||||||
|
if [ ! -d "$WORK_DIR" ]; then
|
||||||
|
mkdir -p "$WORK_DIR" || { echo "Error: Failed to create directory $WORK_DIR"; exit 1; }
|
||||||
|
echo "Created directory $WORK_DIR."
|
||||||
|
else
|
||||||
|
echo "Directory $WORK_DIR already exists."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Функция для скачивания файла
|
||||||
|
download_file() {
|
||||||
|
local url="$1"
|
||||||
|
local dest="$2"
|
||||||
|
|
||||||
|
echo "Downloading $url..."
|
||||||
|
curl -o "$dest" "$url" || { echo "Error: Failed to download $url"; exit 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Проверка и копирование скрипта
|
||||||
|
if [[ -f "$BACKUP_SCRIPT" ]]; then
|
||||||
|
cp "$BACKUP_SCRIPT" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_SCRIPT to $WORK_DIR"; exit 1; }
|
||||||
|
else
|
||||||
|
download_file "$SCRIPT_URL" "$BACKUP_SCRIPT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Проверка и копирование конфигурационного файла
|
||||||
|
if [[ -f "$BACKUP_CONFIG" ]]; then
|
||||||
|
cp "$BACKUP_CONFIG" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_CONFIG to $WORK_DIR"; exit 1; }
|
||||||
|
else
|
||||||
|
download_file "$CONFIG_URL" "$BACKUP_CONFIG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Функция для редактирования файла backup.ini
|
||||||
|
edit_backup_config() {
|
||||||
|
clear
|
||||||
|
echo "Editing backup.ini..."
|
||||||
|
|
||||||
|
# Временный файл для редактирования
|
||||||
|
TEMP_FILE=$(mktemp)
|
||||||
|
|
||||||
|
# Чтение конфигурационного файла и отображение его содержимого
|
||||||
|
echo -e "\033[1;33m************************ Backup.ini ****************************\033[0m"
|
||||||
|
cat "$BACKUP_CONFIG"
|
||||||
|
echo -e "\n\033[1;33m************************ Backup.ini ****************************\033[0m"
|
||||||
|
|
||||||
|
echo -e "\n\n"
|
||||||
|
|
||||||
|
# Запрос на редактирование каждой секции
|
||||||
|
while true; do
|
||||||
|
echo -e "\033[1;34mWhich section would you like to edit? (B - Backup, F - FTP, S - SENT, Q - exit)\033[0m"
|
||||||
|
read -rp "Enter section >>> " section
|
||||||
|
|
||||||
|
case $section in
|
||||||
|
B)
|
||||||
|
echo "Editing [Backup] section:"
|
||||||
|
echo "Current settings:"
|
||||||
|
grep -A 5 "[Backup]" "$BACKUP_CONFIG"
|
||||||
|
echo "Enter new values (or press Enter to keep current):"
|
||||||
|
read -p "ENABLE_DIRS (true/false): " ENABLE_DIRS
|
||||||
|
read -p "ENABLE_FILES (true/false): " ENABLE_FILES
|
||||||
|
read -p "SKIP_FILES: " SKIP_FILES
|
||||||
|
read -p "SKIP_DIRS: " SKIP_DIRS
|
||||||
|
read -p "DIRS (comma separated): " DIRS
|
||||||
|
read -p "FILES (comma separated): " FILES
|
||||||
|
|
||||||
|
# Запись изменений во временный файл
|
||||||
|
sed "/[Backup]/,/^[/{s/ENABLE_DIRS=.*/ENABLE_DIRS=${ENABLE_DIRS:-true}/; s/ENABLE_FILES=.*/ENABLE_FILES=${ENABLE_FILES:-false}/; s/SKIP_FILES=.*/SKIP_FILES=${SKIP_FILES:-}/; s/SKIP_DIRS=.*/SKIP_DIRS=${SKIP_DIRS:-}/; s/DIRS=.*/DIRS=${DIRS:-/etc,/var/log}/; s/FILES=.*/FILES=${FILES:-/home/user/BashProject/backup.sh,/home/user/jet/restore.sh}/}" "$BACKUP_CONFIG" > "$TEMP_FILE"
|
||||||
|
mv "$TEMP_FILE" "$BACKUP_CONFIG"
|
||||||
|
;;
|
||||||
|
F)
|
||||||
|
echo "Editing [FTP] section:"
|
||||||
|
echo "Current settings:"
|
||||||
|
grep -A 4 "[FTP]" "$BACKUP_CONFIG"
|
||||||
|
read -p "FTP_SERVER: " FTP_SERVER
|
||||||
|
read -p "FTP_USER: " FTP_USER
|
||||||
|
read -p "FTP_PASS: " FTP_PASS
|
||||||
|
|
||||||
|
sed "/[FTP]/,/^[/{s/FTP_SERVER=.*/FTP_SERVER=${FTP_SERVER:-127.0.0.1}/; s/FTP_USER=.*/FTP_USER=${FTP_USER:-user}/; s/FTP_PASS=.*/FTP_PASS=${FTP_PASS:-password}/}" "$BACKUP_CONFIG" > "$TEMP_FILE"
|
||||||
|
mv "$TEMP_FILE" "$BACKUP_CONFIG"
|
||||||
|
;;
|
||||||
|
S)
|
||||||
|
echo "Editing [SENT] section:"
|
||||||
|
echo "Current settings:"
|
||||||
|
grep -A 6 "[SENT]" "$BACKUP_CONFIG"
|
||||||
|
read -p "ENABLE_SENT (true/false): " ENABLE_SENT
|
||||||
|
read -p "ENABLE_SENT_GOTIFY (true/false): " ENABLE_SENT_GOTIFY
|
||||||
|
read -p "ENABLE_SENT_TELEGRAM (true/false): " ENABLE_SENT_TELEGRAM
|
||||||
|
read -p "GOTIFY_URL: " GOTIFY_URL
|
||||||
|
read -p "GOTIFY_APP_TOKEN: " GOTIFY_APP_TOKEN
|
||||||
|
read -p "TELEGRAM_TOKEN: " TELEGRAM_TOKEN
|
||||||
|
read -p "CHAT_ID: " CHAT_ID
|
||||||
|
read -p 'TEXT_FINISH_MESSAGE: ' TEXT_FINISH_MESSAGE
|
||||||
|
|
||||||
|
sed "/[SENT]/,/^[/{s/ENABLE_SENT=.*/ENABLE_SENT=${ENABLE_SENT:-true}/; s/ENABLE_SENT_GOTIFY=.*/ENABLE_SENT_GOTIFY=${ENABLE_SENT_GOTIFY:-true}/; s/ENABLE_SENT_TELEGRAM=.*/ENABLE_SENT_TELEGRAM=${ENABLE_SENT_TELEGRAM:-true}/; s/GOTIFY_URL=.*/GOTIFY_URL=${GOTIFY_URL:-http://ваш_gotify_сервер}/; s/GOTIFY_APP_TOKEN=.*/GOTIFY_APP_TOKEN=${GOTIFY_APP_TOKEN:-0000000}/; s/TELEGRAM_TOKEN=.*/TELEGRAM_TOKEN=${TELEGRAM_TOKEN:-00000000}/; s/CHAT_ID=.*/CHAT_ID=${CHAT_ID:-00000000}/; s/TEXT_FINISH_MESSAGE=.*/TEXT_FINISH_MESSAGE="${TEXT_FINISH_MESSAGE:-Backup finished}"/" "$BACKUP_CONFIG" > "$TEMP_FILE"
|
||||||
|
mv "$TEMP_FILE" "$BACKUP_CONFIG"
|
||||||
|
;;
|
||||||
|
Q)
|
||||||
|
echo "Exiting configuration editor."
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid section. Please choose one of the following: Backup, FTP, SENT, END or exit."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -f "$TEMP_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Запуск функции редактирования конфигурации
|
||||||
|
edit_backup_config
|
||||||
|
|
||||||
|
echo "Installation complete."
|
||||||
|
|
Loading…
Reference in New Issue
Block a user