HowTo: Move data directory

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
gumba
New user
New user
Posts: 19
Joined: 2008-09-01 19:45

HowTo: Move data directory

Postby gumba » 2009-05-04 18:43

This is just a short description how to move your datadirectory to a new location (or other drive). Although there r some descriptions how to move the data, or to change the database, i somehow missed a "whole" thing. It is written for Hmailserver 5.1 using a mysql database and a php engine (apache). It should work fine with older versions. If you use another DB system u have to modify some steps concerning the db. Use this description at your own risk. I did write it down from my memory, so some steps might be mixed up when it comes to the setup of hmailserver. And english is obviously not my first language, so there might be some mixups too. Nevertheless i hope i can give clueless guys some hints how to do this.

Problems discussed:
- Hmailserver uses a db to save the path to EVERY email. If u change the dir, u HAVE TO change the content of the db.
- mysql isnt shipped anymore with hmailserver
- Hmailserver sets up envirometnal variables, which are cheesy to edit by hand.

Lets get started.

Step 1:
Stop HMailserver.

Step 2:
Backup your datadirectory, your hmailserver.ini and your database for safety reasons.

If you dont do that allready on a regular basis - START NOW. You will find your directories most likely in the hmailserver installation folder. It should be something like c:\program files (x86)\hmailserver\data and bin.

Hint: For data backup, use CobianBackup. For your mysql server either use phpmyadmin, or mysqldumper (which is pretty powerful backup solution written in php)(couldnt find english version right now).

After the backup of the database, rename the hmailserver table to whatsoever. We will use it later again.

Step 3:
Re-Install HMailserver.

Because HMailserver sets some enviromental variables it is way more easy to deinstall the server and do a new setup on the prefered drive, than changing everything by hand.
De-Install Hmailserver.
Load the latest stable version from http://www.hmailserver.com and install it on your prefered drive..

Step 4:
Follow the guide, till it asks you for your db solution. As mentioned above this minitut is going to use mysql.
Choose to create a new database, since we will use the old one anyways. (I couldnt use the second option it just kept quitting without mentioning what went wrong).
The wizard will ask you for your login data.
Commonly its localhost (try 127.0.0.1 if localhost wont work) and the preset port. Use your username and password, as well as a databasename. The database will be created by hmailserver.

HMailserver will now try to connect to the database and will most likely fail. This is because of the closed source policy of mysql. Hmailserver is not shipped with the necessary libmysql.dll anymore. Copy the dll from your local Apache setup configuration to the your new hmailserver/bin folder. Do not use the libmysql.dll which is sometimes shipped with windows. It will not work. If you are using xampp or something similar, search the mysql/bin folder.

Try to reconnect to the db and be patient. If the connection error still apears, check the screen output (seriously) and/or check your username and password for the db.

Step 5:
Finish setup.
Set up the necessary login data for your hmailserver adminpanel.

Step 6:
Acquiring new data path.
Go to your new hmailserver folder and open the hmailserver.ini. Check the line with the datadirectory. Copy the path, we will need it change our old database.

Step 7:
Changing your database.

Use this simply and dirty script to change your database (the old 1, u renamed in before).

Code: Select all

<?
$old_path = 'd:\hMailServer\Data'; // do not end on a backslash here, it will cause errors if unescaped
$new_path = 'd:\hMailServer\Data'; // do not end on a backslash here, it will cause errors if unescaped


$link = mysql_connect("localhost", "username", "password") // your connection data here
   or die("No connection possible: " . mysql_error());
mysql_select_db("hmailserver") or die("db selection failed"); // your dbname here

