feat : ajout de la rotation pour les scripts de backup
This commit is contained in:
@@ -16,7 +16,8 @@ set -euo pipefail
|
||||
# 5. exporte les rôles PostgreSQL ;
|
||||
# 6. dump chaque base au format personnalisé PostgreSQL ;
|
||||
# 7. transfère chaque fichier vers le serveur distant ;
|
||||
# 8. envoie un bilan sur Discord :
|
||||
# 8. applique une rotation distante sur 10 jours ;
|
||||
# 9. envoie un bilan sur Discord :
|
||||
# - 1 message global si tout est OK ;
|
||||
# - en cas d’erreur partielle :
|
||||
# * USERS OK -> message simple ;
|
||||
@@ -67,6 +68,7 @@ read -r -a DBS_ARRAY <<< "$DBS"
|
||||
|
||||
IA_SSH="${BACKUP_REMOTE_USER}@${BACKUP_REMOTE_HOST}"
|
||||
IA_BASE_DIR="${BACKUP_REMOTE_DIR}"
|
||||
RETENTION_DAYS=10
|
||||
|
||||
SSH_OPTS=(
|
||||
-i "$SSH_KEY"
|
||||
@@ -299,6 +301,36 @@ done
|
||||
|
||||
set -e
|
||||
|
||||
#######################################
|
||||
# Rotation distante
|
||||
#######################################
|
||||
|
||||
log "Starting remote rotation: delete backups older than ${RETENTION_DAYS} days"
|
||||
|
||||
set +e
|
||||
|
||||
ssh "${SSH_OPTS[@]}" "$IA_SSH" "find '${REMOTE_DIR}/user' -type f -name 'user_*.dump' -mtime +${RETENTION_DAYS} -delete"
|
||||
RET=$?
|
||||
|
||||
if [[ $RET -ne 0 ]]; then
|
||||
log "ERROR: remote rotation failed for users"
|
||||
fi
|
||||
|
||||
for DB in "${DBS_ARRAY[@]}"; do
|
||||
ssh "${SSH_OPTS[@]}" "$IA_SSH" "find '${REMOTE_DIR}/${DB}' -type f -name '${DB}_*.dump' -mtime +${RETENTION_DAYS} -delete"
|
||||
RET=$?
|
||||
|
||||
if [[ $RET -ne 0 ]]; then
|
||||
log "ERROR: remote rotation failed for ${DB}"
|
||||
else
|
||||
log "Remote rotation OK for ${DB}"
|
||||
fi
|
||||
done
|
||||
|
||||
set -e
|
||||
|
||||
log "Remote rotation finished"
|
||||
|
||||
#######################################
|
||||
# Nettoyage local
|
||||
#######################################
|
||||
|
||||
Reference in New Issue
Block a user