1
0
forked from ScoDoc/ScoDoc

backup scripts for ScoDoc 9

This commit is contained in:
Emmanuel Viennet 2021-09-11 11:07:53 +02:00
parent a6b97e9667
commit 4b2d5f01a4
3 changed files with 19 additions and 20 deletions

View File

@ -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"

View File

@ -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
#

View File

@ -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 <<EOF
The execution of script $CALLER was not successful on $MACHINE.
@ -57,7 +57,7 @@ EOF
echo "Look at logfile $logfile"
echo
echo "$CALLER terminated, exiting now with rc=1."
dateTest=`date`
dateTest=$(date)
echo "End of script at: $dateTest"
echo ""
@ -74,16 +74,16 @@ EOF
# --------------------------------------
rsync_mirror_to_remote()
{
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
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
}