$change_data = mysql_query("   UPDATE
                             hm_messages
                     SET
                             messagefilename=REPLACE(messagefilename,'".mysql_real_escape_string($old_path)."','".mysql_real_escape_string($new_path)."')
                  ") or die(mysql_error());


Step 8:
Rename your changed old db to be the new one. Use the db_updater located in the hmailserver directory to get it up to date.

Step 9:
Done. Start HmailServer.

intelemark
New user
New user
Posts: 2
Joined: 2009-06-11 13:17

Re: HowTo: Move data directory

Postby intelemark » 2009-06-11 13:57

Hi,

Please Help me on that.

I installed MySQL database in my debian box. Now,How i can locate my "data directory" of MySQL and i need to move the "data directory" alone to some other location,and MySQL need to point the data directory location.

Thanks in Advance

gumba
New user
New user
Posts: 19
Joined: 2008-09-01 19:45

Re: HowTo: Move data directory

Postby gumba » 2009-06-11 14:18

Im not familiar with the directorysettings on your machine.

If u want solely to move ur mysql dir u can just backup ur db.

mbach
Normal user
Normal user
Posts: 49
Joined: 2005-12-12 14:15

Re: HowTo: Move data directory

Postby mbach » 2009-06-15 22:17

Sorry to ask that stupid question:

where should I put the script in? I tried to use it in the MySQL Query Browser, but that did not work...

Thanks, Markus

gumba
New user
New user
Posts: 19
Joined: 2008-09-01 19:45

Re: HowTo: Move data directory

Postby gumba » 2009-06-15 22:24

Save as changedir.php, put it into ur htdocs folder. U will need an apache, or IIS with php extension (or some kind of server which is capable of interpreting php).

Change paths in the script. Run it as u would any normal php script.

U could however do the query by hand. Phpmyadmin could come in handy. The query would be very similar to the one used in the script.

Remember to backup 1st.

prof jolly
New user
New user
Posts: 15
Joined: 2008-11-07 18:39

Re: HowTo: Move data directory

Postby prof jolly » 2009-07-17 17:55

Do you really have to do an uninstall and reinstall to change just the data folder?

What environmental variables does hmailserver have?

User avatar
martin
Developer
Developer
Posts: 6712
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Re: HowTo: Move data directory

Postby martin » 2009-07-17 17:59

> Do you really have to do an uninstall and reinstall to change just the data folder?

No?

> What environmental variables does hmailserver have?

What precisely do you mean by this?

prof jolly
New user
New user
Posts: 15
Joined: 2008-11-07 18:39

Re: HowTo: Move data directory

Postby prof jolly » 2009-07-17 18:15

from first post
Problems discussed:
- Hmailserver uses a db to save the path to EVERY email. If u change the dir, u HAVE TO change the content of the db.
- mysql isnt shipped anymore with hmailserver
- Hmailserver sets up envirometnal variables, which are cheesy to edit by hand.

would i be correct in thiking i could just
1. stop service
2. move files to new folder
3. change the hMailServer.INI file to point to the new folder
4. change the messagefilename in db to point to new folder?

User avatar
martin
Developer
Developer
Posts: 6712
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Re: HowTo: Move data directory

Postby martin » 2009-07-17 18:20

I understand what you mean now.

> would i be correct in thiking i could just

Yes. This topic is just misleading. There's no point in reinstalling hMailServer if all you want to do is change the data directory. I'll probably delete this topic ...

prof jolly
New user
New user
Posts: 15
Joined: 2008-11-07 18:39

Re: HowTo: Move data directory

Postby prof jolly » 2009-07-17 18:21

anyone know a quick mssql query to change the filename in the db? even if its only c: to d:

sckramer2
Normal user
Normal user
Posts: 126
Joined: 2009-07-31 21:50

Re: HowTo: Move data directory

Postby sckramer2 » 2009-07-31 21:52

UPDATE hm_messages SET messagefilename=REPLACE(messagefilename,'C:\\Program Files\\hMailServer\\Data','S:\\hMailServer\\Data')

seebold
New user
New user
Posts: 1
Joined: 2014-02-18 14:24

Move data directory in Windows Server 2012/Windows 7 (Solved

Postby seebold » 2014-02-18 14:45

I had some problems, changing the data folder path using this tutorial. Here my experiences:

    Changing the data path in hmailserver.ini hat no effect, even after clicking stop/resume in hMailServer Status Tab.
    Reinstallation of hMailserver brought error with something like "... COM-..." (I forgot), but I had to recover an old backup

Finaly I managed it:
    1. Stop hMailserver Service directly in Windows (http://technet.microsoft.com/en-us/library/cc736564%28v=ws.10%29.aspx). The button Stop/Resume in hMailserver does not stop the hmailserver-service; whatever they say.
    2. Copy all files to the new directory.
    3. Change bin\hmailserver.ini in the way: DataFolder=D:\.... (Use quotes if spaces in the path)
    4. Change in the SQL-database hm_messages the path using the query written by sckramer2. I used the search/replace-function in MySQL-Front. Newer entries in hm_messages do not have a absolute path, so this step might be unnecessary, just check.
    5. Open hMailServer Administrator and the service will start again automatically.
    6. Enjoy :-)
It is NOT necessary to reinstall hmailserver. Don't do it!

Bill48105
Developer
Developer
Posts: 6171
Joined: 2010-04-24 23:16
Location: Michigan, USA

Re: Move data directory in Windows Server 2012/Windows 7 (So

Postby Bill48105 » 2014-02-18 17:08

seebold wrote:I had some problems, changing the data folder path using this tutorial. Here my experiences:

    Changing the data path in hmailserver.ini hat no effect, even after clicking stop/resume in hMailServer Status Tab.
    Reinstallation of hMailserver brought error with something like "... COM-..." (I forgot), but I had to recover an old backup

Finaly I managed it:
    1. Stop hMailserver Service directly in Windows (http://technet.microsoft.com/en-us/library/cc736564%28v=ws.10%29.aspx). The button Stop/Resume in hMailserver does not stop the hmailserver-service; whatever they say.
    2. Copy all files to the new directory.
    3. Change bin\hmailserver.ini in the way: DataFolder=D:\.... (Use quotes if spaces in the path)
    4. Change in the SQL-database hm_messages the path using the query written by sckramer2. I used the search/replace-function in MySQL-Front. Newer entries in hm_messages do not have a absolute path, so this step might be unnecessary, just check.
    5. Open hMailServer Administrator and the service will start again automatically.
    6. Enjoy :-)
It is NOT necessary to reinstall hmailserver. Don't do it!

Indeeed seebold the main reason the button in the GUI admin was renamed from Stop/Start to Pause/Resume in 5.4 was to make it more obvious it was NOT the same as Stop/Start/Restart in Windows service management! I went beyond that & put a note below the button that says (Use Windows to Start/Stop Service). Surely those 2 things give enough clues.. Or must I also add a popup dialog with more details & an agreement button? ;) Also keep in mind this howto was created back in 2009 well before 5.4.
Bill
*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***
hMailServer build LIVE on my servers: 5.4-B2014050402
Latest test builds: http://www.hmailserver.com/forum/viewtopic.php?f=10&t=21420

User avatar
mattg
Moderator
Moderator
Posts: 13995
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: HowTo: Move data directory

Postby mattg » 2014-02-19 01:05

Yep, all much easier since this thread was last updated some 4 years ago....

Must be the new version, Bill. :mrgreen:

I suspect that seebold was using an older version due to the fact that they didn't see your renaming of those buttons?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Orlanda
New user
New user
Posts: 1
Joined: 2014-02-27 13:51
Location: USA
Contact:

Re: HowTo: Move data directory

Postby Orlanda » 2014-03-05 12:09

i am worried how can i move the data this forum is help me to understand the process.

User avatar
mattg
Moderator
Moderator
Posts: 13995
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: HowTo: Move data directory

Postby mattg » 2014-03-05 14:10

Please start a new thread and link back to this one if you see fit, but seriously, a little more information is required.

Where are you moving data directory to & from
What version of hMailserver
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation


Return to “General discussions”



Who is online

Users browsing this forum: No registered users and 1 guest