info:backups_moodle

Ceci est une ancienne révision du document !


Backups Moodle

Faire des sauvegardes de son moodle en ligne de commande

A: accès ssh

Si vous avez un accès ssh aux deux machines, rien de plus simple

placer le script suivant en l'adaptant et le rendre exécutable

exportMoodle.sh

#!/bin/bash
############################################################################
#    Copyright (C) 2005 by fradeff@akademia.ch                             #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation; either version 2 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program; if not, write to the                         #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################
# Usage:
# exportMoodle.sh
# Required:
# ssh, mysql, mysqldump, rsync
# hint: place in a crontab, and use script importMoodle.sh to restore your backup on a distant (backup) server

# Authors:
# FR, fradeff@akademia.ch, akademia.ch

# History
#   --- //[[fradeff@akademia.ch|Fred Radeff]] 2008/12/03 09:06//---  FR, created
#########################
## BEGIN VARIABLES ##
# definir les chemins

# chemin moodle sur le serveur de production
chemin="/home/yourlogin/cms/moodle/"
# chemin données moodle (normalement pas sous le serveur web)
datas="/home/yourlogin/data/moodledata"
# nom local de la base de données moodle
moodledb="moodle"

#serveur distant pour backup
distant="yourlogin@distant.backup.server.net:/home/yourlogin/moodle"
### END VARIABLES ###
cd $datas
touch $moodledb.sql

### BACKUPS ###
#sauver bases mysql
mysqldump $moodledb --add-drop-table > $moodledb.sql
############# syncing all ###########
rsync -avz $datas/* $distant/
#

chmod 755 exportMoodle.sh

ps: ce script suppose que vous avez configuré mysql avec un ~/.my.cnf qui vous évite de taper votre login et mot de passe pour le serveur mysql, cf my.cnf; si non, il faut changer mysqldump -u yourMySQLlogin -pYourMySQLpassword $moodledb –add-drop-table > $moodledb.sql

faire un crontab (ici tous les jours à 06h32)

crontab -e
# m h  dom mon dow   command
32 06 * * * /home/yourlogin/bin/exportMoodle.sh 

placer le script suivant en l'adaptant et le rendre exécutable

exportMoodle.sh

#!/bin/bash
############################################################################
#    Copyright (C) 2005 by fradeff@akademia.ch                             #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation; either version 2 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program; if not, write to the                         #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################
# Usage:
# importMoodle.sh
# Required:
# mysql
# hint: place in a crontab, and use script exportMoodle.sh to get the backup from your production server

# Authors:
# FR, fradeff@akademia.ch, akademia.ch

# History
#   --- //[[fradeff@akademia.ch|Fred Radeff]] 2008/12/03 09:06//---  FR, created
#########################
## BEGIN VARIABLES ##
# definir les chemins

# chemin moodle sur le serveur de backup
chemin="/home/yourlogin/moodle"
# nom local de la base de données moodle
moodledb="moodle"

mysql $moodledb < $moodledb.sql
#

ps: ce script suppose que vous avez configuré mysql avec un ~/.my.cnf qui vous évite de taper votre login et mot de passe pour le serveur mysql, cf my.cnf; si non, il faut changer mysql -u yourMySQLlogin -pYourMySQLpassword $moodledb < $moodledb.sql

faire un crontab (ici tous les jours à 07h32), soit une heure après l'export

crontab -e
# m h  dom mon dow   command
32 06 * * * /home/yourlogin/bin/importMoodle.sh 

B: accès FTP

plus compliqué pour faire automatique; le plus simple est de copier “à la main” selon les besoins, ou de faire quelque chose avec FTP without password prompt (resterait à écrire le script pour faire les mput* des fichiers différents… fastidieux, à moins que quelqu'un ne l'ait déjà fait - sans doute le cas, ou regarder avec un outil genre ruby, perl ou php)

  • info/backups_moodle.1531899946.txt.gz
  • Dernière modification : 2018/07/18 09:45
  • de radeff