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.

You write that you're running hMailServer 2.6, but I'm assuming you mean 5.6.

I looked in the dmp file and see that the error occur when the backup process copies a specific file.

Is there any error log created when the error occur? Those are located in the log directories and have a name which starts with ERROR_. This log should hopefully contain the exact error message which may explain why the error occur.

1, STOP HMAILSERVER service ('net stop hmailserver')
2, use ROBOCOPY to mirror your data directory to a temporary data directory
3, copy the SDF database file to a temporary database' directory (or if using an external database, do a 'dump' of the database to a .SQL file)
4, start hmailserver
(the above should take just seconds to run after the first time)
5, ZIP the temporary backup/database directories
(6, DONT delete the temporary data directory)

This process is simply in essence all the internal backup routine does. Except doing it this way you ensure that no files (incoming outgoing) get deleted whilst in process and more importantly hmailserver 'offline' time is kept to a minimum.

Create a batch file with the above, stick it in Task Scheduler.

Mine effectively does this but looks a lot more fancy as I incorporate other data directories and various checks for service stop/starting correctly, as well as incorporating notification emails as it processes. Im sure if you search the forums, or ask here, I/someone would be happy to show their ready-made versions if you dont fancy the 'challenge' (if you could call it a challenge).

are you using compression option when you dump?
Where are you dumping to and is the folder being scanned by real time AV program?
If so then try switching off AV while you do backup or exclude the backup folder from your AV scan.
And check your AV logs to see if anything is happening during the backup.
Also exclude hmailserver/temp from AV scans.

percepts wrote:are you using compression option when you dump?
Where are you dumping to and is the folder being scanned by real time AV program?
If so then try switching off AV while you do backup or exclude the backup folder from your AV scan.
And check your AV logs to see if anything is happening during the backup.
Also exclude hmailserver/temp from AV scans.

1. Yes
2. A different drive/folder and there is no real-time AV running on that machine.

It *looks* like it's some kind of race condition if a message is in the delivery queue at exactly the wrong time.

I've been running hMailServer on this box (which is actually a Hyper-V VM) (with a nightly backup run) for 3 years and I've had this error happen twice (both in January 2015).

I have always wondered about the safety of running a a backup whilst a server is still processing mail in that whilst the backup might appear to work its possible that between the xml extract from DB and backup of data folder, its possible that one or other could change which makes the restore potentially incomplete on one side or the other. i.e. DB entries with no eml or eml with no DB entry.
This probably isn't a problem on a server with low throughput and small volume of data run at night but its still a risk. But when backup starts taking a several minutes and longer the risk gets higher that a mail will be processed during backup which in the event of a restore can lead to loss of data.

Solution is to pause the mailserver during backup. Following mods to startbackup.vbs will do that. i.e. pause mail delivery (oApp.Stop) and resume (oApp.Start) either side of actual backup without actually shutting down hmailserver service.

' This scripts creates a hMailServer backup using the settings
' specified in hMailAdmin. You can double-click on the file to
' run the script.
'
' To use the script you need to update the sAdminPassword
' setting below to reflect your own hMailServer Administrator
' password. If you want to run automatic backups, please
' start this script using Windows Scheduled Tasks.
'
Const sAdminPassword = "password"
Dim oApp
Set oApp = CreateObject("hMailServer.Application")
' Authenticate the client.
Call oApp.Authenticate ("Administrator", sAdminPassword)
Call oApp.Stop
Call oApp.BackupManager.StartBackup()
Call oApp.Start

Infact I would suggest that hmail startbackup.vbs should do this by default. I know people might not like it but they will like it even less if they find a restore doesn't work or is missing data.
Then if people don't want to have to pause during backup they have to look at sorting out their own backup strategy such as raid mirroring to another box somewhere. What do you think Martin?

percepts wrote:Solution is to pause the mailserver during backup. Following mods to startbackup.vbs will do that. i.e. pause mail delivery (oApp.Stop) and resume (oApp.Start) either side of actual backup without actually shutting down hmailserver service.

I think that's a great idea really.

Archiving an in-use file system (especially one as fluid as a mail server queue and mailboxes) is a tricky proposition in any case so pausing would make a lot of sense.

I agree it should probably pause by default but probably make it an option at the top of the script so those that want it to behave as it has in the past would have that ability.

(Might be even safer to somehow put the mailboxes in a 'read only' mode so POP3/IMAP deletes/changes would either be queued or denied.)

The stop and start in the code I gave you does that already. Not only is mail stopped from processing but all connections are blocked too.

