forked from ScoDoc/ScoDoc
backup scripts for ScoDoc 9
This commit is contained in:
parent
a6b97e9667
commit
4b2d5f01a4
@ -1,29 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# usage: backup_db2 dbname
|
# usage: backup_db9 dbname
|
||||||
# Dump une base postgresql, et garde plusieurs dumps dans le passe
|
# Dump une base postgresql, et garde plusieurs dumps dans le passe
|
||||||
# (configurable dans le script backup_rotation.sh)
|
# (configurable dans le script backup_rotation.sh)
|
||||||
# Les dumps sont compresses (gzip).
|
# 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
|
# (ce script est meilleur que l'ancien backup-db, car l'espace entre
|
||||||
# deux sauvegardes dépend de leur anciennete)
|
# deux sauvegardes dépend de leur anciennete)
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Note: pour restaurer un backup (en supprimant la base existante !):
|
# 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
|
# Puis en tant qu'utilisateur scodoc: su scodoc
|
||||||
# 1- supprimer la base existante si elle existe: dropdb SCOXXX
|
# 1- supprimer la base existante si elle existe: dropdb SCODOC
|
||||||
#
|
#
|
||||||
# 2- recreer la base, vide: createdb -E UTF-8 SCOXXX
|
# 2- recreer la base, vide: createdb -E UTF-8 SCOXXX
|
||||||
# (nom de la base: SCOXXX ou XXX=departement)
|
# /opt/scodoc/tools/create_database.sh SCODOC
|
||||||
#
|
# 3- pg_restore -d SCODOC SCODOC_pgdump
|
||||||
# 3- pg_restore -d SCOXXX SCOXXX_pgdump
|
|
||||||
#
|
#
|
||||||
# Revenir a l'utilisateur root: exit
|
# 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
|
DBNAME=$1
|
||||||
DUMPBASE="$DBNAME"-BACKUPS
|
DUMPBASE="$DBNAME"-BACKUPS
|
||||||
@ -50,4 +49,4 @@ pg_dump --format=t "$DBNAME" -f $DUMPFILE
|
|||||||
gzip $DUMPFILE
|
gzip $DUMPFILE
|
||||||
|
|
||||||
# 3- Rotate backups: remove unneeded copies
|
# 3- Rotate backups: remove unneeded copies
|
||||||
/opt/scodoc/Products/ScoDoc/misc/backup_rotation.sh "$DUMPBASE"
|
/opt/scodoc/tools/backups/backup_rotation.sh "$DUMPBASE"
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Backup rotation
|
# 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
|
# This script is designed to run each hour
|
||||||
#
|
#
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# A adapter a vos besoins. Utilisation a vos risques et perils.
|
# A adapter a vos besoins. Utilisation a vos risques et perils.
|
||||||
#
|
#
|
||||||
# E. Viennet, 2002
|
# E. Viennet, 2002, 2021
|
||||||
|
|
||||||
# Installation:
|
# Installation:
|
||||||
# 1- Installer rsync:
|
# 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:
|
# A qui envoyer un mail en cas d'erreur de la sauvegarde:
|
||||||
SUPERVISORMAIL=emmanuel.viennet@example.com
|
SUPERVISORMAIL=emmanuel.viennet@example.com
|
||||||
|
|
||||||
CALLER=`basename $0`
|
CALLER=$(basename $0)
|
||||||
MACHINE=`hostname -s`
|
MACHINE=$(hostname -s)
|
||||||
|
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ MACHINE=`hostname -s`
|
|||||||
# ----------------------------------
|
# ----------------------------------
|
||||||
terminate()
|
terminate()
|
||||||
{
|
{
|
||||||
dateTest=`date`
|
dateTest=$(date)
|
||||||
|
|
||||||
mail -s "Attention: Probleme sauvegarde ScoDoc" $SUPERVISORMAIL <<EOF
|
mail -s "Attention: Probleme sauvegarde ScoDoc" $SUPERVISORMAIL <<EOF
|
||||||
The execution of script $CALLER was not successful on $MACHINE.
|
The execution of script $CALLER was not successful on $MACHINE.
|
||||||
@ -57,7 +57,7 @@ EOF
|
|||||||
echo "Look at logfile $logfile"
|
echo "Look at logfile $logfile"
|
||||||
echo
|
echo
|
||||||
echo "$CALLER terminated, exiting now with rc=1."
|
echo "$CALLER terminated, exiting now with rc=1."
|
||||||
dateTest=`date`
|
dateTest=$(date)
|
||||||
echo "End of script at: $dateTest"
|
echo "End of script at: $dateTest"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
@ -74,16 +74,16 @@ EOF
|
|||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
rsync_mirror_to_remote()
|
rsync_mirror_to_remote()
|
||||||
{
|
{
|
||||||
echo "--------------- mirroring " $MACHINE:$srcdir " to " $remotehost:$destdir >> $logfile 2>&1
|
echo "--------------- mirroring $MACHINE:$srcdir to $remotehost:$destdir" >> $logfile 2>&1
|
||||||
echo "starting at" `date` >> $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
|
rsync -vaze ssh --delete --rsync-path=/usr/bin/rsync "$srcdir" "$remotehost:$destdir" >> $logfile 2>&1
|
||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
echo Error in rsync: code=$?
|
echo Error in rsync: code=$?
|
||||||
terminate
|
terminate
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "ending at" `date` >> $logfile 2>&1
|
echo "ending at $(date)" >> $logfile 2>&1
|
||||||
echo "---------------" >> $logfile 2>&1
|
echo "---------------" >> $logfile 2>&1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user