savegarde BDD et scripts

This commit is contained in:
root 2023-05-11 22:48:11 +02:00
parent b8711daa5d
commit 9228d915fb
3 changed files with 292 additions and 0 deletions

253
sauvBDD/backup.sql Executable file

File diff suppressed because one or more lines are too long

24
sauvBDD/restauredb Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
set -e
set -u
save () {
echo "Restauration de la base de données en cours ..."
zcat "${BACKUP_DIR}/catalogue_latest.sql.gz" | ssh root@ap23 "mysql -u admin -padmin ${DB_NAME}"
}
DATE=$(date "+%u")
DB_USER="usersave"
DB_PASS="saveuser"
DB_NAME="catalogue"
BACKUP_DIR="/root/bu"
BACKUP_NAME="${BACKUP_DIR}/${DB_NAME}-${DATE}.sql.gz"
#S'assurer que lutilisateur veuille restaurer la base
read -p "êtes-vous certain de vouloir restaurer la base de données ? (y/n) " answer
if [[ $answer == "y" ]] ; then
save
else
echo "Stop"
fi
exit 0

15
sauvBDD/sauvedb Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
# Variables
set -e
set -u
DATE=$(date "+%u")
DB_USER="usersave"
DB_PASS="saveuser"
DB_NAME="catalogue"
BACKUP_DIR="/root/bu"
BACKUP_NAME="${BACKUP_DIR}/${DB_NAME}-${DATE}.sql.gz"
ssh root@ap23 "mysqldump -u admin -padmin ${DB_NAME}|gzip" > "${BACKUP_NAME}"
cp "${BACKUP_NAME}" "${BACKUP_DIR}/catalogue_latest.sql.gz"