The com api stop and start are exact same as using PAUSE/RESUME in your hmailadmin STATUS panel. So you can see what effect they have on your email clients by hitting PAUSE and trying to do something in a client.

It seems you are correct and annoyingly StartBackup() doesn't seem to return anything which can be used as a test to delay the script from contnuing until the backup has finished.
Apologies for giving you a bad steer on this. I thought it worked.

That means shutting down hmailserver service before running backup. See above.

percepts wrote:It seems you are correct and annoyingly StartBackup() doesn't seem to return anything which can be used as a test to delay the script from contnuing until the backup has finished.
Apologies for giving you a bad steer on this. I thought it worked.

That means shutting down hmailserver service before running backup. See above.

Sub OnBackupCompleted() in EventHandler.vbs ??

SørenR.

The quantum rule of insecurity which states that the act of observing how vulnerable a host or service is changes the insecurity level of the service.

' This scripts creates a hMailServer backup using the settings
' specified in hMailAdmin. You can double-click on the file to
' run the script.
'
' To use the script you need to update the sAdminPassword
' setting below to reflect your own hMailServer Administrator
' password. If you want to run automatic backups, please
' start this script using Windows Scheduled Tasks.
'

OK after further testing and Sorens suggestion this is a more robust solution:

For StartBackup.vbs use

' This scripts creates a hMailServer backup using the settings
' specified in hMailAdmin. You can double-click on the file to
' run the script.
'
' To use the script you need to update the sAdminPassword
' setting below to reflect your own hMailServer Administrator
' password. If you want to run automatic backups, please
' start this script using Windows Scheduled Tasks.
'

I've noticed that this error comes out only if the destination directory is not empty (or if the file being backed up already exists in the destination directory).
When this error comes out subsequents backups fail with:

Now if you do (1) then you get a "hMailserverbackup.xml" file temporarily written out which is then zipped to an original-named zip file timestamped to the SECOND in the destination directory and the original temporary mailserverbackup.xml is deleted.

If you do (2) then as well as (1) the messages are copied to a temporary directory, then everything is zipped to the timestamped zip file and the temporary data messages are deleted.

Given that in both cases the zip file in the destination directory is created with a new timestamp, at what point are you having the scenario that matches: "if the file being backed up already exists"? WHAT file is existing??

funcoolio wrote:
i am backing up settings, domains and messages, compress files is not checked

And there is your problem.

a, ok, you have identified it is causing you a minor problem now but
b, EVEN IF IT 'worked' this backup would be no good to you.

If you DO NOT compress the messages, then you WILL NOT BE ABLE to restore from this backup. Fullstop. (It is a known bug/feature/non-sensical garbage, but netertheless it is fact. Read this thread fro the beginning. Trust me on this....or try a restore for yourself and see. )

Remember: it is always a good idea to test your restore procedures BEFORE actually needing them in a live environment. Your are lucky that this 'problem' came along and actually highlighted a fundamental error in your procedures.

There still seems to be an issue with this crashing periodically. Fortunately, it's not occurring very often.

While the backup is taking place, users can check/delete mail, the server can receive mail etc, and that's all good, however, hMailServer's backup function throws an exception if a file it thought it was going to copy gets deleted in the meantime.

The DataBackup folder (and it's contents) is left in the backup directory.

Future backup attempts fail because it still thinks backup is running. (BACKUP ERROR: Backup or restore operation is already started).

I would suggest perhaps the following ideas for a solution:

During the data directory backup, basically 'pause' the system. Perhaps still answer on the ports but with a 400 Server Busy or something. Unfortunately this can be a 10+ minute window depending on the volume of data.

Use Windows Shadow Copy to copy the data files.

Instead of throwing an exception if the file can't be found when it actually does the copy_file function, just log it and skip it.

This seems to almost always be the transient message queue, perhaps exclude it from backup? Not ideal but..

It would also probably be a good idea if an exception is thrown to log the event, clean up the temporary files, reset the backup status and alert the administrator (e-mail, popup, foghorn, etc). (Or make this an option.)

Guys, I'm not able to understand why we have to write batches and patches, do tricks, read hints about bugs, write post after post.

This software has a build in backup and should be able to do a hot backup compressed, not compressed or completely without messages. But it is not able to. This should be improved. I'd test it and I'd help whereever my help is wanted. But I'm not able to code it. I'm telling this anybody everytime. But nobody seems to listen...

Well, my workaround batch file to clean up when hMailServer's backup job crashes is working, however, the exceptions do seem to be occurring more often than you might expect. I have the backup scheduled to run the nightly at 5 minutes past midnight and through the month of July, the backup job has crashed 4 times. This is a little alarming because my mail server is very low traffic. (It's for me, some friends, and some family members.) So far it's always a message that has obviously been deleted or delivered by the time hMailServer gets to the file.

