Explorar el Código

* Añadido configurarBackups()

Guzmán Castanedo Villalba hace 6 años
padre
commit
7603889302
Se han modificado 1 ficheros con 48 adiciones y 1 borrados
  1. 48 1
      install

+ 48 - 1
install

@@ -176,6 +176,10 @@ comprobarError() {
 		605)
 			error="\n$type $codeNum:\tImposible instalar 'policycoreutils-python'.Detalles:\n$extraInfo\n"
 			;;
+		701)
+			type="WARNING"
+			error="\n$tupe $codeNum:\tImposible configurar actualizaciones automáticas.\n"
+			;;
 		800)
 			error="$type $codeNum:\tEs necesario ser root ('sudo $0').\n"
 			;;
@@ -1719,6 +1723,49 @@ instalarPHPInfo() {
 	fi
 }
 
+configurarBackups() {
+# Instala backup-server y lo configura
+	letsEncryptCode=""
+	if [ ! -d "./var" ];then
+		comprobarError 1 5 "./var"
+	fi
+	which backup-server > /dev/null 2>&1
+	if [ $? -ne 0 ];then
+		# Descargamos backup-server
+		curl "https://code.castanedo.es/guzman/backup-server/archive/2.1.tar.gz" 2>/dev/null | tar -xz -C "./var/"
+		if [ $? -ne 0 ];then
+			comprobarError 1 701
+			return 1
+		fi
+		# Copiamos backup-server y logrotate
+		cp -f ./var/backup-server/backup-server /usr/bin/backup-server
+		if [ $? -ne 0 ];then
+			comprobarError 1 701
+			return 1
+		fi
+		cp -f ./var/backup-server/scripts/logrotate.d/backup-server /etc/logrotate.d/backup-server
+		if [ $? -ne 0 ];then
+			comprobarError 1 701
+			return 1
+		fi
+		# Creamos carpeta de backups
+		if [ ! -d /var/backup ];then
+			mkdir /var/backup 2>/dev/null
+			comprobarError $? 5 "/var/backup"
+		fi
+		# Configuramos cron.d
+		if [ $letsEncryptOn = false ];then
+			letsEncryptCode="--no-letsencrypt "
+		else
+		fi
+		echo -en "# /etc/cron.d/backup-server: crontab for $hostname\n\n" > /etc/cron.d/backup-server
+		echo -en "# Backup every day at 4:00 am\n" >> /etc/cron.d/backup-server
+		echo -en "0 4 * * * root [ -x /usr/bin/backup-server ] && /usr/bin/backup-server --xz -u $webServerUser -g $webServerGroup --no-encryption --sql-user $sqlPasswd --nginx-dir /etc/$webServerName $letsEncryptCode--no-mail --no-gogs --no-postfix --no-dovecot --no-opendkim --no-spf --no-opendmarc --no-amavis --no-spamassasin /var/backup >> /var/log/backup-server.log 2>&1" >> /etc/cron.d/backup-server
+		comprobarError $? 701
+	fi
+	unset letsEncryptCode
+}
+
 # Comprobación del sistema e inicialización
 	horaInicial=$(date +"%s")
 	inicializarVariables
@@ -1875,7 +1922,7 @@ instalarPHPInfo() {
 # Configurar Backup
 	if [ $backupOn = true ]; then
 		echo -en "Configurando Backup Automático..." | tee -a $logFile
-		sleep 2
+		configurarBackups
 		echo -en " OK.\n" | tee -a $logFile
 	fi