From 4b2d5f01a4eb3ed4e64e22912751f277ae055760 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 11 Sep 2021 11:07:53 +0200 Subject: [PATCH] backup scripts for ScoDoc 9 --- misc/backup_db2 => tools/backups/backup_db9 | 19 +++++++++---------- {misc => tools/backups}/backup_rotation.sh | 2 +- .../backups}/backup_to_remote_server.sh | 18 +++++++++--------- 3 files changed, 19 insertions(+), 20 deletions(-) rename misc/backup_db2 => tools/backups/backup_db9 (66%) rename {misc => tools/backups}/backup_rotation.sh (99%) rename {misc => tools/backups}/backup_to_remote_server.sh (85%) diff --git a/misc/backup_db2 b/tools/backups/backup_db9 similarity index 66% rename from misc/backup_db2 rename to tools/backups/backup_db9 index 77928770..ca760ea8 100755 --- a/misc/backup_db2 +++ b/tools/backups/backup_db9 @@ -1,29 +1,28 @@ #!/bin/bash -# usage: backup_db2 dbname +# usage: backup_db9 dbname # Dump une base postgresql, et garde plusieurs dumps dans le passe # (configurable dans le script backup_rotation.sh) # Les dumps sont compresses (gzip). # -# E. Viennet pour ScoDoc, 2014 +# E. Viennet pour ScoDoc, 2014, 2021 pour ScoDoc 9 # (ce script est meilleur que l'ancien backup-db, car l'espace entre # deux sauvegardes dépend de leur anciennete) # # # Note: pour restaurer un backup (en supprimant la base existante !): # -# 0- Arreter scodoc: /etc/init.d/scodoc stop (ou systemctl stop scodoc) +# 0- Arreter scodoc: systemctl stop scodoc # -# Puis en tant qu'utilisateur postgres: su postgres -# 1- supprimer la base existante si elle existe: dropdb SCOXXX +# Puis en tant qu'utilisateur scodoc: su scodoc +# 1- supprimer la base existante si elle existe: dropdb SCODOC # # 2- recreer la base, vide: createdb -E UTF-8 SCOXXX -# (nom de la base: SCOXXX ou XXX=departement) -# -# 3- pg_restore -d SCOXXX SCOXXX_pgdump +# /opt/scodoc/tools/create_database.sh SCODOC +# 3- pg_restore -d SCODOC SCODOC_pgdump # # Revenir a l'utilisateur root: exit -# 4- Relancer scodoc: /etc/init.d/scodoc start (ou systemctl start scodoc) +# 4- Relancer scodoc: systemctl start scodoc DBNAME=$1 DUMPBASE="$DBNAME"-BACKUPS @@ -50,4 +49,4 @@ pg_dump --format=t "$DBNAME" -f $DUMPFILE gzip $DUMPFILE # 3- Rotate backups: remove unneeded copies -/opt/scodoc/Products/ScoDoc/misc/backup_rotation.sh "$DUMPBASE" +/opt/scodoc/tools/backups/backup_rotation.sh "$DUMPBASE" diff --git a/misc/backup_rotation.sh b/tools/backups/backup_rotation.sh similarity index 99% rename from misc/backup_rotation.sh rename to tools/backups/backup_rotation.sh index 351a1e36..cfab628d 100755 --- a/misc/backup_rotation.sh +++ b/tools/backups/backup_rotation.sh @@ -1,6 +1,6 @@ #!/bin/bash # Backup rotation -# Usage example: backup_rotation.sh /var/lib/postgresql/BACKUP-SCOGEII +# Usage example: backup_rotation.sh /var/lib/postgresql/BACKUP-SCODOC # # This script is designed to run each hour # diff --git a/misc/backup_to_remote_server.sh b/tools/backups/backup_to_remote_server.sh similarity index 85% rename from misc/backup_to_remote_server.sh rename to tools/backups/backup_to_remote_server.sh index 2509ab6a..8638e1bd 100644 --- a/misc/backup_to_remote_server.sh +++ b/tools/backups/backup_to_remote_server.sh @@ -11,7 +11,7 @@ # # A adapter a vos besoins. Utilisation a vos risques et perils. # -# E. Viennet, 2002 +# E. Viennet, 2002, 2021 # Installation: # 1- Installer rsync: @@ -30,8 +30,8 @@ logfile=/var/log/rsynclog # log sur serveur scodoc # A qui envoyer un mail en cas d'erreur de la sauvegarde: SUPERVISORMAIL=emmanuel.viennet@example.com -CALLER=`basename $0` -MACHINE=`hostname -s` +CALLER=$(basename $0) +MACHINE=$(hostname -s) # ----------------------------------------------------- @@ -40,7 +40,7 @@ MACHINE=`hostname -s` # ---------------------------------- terminate() { - dateTest=`date` + dateTest=$(date) mail -s "Attention: Probleme sauvegarde ScoDoc" $SUPERVISORMAIL <> $logfile 2>&1 - echo "starting at" `date` >> $logfile 2>&1 - rsync -vaze ssh --delete --rsync-path=/usr/bin/rsync $srcdir $remotehost":"$destdir >> $logfile 2>&1 + echo "--------------- mirroring $MACHINE:$srcdir to $remotehost:$destdir" >> $logfile 2>&1 + echo "starting at $(date)" >> $logfile 2>&1 + rsync -vaze ssh --delete --rsync-path=/usr/bin/rsync "$srcdir" "$remotehost:$destdir" >> $logfile 2>&1 if [ $? -ne 0 ] then echo Error in rsync: code=$? terminate fi - echo "ending at" `date` >> $logfile 2>&1 + echo "ending at $(date)" >> $logfile 2>&1 echo "---------------" >> $logfile 2>&1 }