PDA

View Full Version : Moodle Backup



mastercsmith1990
29-03-11, 09:25
I am not sure whether this topic is in the correct area so i apologise for that.

I just wanted to know if there is a way on being able to automatically backup a moodle site and also the database. I am able to set an automatic backup for the files etc but i need a way on being able to schedule a backup automatically for database (i can do it manually)

I have looked on many websites which it has given and it goes slightly complicated with it asking you to create scripts. I am not a php kinda person i only know the basics of how you set up a php server anything other than that i get stuck on.

Any help is appreciated.

Dukey
29-03-11, 11:07
Is the server IIS based or Apache based? :)
and if Apache, Windows or Unix based? :)

Polo
29-03-11, 16:07
If it's a windows based server, you can use task scheduler to run a batch script which automatically makes a copy of all the files you need.

If, however, it's a unix server, you can use cronjobs (similar to task scheduler) to run a script.

Google should be able to help in creating a basic script to copy files. If not, I'm sure Dukey can. ;)

Dukey
29-03-11, 16:19
If it's a windows based server, you can use task scheduler to run a batch script which automatically makes a copy of all the files you need.

If, however, it's a unix server, you can use cronjobs (similar to task scheduler) to run a script.

Google should be able to help in creating a basic script to copy files. If not, I'm sure Dukey can. ;)

Personally I have found batch / shell scripts a little inflexible for database backups, but should work nicely for the file copies. I personally use the following PHP script for MySQL backups. which I execute directly using the PHP executable via CRON/Task Scheduler, then is emailed to me in a compressed format.





// Create the mysql backup file
// edit this section
$dbhost = "localhost"; // usually localhost
$dbuser = " **database username** ";
$dbpass = " **database password** ";
$dbname = " **database name**";
$sendto = " **an email you want the backup sent to**";
$sendfrom = "**an address on your server**";
$sendsubject = "SQL Backup";
$bodyofemail = "Here is the backup dated: ".date("d/m/Y");
$tmp = "a temporary directory on your server"
// don't need to edit below this section

/*

Quickly and easily backup your MySQL database and have the tgz emailed to you. You need PEAR installed with the Mail and Mail_Mime packages installed. Read more about PEAR here: http://pear.php.net. This will work in any *nix enviornment. Make sure you have write access to your /tmp directory.

*/
include('PEAR.php');
require_once('Mail.php');
require_once('Mail/mime.php');

// mysql & minor details..
$tmpDir = "/home/stovesp/tmp/";
$user = $dbuser;
$password = $dbpass;
$dbName = $dbname;
$prefix = "db_";

// email settings...
$to = $sendto;
$from = $sendfrom;
$subject = "Database Backup";
$sqlFile = $tmpDir.$prefix.date('Y_m_d').".sql";
$attachment = $tmpDir.$prefix.date('Y_m_d').".tgz";

$creatBackup = "mysqldump -u ".$user." --password=".$password." ".$dbName." > ".$sqlFile;
$createZip = "tar cvzf $attachment $sqlFile";
exec($creatBackup);
exec($createZip);

$headers = array('From' => $from, 'Subject' => $subject);
$textMessage = $attachment;
$htmlMessage = "";

$mime = new Mail_Mime("\n");
$mime->setTxtBody($textMessage);
$mime->setHtmlBody($htmlMessage);
$mime->addAttachment($attachment, 'application/x-compressed');
$body = $mime->get();
$hdrs = $mime->headers($headers);
$mail = &Mail::factory('mail');
$mail->send($to, $hdrs, $body);

unlink($sqlFile);
unlink($attachment);


Hopefully other people have some more elegant solutions, I'd be interested in them too :)

mastercsmith1990
30-03-11, 14:28
Is the server IIS based or Apache based? :)
and if Apache, Windows or Unix based? :)

It is running Windows Server 2003 Enterprise Edition, and using XAMMP (apache).


Is the server IIS based or Apache based? :)
and if Apache, Windows or Unix based? :)

It is running Windows Server 2003 Enterprise Edition, and using XAMMP (apache).

Added after 3 minutes:


Hopefully other people have some more elegant solutions, I'd be interested in them too :)

I will give your method a try but if find another method to being able to backup the database then i will be sure to let you know dukey ;)

Thanks for your help and assistance :)

Polo
30-03-11, 15:54
I will give your method a try but if find another method to being able to backup the database then i will be sure to let you know dukey ;)

Thanks for your help and assistance :)
You can just use a batch script to copy the files in C:/xampp/mysql/data/your-database-name (assuming XAMPP is installed on your C drive, of course). Or you could copy the entire /data folder if you have a lot of databaes to backup. Then if you ever need to restore the database, just paste whatever version you want back into the folder. Dukey's method is probably better though. :P