Moving moodledata folder

Moving moodledata folder

by CoreDev Develop -
Number of replies: 14

Hi All,

I am planning to move my moodledata folder from /usr/ to /home folder within the same physical server.  This is because the limited space I have on the /usr partition.  

My plan is: shutdown moodle, update config.php to point to the new location, then start the moodle. 

Below are some of my questions:

- What do I need to change beside the config.php?

- Do I need to change the permission

- What other step do I need to do?

I am using Red Hat 6.3, MySql and Moodle 2.3 stable. 

Please advise.

Thanks and Regards,

Yulstar

Average of ratings; -
In reply to CoreDev Develop

Re: Moving moodledata folder

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think you just need to update config.php. If possible, test this on a test server first.

In reply to CoreDev Develop

Re: Moving moodledata folder

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi

How come moodledata came to /usr in the first place? http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard says, "/usr Secondary hierarchy for read-only user data; contains the majority of (multi-)user utilities and applications". How did you install Moodle? A package version?

Your plan should work with one modification: Move moodledata keeping the permissions. 'cp -r' will look after that.
In reply to Visvanath Ratnaweera

Re: Moving moodledata folder

by Ken Task -
Picture of Particularly helpful Moodlers

Uhhh ... minor but cp -r does recursive and cp -rp does recursive AND perserve (permissions/ownerships), does it not?

If using mv think I'd still check ownerships/persmissions *after* the mv.

'spirit of sharing', Ken

In reply to Ken Task

Re: Moving moodledata folder

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I wouldn't recommend using mv across file systems as in this example as it is not atomic and if it were to fail half-way through (e.g. you filled your target disk by mistake) I'm not quite sure what state it would leave your data in. As a result, it could be difficult to recover.

Andrew

In reply to Ken Task

Re: Moving moodledata folder

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Sorry, I meant 'cp -a' (archive). Yes, 'cp -rp' is more descriptive. 'man cp' has it all.

Ken, thanks for pointing out.
In reply to CoreDev Develop

Re: Moving moodledata folder

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Yulstar,

You only need to change your config.php. I would recommend putting your site into maintenance mode whilst you perform the move. This will ensure you don't miss any files by mistake.

As Visvanath has already aluded to, /usr is really the wrong place for data. Yes, even /usr/local. The correct place according to the File Hierarchy Specification is /srv - see http://www.pathname.com/fhs/pub/fhs-2.3.html#SRVDATAFORSERVICESPROVIDEDBYSYSTEM for information. It's up to you how you arrange it but I'd advise something sensible which states what it's for. I would recommend something like /srv/www/URL/data. For example:

/srv/www/moodle.org/data

Your file permissions must stay the same, so I would recommend using rsync. I would recommend against using cp or mv. If you have to interrupt the transfer part way through, you will have to start again with a cp, and mv will not be atomic across file systems. rsync is designed for this kind of purpose and can be invoked with something like:

rsync -avi /usr/local/somewhere/really/strange /srv/www/my.moodle.site/data

Best wishes,

Andrew

In reply to Andrew Lyons

Re: Moving moodledata folder

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

p.s. you can cancel and resume and rsync and it will not have to copy existing files again.

In reply to Andrew Lyons

Re: Moving moodledata folder

by CoreDev Develop -

Dear All,

Thanks for all the response. We realize the mistake to install it in the /usr folder as this is our first installation. We install from moodle package. 

Our plan is to down the apache completely. Then, copy the file from /usr folder to /home folder or other subfolder under /home. We have not decide yet.  We don't want to Move in case something wrong we during the testing, so we can revert back to the /usr folder for time being. 

We have a crontab running rsync every night to home folder for backup purposes. So, either I use this or I will run another rsync for to the target folder. 

Permission wise, we create new users for the moodledata, not using the root folder. So, as mentioned, I will need to make sure the permission should be the same.

Thanks a lot for all the responses.

Best Regards,

Yulstar

 

In reply to CoreDev Develop

Re: Moving moodledata folder

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
> We install from moodle package.

Could you disclose whose package? Even better, describe HOW you installed Moodle or point to the tutorial you used.
In reply to CoreDev Develop

Re: Moving moodledata folder

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Yulstar,

You don't need to down Apache completely. It's better to put Moodle into maintenance mode. This way, any CLI cron jobs you have also won't be running.

That said, in thinking about it, you don't need to have any downtime at all because rsync does enough magic:

  • rsync your data to the new location
  • rsync again to ensure the diff is small
  • change your config.php
  • rsync again to pick up anything that had changed in the time that it took to change your config.php

Unless you run rsync with --delete, then the rsync is additive and corrective only.

You need to ensure that the ownership of the files does not change. Your web server must be able to read and write all of the files. Changing ownership to a different user account would prevent this.

Why are you putting these files in /home? It's not an ideal location. If you really must, then put them in /home/apache (or whatever username your web server runs as), but this 

Ick - crontab ;(

Andrew

In reply to Andrew Lyons

Re: Moving moodledata folder

by CoreDev Develop -

Thanks Andrew, 

I am testing the rsync command using crontab and let it run on 4 AM in the morning since last friday. 

I check and compare the moodledata, the size are different today. The source moodledata size is only about 8 GB, but the target size is about 14GB.  Could you advise what happen? How come the size is different?

I am using: rsync -azvr.

Thanks and Regards,

Yulstar

In reply to Andrew Lyons

Re: Moving moodledata folder

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Andrew, I really like your suggestion to use rsync.

How would this command look if I wanted to rsync between two different servers?  Would I have to embed a password?

Thanks.

In reply to Rick Jerz

Re: Moving moodledata folder

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Rick,

You'd use ssh to do so:

rsync -avi -e ssh /srv/www/learn.myschool.sch.uk/data newserver:/srv/www/learn.myschool.sch.uk/data

To avoid using passwords, use an ssh key on the servers.

Best wishes,

Andrew

In reply to Andrew Lyons

Re: Moving moodledata folder

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Andrew, thanks.  How do I use this command with the ssh key?  And if I did want to use passwords, how would this command look, if it is possible.

I have been reading about rsync, and I have still not found answers to how to completely do this, with examples.  So I thought maybe you would know.

Thanks.