63 lines
2.3 KiB
Bash
63 lines
2.3 KiB
Bash
#!/bin/bash
|
|
# Script per l'installazione del backup di database PostgreSQL o MSSql
|
|
# Autore: Mattia Tadini
|
|
# Nome File: install_db_backup.sh
|
|
# Revisione: 1.0
|
|
|
|
# Variabili globali
|
|
BACKUP_DIR="/zucchetti/backupdb"
|
|
MSSQL_BACKUP_SCRIPT_URL="https://dl.poloinformatico.it/assistenza/Scripts/mssql-backup.sh"
|
|
MSSQL_CONFIG_URL="https://dl.poloinformatico.it/assistenza/Scripts/mssqlconfig.env"
|
|
POSTGRES_BACKUP_SCRIPT_URL="https://dl.poloinformatico.it/assistenza/Scripts/postgres-backup.sh"
|
|
POSTGRES_CONFIG_URL="https://dl.poloinformatico.it/assistenza/Scripts/psqlconfig.env"
|
|
|
|
# Crea la cartella /zucchetti/backupdb/
|
|
mkdir -p $BACKUP_DIR
|
|
|
|
# Chiedi al utente di scegliere il tipo di database
|
|
read -p "Vuoi installare lo script per MSSQL o PostgreSQL? (mssql/postgres): " choice
|
|
|
|
if [[ "$choice" == "mssql" ]]; then
|
|
# Scarica i file per MSSQL
|
|
wget $MSSQL_BACKUP_SCRIPT_URL -O $BACKUP_DIR/mssql-backup.sh
|
|
wget $MSSQL_CONFIG_URL -O $BACKUP_DIR/mssqlconfig.env
|
|
|
|
# Commento specifico per MSSQL
|
|
cron_comment="### Backup Database MSSQL ###"
|
|
else
|
|
# Scarica i file per PostgreSQL
|
|
wget $POSTGRES_BACKUP_SCRIPT_URL -O $BACKUP_DIR/postgres-backup.sh
|
|
wget $POSTGRES_CONFIG_URL -O $BACKUP_DIR/psqlconfig.env
|
|
|
|
# Commento specifico per PostgreSQL
|
|
cron_comment="### Backup Database PostgreSQL ###"
|
|
fi
|
|
|
|
# Imposta i permessi eseguibili sui file .sh
|
|
if [[ "$choice" == "mssql" ]]; then
|
|
chmod +x $BACKUP_DIR/mssql-backup.sh
|
|
else
|
|
chmod +x $BACKUP_DIR/postgres-backup.sh
|
|
fi
|
|
|
|
echo "Script installati."
|
|
|
|
# Chiedi l'ora di esecuzione del backup nel formato HH:MM
|
|
read -p "Inserisci l'ora di esecuzione del backup (HH:MM): " user_time
|
|
|
|
# Estrai l'ora e i minuti dall'imput dell'utente
|
|
IFS=':' read -r hour minute <<< "$user_time"
|
|
|
|
# Converti l'ora nel formato HH:MM per il cron
|
|
cron_time="$minute $hour * * *"
|
|
|
|
# Aggiungi la linea al file /etc/crontab con il commento
|
|
if [[ "$choice" == "mssql" ]]; then
|
|
echo "$cron_comment" | sudo tee -a /etc/crontab > /dev/null
|
|
echo "$cron_time root /bin/bash $BACKUP_DIR/mssql-backup.sh" | sudo tee -a /etc/crontab >> /dev/null
|
|
else
|
|
echo "$cron_comment" | sudo tee -a /etc/crontab > /dev/null
|
|
echo "$cron_time root /bin/bash $BACKUP_DIR/postgres-backup.sh" | sudo tee -a /etc/crontab >> /dev/null
|
|
fi
|
|
|
|
echo "Cron impostato correttamente." |