Moodle: Copy Database

From OnnoWiki
Jump to navigation Jump to search

A Moodle system comprises three parts:

  1. The data stored in the database (For example, a MySQL database)
  2. The uploaded files (For example, site and course files uploaded via Moodle located in moodledata)
  3. The Moodle code (For example, everything in server/htdocs/moodle)

You can confirm where all these things are located in a Moodle installation by checking the config.php file.

  1. $CFG->dbname shows the database name
  2. $CFG->prefix shows the the database table name prefix
  3. $CFG->dataroot controls where the uploaded files are stored; and
  4. $CFG->wwwroot points to where the code is stored.

Tip

Generally speaking, the database ("dbname and prefix") and the uploaded files (dataroot) are the two most important to copy on a regular basis. These contain information that will change most often.

The Moodle code (wwwroot) is less important as a frequent backup, since it will only change when the the actual code is changed through upgrades, addins and code tweaks. You can always get a copy of the standard Moodle code from http://download.moodle.org so you only have to backup the parts you added or changed yourself.

menggunakan moodle_backup.php

  • Download dari
http://cvs.moodle.org/contrib/tools/moodle_backup/moodle_backup.php
http://cvs.moodle.org/contrib/tools/moodle_backup/moodle_backup.php?view=co
http://cvs.moodle.org/contrib/tools/moodle_backup/moodle_backup.php?view=log
  • siapkan
apt-get install zip
mkdir /var/moodlebackups
chmod -Rf 777 /var/moodlebackups
chown -Rf nobody.nogroup /var/moodlebackups
  • buat script
cd /usr/local/bin
touch moodle_backup.php
chmod -Rf 777 moodle_backup.php 
chown -Rf nobody.nogroup moodle_backup.php
vi moodle_backup.php

Ubah agar

//=================================
// CONFIG SECTION - EDIT ME
//=================================

// location of Moodle config files
// list one or more config file locations on your system
// whatever user this runs as needs read permission to the config files
// AND to the moodledata area
$configs = array();
$configs[] = '/var/www/moodle/config.php';
//$configs[] = '/var/www/moodle2/config.php';
//$configs[] = '/var/www/moodle2/config.php';
//$configs[] = '/var/www/moodle2/config.php'; 

// path to your zip binary
// if you're not sure, do 'which zip' on the command line
$zippath = '/usr/bin/zip';

// location of backup folder
// do not include trailing slash
// whatever user this runs as needs write permissions to this
$backuploc = '/var/moodlebackups';

//=================================
// END OF CONFIG SECTION
//=================================


Menjalankan script

php moodle_backup.php

menggunakan mysqldump

WARNING: Entah kenapa password user jadi beda / berubah, kayanya karena hash

  • Install Moodle Kosong di mesin mirror
  • di mesin asal
/usr/bin/mysqldump -u root -p123456 -C -Q -e --create-options moodle | /bin/gzip -9 > moodle-database.sql.gz
scp moodle-database.sql.gz stkip@10.150.5.249:


  • di mesin mirror
cd ~
gunzip moodle-database.sql.gz 
sudo mysqladmin --user=root --password=123456 --force drop moodle
sudo mysqladmin --user=root --password=123456 create moodle
sudo mysql -u moodle -pmoodle moodle < ~/moodle-database.sql
scp -r root@10.150.5.250:/var/moodledata /var
sudo chmod -Rf 777 /var/moodledata/lang/
sudo chown -Rf www-data.www-data /var/moodledata/lang/
sudo chown -Rf www-data.www-data /var/moodledata/

scp database

WARNING: Cara ini akan menimbulkan error karena banyak yang kurang lengkap

mysql -u root -p123456
create database moodle;
ALTER DATABASE moodle charset=utf8;
grant ALL on root.* to moodle@localhost;
grant ALL on moodle.* to moodle@localhost identified by "moodle";
grant ALL on moodle.* to moodle identified by "moodle";
exit


scp -r root@10.150.5.250:/var/lib/mysql/moodle /var/lib/mysql
scp -r root@10.150.5.250:/var/moodledata /var
scp -r root@10.150.5.250:/var/www/moodle /var/www
chmod -Rf 777 /var/moodledata/lang/
chown -Rf www-data.www-data /var/moodledata/lang/
chown -Rf www-data.www-data /var/moodledata/
chmod -Rf 777 /var/www/moodle	
chown -Rf www-data.www-data /var/www/moodle 
chown -Rf mysql.mysql /var/lib/mysql/moodle
config.php:$CFG->wwwroot   = 'http://10.150.5.250/moodle';
vi /var/www/moodle/config.php

Referensi

Pranala Menarik