35 lines
1.0 KiB
Bash
Executable File
35 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#screen -dmS admin-dashboard-backend | exit 0
|
|
#screen -S admin-dashboard-backend -p 0 -X stuff 'go run main.go\n'
|
|
|
|
# Set variables
|
|
BACKUP_DIR="backups"
|
|
DATE=$(date +'%Y-%m-%d_%H-%M-%S')
|
|
MAIN_FILE="main"
|
|
BACKUP_FILE="$BACKUP_DIR/main-$DATE"
|
|
MAX_BACKUPS=10
|
|
|
|
# Create backup directory if it doesn't exist
|
|
mkdir -p $BACKUP_DIR
|
|
|
|
# Check if the main file exists and move it to the backup directory with the current date and time
|
|
if [ -f $MAIN_FILE ]; then
|
|
mv $MAIN_FILE $BACKUP_FILE
|
|
echo "Backup of '$MAIN_FILE' created at '$BACKUP_FILE'"
|
|
else
|
|
echo "No existing main file to backup."
|
|
fi
|
|
|
|
# Ensure there are at most MAX_BACKUPS backups in the directory
|
|
BACKUPS_COUNT=$(ls $BACKUP_DIR | wc -l)
|
|
if [ $BACKUPS_COUNT -gt $MAX_BACKUPS ]; then
|
|
BACKUPS_TO_DELETE=$(expr $BACKUPS_COUNT - $MAX_BACKUPS)
|
|
ls -t $BACKUP_DIR | tail -n $BACKUPS_TO_DELETE | while read -r file; do
|
|
rm "$BACKUP_DIR/$file"
|
|
echo "Deleted old backup '$BACKUP_DIR/$file'"
|
|
done
|
|
fi
|
|
|
|
go build main.go
|
|
sudo systemctl restart admin-dashboard-backend.service |