Projet

Général

Profil

Actions

Copie de sécurité

Création

Méthode manuelle

Remplacer les items suivants :

  • username : Usager de la base de donnés.
  • password : Mot de passe de la base de donnés.
  • database : Nom de la base de données.
  • path : Emplacement pour recevoir le fichier.
/usr/bin/mysqldump -u username -p password database | gzip > /path/redmine_`date +%y_%m_%d`.gz
rsync -a /srv/redmine/files /path/

Script un peu plus évolué

#!/bin/bash
#
# backup_redmine.sh
# Backup of a Redmine setup
# Last Changes: 2013-02-23
# Maintainer: Patrice Nadeau  <pnadeau@patricenadeau.com>

# TODO Verify the results (folder exist, enough disk pace , etc..)

## The only variable needed to be changed
# Directory of the Redmine install
declare -r RAIL_ROOT='/srv/redmine'
# MySQL database
declare -r MYSQL_DB=''
# MySQL username for the Redemine db
declare -r MYSQL_USER=''
# MySQL password for the Redemine db
declare -r MYSQL_PASSWORD=''
# Directory for the backup (must exist and with no space in the name)
declare -r DIR='/root'
## end

# Exit level
declare -ir EXIT_OK=0
declare -ir EXIT_WARNING=1
declare -ir EXIT_ERROR=2

declare -i STATUS=$EXIT_OK

# The directory inside the archive 
declare -r REDMINE='redmine'
TMP_DIR=$DIR/$REDMINE

# This will be used for the archive file 
declare -r DST=$DIR/redmine_$(date +%Y%m%d_%H%M%S).tar.gz

# The temporary sql file
declare -r TMP_MYSQL=$TMP_DIR/$MYSQL_DB.mysql

echo "Backup in progress in $DST"

#### Create the temp directory ####
mkdir $TMP_DIR

#### backup MySQL ####
if [ $STATUS -eq $EXIT_OK ] 
then
    STEP='Creating MySQL backup'
    mysqldump --user=$MYSQL_USER --password=$MYSQL_PASSWORD $MYSQL_DB \
        > $TMP_MYSQL
    STATUS=$?
fi

#### backup the Redmine folder ####
if [ $STATUS -eq $EXIT_OK ] 
then
    STEP='Creating Redmine'"'"' files backup'
    cp --recursive $RAIL_ROOT $TMP_DIR
    STATUS=$?
fi

#### create the archive file ####
if [ $STATUS -eq $EXIT_OK ] 
then
    STEP="Creating archive"
    tar --create --gzip --file $DST --directory=$DIR $REDMINE
    STATUS=$?
fi

#### cleanup ####
if [ $STATUS -eq $EXIT_OK ] 
then
    STEP='Cleaning up'
    rm --recursive --force $TMP_DIR
    STATUS=$?
fi

#### exit ####
if [ $STATUS -eq $EXIT_OK ] 
then
    echo "Backup done"
else
    echo "Bakup failed with error code $STATUS in step $STEP"
fi


exit $STATUS

Mon script

Disponible à "dans la section fichiers":/attachments/download/137

Utilisation

Simplement changer les 4 variables situées au début du script

  • 3 pour MySQL
  • 1 pour la destination de la copie

Rendre le script exécutable

chmod +x backup_redmine.sh 

Et exécuter

./backup_redmine.sh

Récupération

Sur un serveur avec Redmine déjà installé

  1. Recopier le répertoire « Redmine »
  2. Remettre la base de données.

    # Si la copie a été fait avec mysql
    mysql -u redmine -p < redmine.sql
    # Si la copie a été fait avec mysqldump
    mysqldump -u redmine -p < redmine.sql
    

En supposant :

  • l'usager MySQL/MariaDB se nomme redmine
  • la base de donnes se nomme redmine.mysql

Mis à jour par Patrice Nadeau il y a plus de 5 ans · 19 révisions