Update the deploy script with backup feature.

This commit is contained in:
atef 2024-11-26 15:50:34 +01:00
parent abd2d24e6c
commit e342cb18b1
2 changed files with 38 additions and 6 deletions

View File

@ -6,21 +6,55 @@ username='ie-entwicklung'
root_password='Salimax4x25' root_password='Salimax4x25'
set -e set -e
# Define directories
DEST_DIR="/home/$username/salimax/SaliMax" # Path to the specific file
BACKUP_DIR="/home/$username/salimax/salimax_backup/$(date +'%Y%m%d_%H%M%S')" # Backup folder with timestamp
MAX_BACKUPS=10 # Limit to 10 backups
echo -e "\n============================ Build ============================\n" echo -e "\n============================ Build ============================\n"
# Build the project
dotnet publish \ dotnet publish \
./SaliMax.csproj \ ./SaliMax.csproj \
-p:PublishTrimmed=false \ -p:PublishTrimmed=false \
-c Release \ -c Release \
-r linux-x64 -r linux-x64
echo -e "\n============================ Backup Old SaliMax File ============================\n"
# SSH into the remote machine and create the backup directory
ssh $username@$salimax_ip "mkdir -p $BACKUP_DIR"
# Move the 'SaliMax' file to the backup folder on the remote machine
ssh $username@$salimax_ip "rsync -av --exclude='$BACKUP_DIR/*' --exclude='salimax_backup/*' $DEST_DIR $BACKUP_DIR/"
echo -e "\n============================ Cleanup Old Backups ============================\n"
# Cleanup old backups if the total number exceeds the maximum allowed
# List all backups and remove the oldest if the number exceeds MAX_BACKUPS
BACKUP_COUNT=$(ssh $username@$salimax_ip "ls -1 /home/$username/salimax/salimax_backup | wc -l")
if [ $BACKUP_COUNT -gt $MAX_BACKUPS ]; then
# Find and delete the oldest backup
OLD_BACKUP=$(ssh $username@$salimax_ip "ls -1 /home/$username/salimax/salimax_backup | head -n 1")
echo "Backup limit reached. Deleting old backup: $OLD_BACKUP"
ssh $username@$salimax_ip "rm -rf /home/$username//salimax/salimax_backup/$OLD_BACKUP"
else
echo "Backup limit not reached. Current number of backups: $BACKUP_COUNT"
fi
echo -e "\n============================ Deploy ============================\n" echo -e "\n============================ Deploy ============================\n"
# Deploy new files to the remote destination
rsync -v \ rsync -v \
--exclude '*.pdb' \ --exclude '*.pdb' \
./bin/Release/$dotnet_version/linux-x64/publish/* \ ./bin/Release/$dotnet_version/linux-x64/publish/* \
$username@"$salimax_ip":~/salimax $username@"$salimax_ip":~/salimax
echo -e "\n============================ Execute ============================\n" echo -e "\nDeployment complete!\n"
sshpass -p "$root_password" ssh -o StrictHostKeyChecking=no -t "$username"@"$salimax_ip" "echo '$root_password' | sudo -S sh -c 'cd salimax && ./restart'" 2>/dev/null
#echo -e "\n============================ Execute ============================\n"
#sshpass -p "$root_password" ssh -o StrictHostKeyChecking=no -t "$username"@"$salimax_ip" "echo '$root_password' | sudo -S sh -c 'cd salimax && ./restart'" 2>/dev/null

View File

@ -224,8 +224,6 @@ internal static class Program
var record = ReadStatus(); var record = ReadStatus();
/******************************************** For Battery Debug *************************************/
var currentSalimaxState = GetSalimaxStateAlarm(record); var currentSalimaxState = GetSalimaxStateAlarm(record);
SendSalimaxStateAlarm(currentSalimaxState, record); SendSalimaxStateAlarm(currentSalimaxState, record);
@ -572,7 +570,7 @@ internal static class Program
} }
else else
{ {
Console.WriteLine(" Different ActiveUpperVoltage between inverters "); Console.WriteLine(" Different ActiveUpperVoltage between inverters "); // this should be reported to salimax Alarm
return; return;
} }