I think this is a pretty serious bug actually as it basically leaves hMailServer in a state where it can no longer run the backup job and just restarting the service won't fix it because the temporary files are all still in the backup location and hMailServer will throw a fit if it tries to run the backup job.

In my opinion, the options for a fix could be several things:

Pause the queue at the start of the backup job, and resume at the end.

Use VSS service to do a shadow copy.

Simply move on if a file isn't there instead of throwing an exception. (Perhaps log a warning with the pathname.)

Frankly, the last option is the best one as even if #1 and #2 are both implemented, this problem could still occur. Pausing the queue could have it's own issues if for some reason it didn't resume.

(The data storage location should also not be under Program Files but that's another issue entirely. Technically it should be under %ProgramData% or an administrator-specified path.)

I physically stop and start the service (rather than pause it) in my script to prevent this happening, and the service is offline for about 30 seconds whilst it does an MIRROR update of the files and takes a dump of MySQL database. I think 30 seconds in the dead of night is is far more acceptable (and highly unlikely to be a problem) than taking alternative methods which do cause this missing file problem.

jimimaseye wrote:I physically stop and start the service (rather than pause it) in my script to prevent this happening, and the service is offline for about 30 seconds whilst it does an MIRROR update of the files and takes a dump of MySQL database. I think 30 seconds in the dead of night is is far more acceptable (and highly unlikely to be a problem) than taking alternative methods which do cause this missing file problem.

I thought about doing it that way as well. I kinda wish I had gone with a MySQL install since it's easier to database dump that than MSSQL CE.

Still, my point is that hMailServer's backup function should just handle it without us having to work around it. It's overall such an excellent program, it's disappointing that this function is pretty much busted.

you do realise that the built in MS SQL CE is intended only for very small home installations, and it is against the EULA of that product to use this database in a commercial environment.

If the builtin hmailserver backup works, to change database you simply need to:-
1. back up (compressed including all messages)
2. installing the new database type (ie MySQL)
3. running the DBsetup.exe to create the tables and modify the hmailserver.ini
4. restore the backup

Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

mattg wrote:you do realise that the built in MS SQL CE is intended only for very small home installations, and it is against the EULA of that product to use this database in a commercial environment.

If the builtin hmailserver backup works, to change database you simply need to:-
1. back up (compressed including all messages)
2. installing the new database type (ie MySQL)
3. running the DBsetup.exe to create the tables and modify the hmailserver.ini
4. restore the backup

This is a home. My wife and I use it and a couple of friends and family members. I have a total of 6 email accounts on hMailServer.

(I have a windows domain setup under MSDN OS because I do a lot of programming/IT work as a consultant and stay in practice that way. Well, and I'm a geek.)

But thanks for the instructions -- might switch it to MySQL.

But anyway, the backup function shouldn't be crashing out if it can't find a file that's been deleted/moved from normal routing operations.

Lee Thompson wrote:But anyway, the backup function shouldn't be crashing out if it can't find a file that's been deleted/moved from normal routing operations.

Agreed....

btw I'm not the police; I don't care how you use hmailserver (as long as you aren't a spammer - then I care). I was trying to say that a small install with only a few accounts would be unlucky to experience the backup trying to handle a mail message that is in the delivery queue in the few seconds taken to do the backup. The mini dump is new, so maybe this has been happening a while and no-one ever noticed, because the error message doesn't say that backup stops and won't re-start.

Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

mattg wrote:
btw I'm not the police; I don't care how you use hmailserver (as long as you aren't a spammer - then I care). I was trying to say that a small install with only a few accounts would be unlucky to experience the backup trying to handle a mail message that is in the delivery queue in the few seconds taken to do the backup. The mini dump is new, so maybe this has been happening a while and no-one ever noticed, because the error message doesn't say that backup stops and won't re-start.

Oh phew (Believe me I'm not a spammer, I *&#$*( hate spam.)

That's what struck me too, if it's happening on my tiny little server... then this could be a potential serious issue and it can be hard to even tell it's failing unless you're really paying attention. When the backup job tries to run again in the crashed state, it just logs that it's already running.

If you need the dmp files I can get them to you.

(By the way, I did used to work on a commercial mail server from about 1996-2001. We bought it from another developer, it was a 16-bit application mode and we built it into a 32-bit service and the code was an utter mess. A lesson in the importance of due diligence.)