47 lines
1.3 KiB
Bash
Executable File
47 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
copy_files=false
|
|
user_ssh=root
|
|
host_ssh=10.0.133.74
|
|
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
NC='\033[0m'
|
|
|
|
for arg in "$@"
|
|
do
|
|
if [ "$arg" == "-copy" ]; then
|
|
copy_files=true
|
|
fi
|
|
done
|
|
|
|
archive_name="update_$(date +'%d-%m-%Y_%H-%M').tar.gz"
|
|
|
|
current_dir=$(pwd)
|
|
|
|
if [ ! -f "upd-file.txt" ]; then
|
|
echo -e "${RED}Ошибка:${NC} файл upd-file.txt не найден."
|
|
exit 1
|
|
fi
|
|
|
|
tar -czvf "$archive_name" -T upd-file.txt
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}Ошибка при создании архива.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}Архивирование завершено. Архив создан в: $current_dir/$archive_name.${NC}"
|
|
|
|
if [ "$copy_files" == true ]; then
|
|
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P 22 "$archive_name" $user_ssh@$host_ssh:/tmp/update-dashboard
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo -e "${GREEN}Архив $archive_name успешно скопирован на удаленный сервер $host_ssh.${NC}"
|
|
rm "$archive_name"
|
|
echo -e "${GREEN}Архив $archive_name удален.${NC}"
|
|
else
|
|
echo -e "${RED}Ошибка при копировании архива $archive_name на удаленный сервер $host_ssh.${NC}"
|
|
fi
|
|
fi
|