HMS Backup Script

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

HMS Backup Script

Post by tohare » 2016-08-21 07:53

Hello!

I have been trying to make the HMS Backup Script run unattended for several months and cannot seem to make it 100%. I use it with Task Scheduler to run every hour. The error I normally get is:

BACKUP ERROR: Backup or restore operation is already started

I do not have any spaces in the path names etc., put delays in the script to insure services run as expected, but no luck. It runs between 1x to 10x normally but then I get the error. I have searched here several times and cannot find anything very illuminating.

In TS I have all the correct options set such as "run with highest permissions", etc. Just for some reason sooner or later the script fails with above error.

I must reset the HMS service to get HMS backup to work again.

The script here is exaggerated but what I have tried lately.

Dim oApp
Dim iElapsed
Dim iStartTime
'
Set oApp = CreateObject("hMailServer.Application")
' Authenticate the client.
Call oApp.Authenticate ("Administrator", sAdminPassword)
'
oApp.Stop
'
iElapsed = 0
iStartTime = Now
Do While iElapsed < 5
iElapsed = DateDiff("s", iStartTime, Now)
Loop
'
Call oApp.BackupManager.StartBackup()
'
iElapsed = 0
iStartTime = Now
Do While iElapsed < 5
iElapsed = DateDiff("s", iStartTime, Now)
Loop
'
oApp.Start
'
iElapsed = 0
iStartTime = Now
Do While iElapsed < 3
iElapsed = DateDiff("s", iStartTime, Now)
Loop
'
Set oApp = Nothing
Thanks,
Thomas

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

Re: HMS Backup Script

Post by mattg » 2016-08-21 09:11

tohare wrote:I have been trying to make the HMS Backup Script run unattended for several months and cannot seem to make it 100%. I use it with Task Scheduler to run every hour. The error I normally get is:

BACKUP ERROR: Backup or restore operation is already started
That means that the previous backup is still running....

Mine typically takes a couple of hours backing up to a NAS using a custom script.
I robocopy the data directory to the NAS
I add the ini file and "\hMailserver\PHPWeAdmin\include_versioncheck.php" file
I backup MySQLdatabse and then zip the lot using 7Zip
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-21 10:26

Matt

Right, then how can I stop the previous Backup process? There is "plenty" of time between backups and obviously something hung for whatever reason.

Yes, I do a weekly MySQL Data dump as I trust the DB more than HMS with constant stream of attempted unauthorized logins, etc. MySQL is protected, HMS is exposed to the wild west.
Thanks,
Thomas

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

Re: HMS Backup Script

Post by mattg » 2016-08-21 12:19

tohare wrote: I use it with Task Scheduler to run every hour.
In Task scheduler advanced options there is an option to stop all previous instances of this task before commencing

You can also limit the amount of time by setting the task scheduler to stop it running after say 45 minutes
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-21 12:31

Matt

I did all of that and it either is not working or something else is going on. I set every switch I thought possible to make Backup work. Only thing that resets it is to manually reset the HMS service switch in "Services" in the Management Console.
Thanks,
Thomas

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

Re: HMS Backup Script

Post by mattg » 2016-08-21 13:09

What do the hmailserver backup logs say before you stop the service?

Are you sure that it takes less than an hour to do 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

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-21 13:18

Logs have nothing unusual. Even on a test server with limited emails, same results. Going to run Robocopy also as a safeguard. Thanks for idea.
Thanks,
Thomas

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-21 16:07

Untested, built from memory. It should run....

NOTE: There is no point in having the code wait for the backup to finish when you already have that trigger in hMailServer :mrgreen:

oApp.ServerState =
1: Stopped
2: Starting
3: Running
4: Stopping

NB: There is no check if hMailServer SERVICE has been stopped :!:

EDIT: It appears that "Option Explicit" have a bad influence on running this script for some reason - removed...

Code: Select all

****** RunBackup.vbs ******

   Dim oApp, EventLog, t

   ' Set up COM environment
   Set oApp = CreateObject("hMailServer.Application")
   Call oApp.Authenticate ("Administrator", sAdminPassword)   ' <== CHANGE !!
   Set EventLog = CreateObject("hMailServer.EventLog")

   If oApp.ServerState = 1 Then
      EventLog.Write("Backup already running or server has been stopped manually.")
   Else
      EventLog.Write("Stopping server for Backup")
      Call oApp.Stop

      EventLog.Write("Waiting for server to stop")
      Do While oApp.ServerState = 4
         EventLog.Write("Waiting...")
         t = Timer
         Do While ((Timer - t) < 5) Xor (Timer < t)
         Loop
      Loop
 
      EventLog.Write("Starting backup")
      Call oApp.BackupManager.StartBackup()
   End If

Code: Select all

****** EventHandlers.vbs ******

   Sub OnBackupFailed(sReason)
      Dim oApp
      ' Set up COM environment
      Set oApp = CreateObject("hMailServer.Application")
      Call oApp.Authenticate ("Administrator", sAdminPassword)   ' <== CHANGE !!
      EventLog.Write("Starting server AFTER backup FAILED! Error: " & sReason)
      Call oApp.Start
   End Sub

   Sub OnBackupCompleted()
      Dim oApp
      ' Set up COM environment
      Set oApp = CreateObject("hMailServer.Application")
      Call oApp.Authenticate ("Administrator", sAdminPassword)   ' <== CHANGE !!
      EventLog.Write("Starting server after backup COMPLETED.")
      Call oApp.Start
   End Sub
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

User avatar
jimimaseye
Moderator
Moderator
Posts: 8549
Joined: 2011-09-08 17:48

Re: HMS Backup Script

Post by jimimaseye » 2016-08-21 16:40

Thomas check the backup destination doesn't have a DATA folder in it. Better still ensure the backup destination is completely empty (and with full write permissions).

You get this message when a previous backup fails leaving ruminants in them.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-21 17:01

SorenR wrote:EDIT: It appears that "Option Explicit" have a bad influence on running this script for some reason - removed...
I think I messed up here... I inserted a statement before "Option Explicit" and that was the reason it failed...

Anyways...

Code: Select all

3004		"2016-08-21 16:29:00.615"	"Stopping server for Backup"
3004		"2016-08-21 16:29:01.412"	"Waiting for server to stop"
3004		"2016-08-21 16:29:01.412"	"Starting backup"
720		"2016-08-21 16:56:15.167"	"Starting server after backup COMPLETED."
:mrgreen:
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

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

Re: HMS Backup Script

Post by mattg » 2016-08-21 23:47

tohare wrote:Logs have nothing unusual.
There is a specific hMailserver backup log if you use the built in 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

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-22 04:22

Jimmy,

Backup Destination is a folder with the data as the name -- we keep 1 BU file for each day (folder) for 1 week. All that is in that folder is the BU file for each BU operation.

The NAS software backups every new entry as they are added to the NAS remote device.

We do several simultaneous archive operations (completely separate) as a preventative and the hope is we do not lose more than 1 hours worth of email (should 30 minutes or less) in case of a catastrophe.

We could do instantaneous backups but we may get severe data bloat if we do that.
Thanks,
Thomas

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-22 04:38

Soren,

Like I said, the script I had was "greatly exaggerated" to try to cover any "possible" problem. I have abandoned my script and running yours to see how that does. I really appreciate a great pointer in the right direction.
Thanks,
Thomas

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-22 05:53

OK, seems more stable after ~10x of testing. Once in a while the temp BU dir is not deleted but the next round seems to delete it. If it works fine in 24+ hours I will post the script here.

BTW, any reason why the Temp dir is not deleted? Just curious as it does not seem to be a problem.
Thanks,
Thomas

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-22 14:04

OK, I have documented an infinite loop in the code Soren posted. After more testing I will post new code.

Here is the error that caused the loop:

"Severity: 3 (Medium), Code: HM4203, Source: MySQLRecordset::Close, Description: An unknown error occurred while closing recordset."

In the Backup log I have:

4380 "2016-08-22 11:00:00.168" "Stopping server for Backup."
3144 "2016-08-22 11:00:00.231" "Stopping server for Backup."
3144 "2016-08-22 11:00:00.231" "Waiting for server to stop."
3144 "2016-08-22 11:00:00.231" "Waiting..."
3144 "2016-08-22 11:00:05.238" "Waiting..."
3144 "2016-08-22 11:00:10.246" "Waiting..."
... Infinite loop...
2972 "2016-08-22 11:14:56.591" "Waiting..."
2972 "2016-08-22 11:15:00.242" "Stopping server for Backup." <== Task Scheduler is set to retry on failure in 15 minutes.
2972 "2016-08-22 11:15:00.242" "Waiting for server to stop."
2972 "2016-08-22 11:15:00.242" "Waiting..."
2972 "2016-08-22 11:15:01.599" "Waiting..."
2972 "2016-08-22 11:15:05.249" "Waiting..."

Code that hangs on ServerState:

Do While oApp.ServerState = 4

My Fix to end infinite loop (I used "30" as that is the normal network default timeout):

iElapsed = 0
iStartTime = Now
Do While oApp.ServerState = 4 and iElapsed < 30
iElapsed = DateDiff("s", iStartTime, Now)

Will post final (?) code in ~24 hours. Good news is the backups seem to run well otherwise.
Thanks,
Thomas

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-22 14:33

Perhaps you should investigate WHY your server is taking so long to stop :idea:
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-23 09:38

OK, this has been working very well for a number of Backups. There is really no more problems with Backup. It is over commented for clarification.

' 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.
'
' Important to read server state.
' hStateStopped = 1, Server is stopped.
' hStateStarting = 2, Server is starting.
' hStateRunning = 3, Server is running.
' hStateStopping = 4, Server is stopping.
'
' BlowFish Hash of Admin Password.
Const sBlowFishPW = "b54084c9e4d33189"
' All vars declared here.
Dim oApp
Dim iStartTime, iElapsed, iStart, iTimer
' Create Application Object.
Set oApp = CreateObject("hMailServer.Application")
' Derypt BlowFish Encrypted PW.
sAdminPassword = oApp.Utilities.BlowfishDecrypt(sBlowFishPW)
' Authenticate the user.
Call oApp.Authenticate ("Administrator", sAdminPassword)
' Create EventLog Object.
Set oEventLog = CreateObject("hMailServer.EventLog")
' Write a beginning block to log file.
oEventLog.Write("v--STARTING Backup Operation.--v")
' Start actual code to do Backup Operation.
' If server already stopped we have a problem.
If oApp.ServerState = 1 Then
oEventLog.Write("*** Backup already running or server has been stopped manually. ***")
' A problem exists, let's see if we can manually clear the problem.
oEventLog.Write("Resetting server.")
Call oApp.Stop
Else
' Stop the server service so we can do the Backup cleanly.
oEventLog.Write("Stopping server for Backup.")
Call oApp.Stop
' Now we monitor the service to be sure it stopped.
oEventLog.Write("Waiting for server to stop.")
' Start main loop and prepare for actual Backup.
' This loop is to help insure server service is actually stopped.
iElapsed = 0
iStartTime = Now
' Loop while Server State is Stopping and Elapsed Time is < 30 seconds.
Do While oApp.ServerState = 4 and iElapsed < 30
oEventLog.Write("Waiting...")
' Set the Timer Start Time var to Seconds Since Midnight (SSM) value.
iStartTime = Timer
' A local loop to insure log file is not flooded.
iTimer = 0
iStart = Now
' Sub-Loop to idle while Server is Stopping.
' 30/3 = 10 iterations/cycle log entries max written to log file.
Do While iTimer < 3 and oApp.ServerState = 4
iTimer = DateDiff("s", iStart, Now)
'
Loop
' Set main timer var for main loop.
iElapsed = DateDiff("s", iStartTime, Now)
'
Loop
' Check for Stopped Server.
If oApp.ServerState = 1 Then
oEventLog.Write("Server Stopped.")
' We assume all is ready so do the actual Backup Operation.
oEventLog.Write("Starting backup.")
Call oApp.BackupManager.StartBackup()
oEventLog.Write("Backup COMPLETE.")
Else
oEventLog.Write("*** Server did not stop, CANNOT BACKUP. ***")
End If
End If
' Check for Stopped Server.
If oApp.ServerState = 1 Then
' Clean up and re-start server service.
oEventLog.Write("Starting Server.")
Call oApp.Start
End If
' Check Server State and write it to the Backup Log File.
If oApp.ServerState = 3 Then
oEventLog.Write("Server Started.")
Else
oEventLog.Write("*** Server is in an UNDETERMINED STATE.***")
End If
' Write an ending block to log file.
oEventLog.Write("^--ENDING Backup Operation.--^")
'
' EoF: StartBackup.Vbs.
Thanks,
Thomas

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-23 13:52

One major flaw with your script...

Code: Select all

      ' We assume all is ready so do the actual Backup Operation.
      oEventLog.Write("Starting backup.")
      Call oApp.BackupManager.StartBackup()
      oEventLog.Write("Backup COMPLETE.")
"Call oApp.BackupManager.StartBackup()" does NOT wait for the backup to complete :!:

Why do you think I use "Sub OnBackupCompleted()" from EventHandlers.vbs in my example ??

PS.. What's with the Blowfish encryption ??
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-24 11:49

Soren,

Whoops! I am used to other environments and spaced out. Will change that and I appreciate your feedback.

The BlowFish thingy is because I got paranoid of having the HMS Admin PW in plain text in a text file. Seemed like a security issue so I encrypted it, then copied it into StartBackup.Vbs.

Back to the editor and apply what I have learned.
Thanks,
Thomas

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-24 12:02

Several issues...

I had a "file not found" error during a backup and it caused HMS to stop SMTP services (minimum). The file was in MySQL and on disk. It may have been in the wrong place. I believe it should have been in a different Domain and was a week or two old (and "just" showed up today). Just trying to figure out why a MySQL (data) error caused SMTP to be unreachable.

Also, learned the "Process already started" error message was because the "WScript.Exe" program "hung" in memory. I had about a dozen instances in memory and had to manually clear them out. I ended up running a command in a BAT file in Task Scheduler at a time when I know the Backup process would be completed. Just as a "better safe than sorry" thingy. Command I use is:

TaskKill /IM WScript.Exe /f

Anyone have a cleaner solution? Or better yet, know why it hangs? 90%+ plus of the time there is not a problem with WScript.Exe, just a one time during 24+ hour period.
Thanks,
Thomas

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-24 12:51

You may have put yourself in that position with your previous script...

Roadmap:

1: Script to start backup (remember it is STATELESS)
2: Resume backup handling in EventHandlers.vbs by using "Sub OnBackupFailed(sReason)" and "Sub OnBackupCompleted()"

I looked thru your last script and you are overcomplicating things. AND... You can leave the password in the script as cleartext. If some hacker manages to get access to your server you are doomed regardless :mrgreen:

Now, handling errors may be a challenge since the scripted backup is stateless, so if you already started the backup and try to start it a second time, it will fail and trigger "Sub OnBackupFailed(sReason)" - later, when the initial backup completes, it will trigger "Sub OnBackupCompleted()"...

This is work in progress...
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-25 00:52

Code: Select all

Option Explicit

   '
   ' CheckState.vbs Version 0.9
   '
   Dim FSO, oApp, EventLog, sAdminPassword : sAdminPassword = "MyVerySecretPassword"

   Set FSO = CreateObject("Scripting.FileSystemObject")

   Set oApp = CreateObject("hMailServer.Application")
   Call oApp.Authenticate ("Administrator", sAdminPassword)
   Set EventLog = CreateObject("hMailServer.EventLog")

   If oApp.ServerState = 1 Then
      If (FSO.FolderExists(oApp.Settings.Backup.Destination & "\DataBackup")) Then
         EventLog.Write("Server is currently doing backup...")
      Else
         EventLog.Write("Server was stopped for no reason, starting...")
         Call oApp.Start      
      End If
   End If
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-25 04:51

Soren, et. al.,

I am supposed to be notified when a reply is given here but lately it does not work. Maybe you are Anonymous? ;-) So, sorry for the delay.

I will be looking at what you have just above soon. And I "really" appreciate the feedback.

I encrypted the HMS PW not so much for hackers, but for any legitimate user on the system. I am sure they are OK, but if they do not have the PW then they cannot cause problems. IOW, I can eliminate them from suspicion if I see something not quite right in the HMS arena. I even tell people to "not" give me info so I can remain out of suspicion if something odd happens. So encrypted PW is to protect the guilty -- uh, I mean innocent! ;-)

The "big" problem right now is the procedure below in EventHandlers.Vbs script does "not" appear to be firing -- at all!!! The same code runs fine in StartBackup.Vbs. That is the correct name, in the same dir as StartBackup.Vbs, and has two subroutines named: OnBackupCompleted(), OnBackupFailed(sReason).

Sub OnBackupCompleted()
' BlowFish Hash of Admin Password.
' All vars declared here.
Dim oApp, oEventLog
Dim sBlowFishPW, sAdminPassword
sBlowFishPW = "sg498jd92u8dh"
' Create Application Object.
Set oApp = CreateObject("hMailServer.Application")
' Derypt BlowFish Encrypted PW.
sAdminPassword = oApp.Utilities.BlowfishDecrypt(sBlowFishPW)
' Authenticate the user.
Call oApp.Authenticate ("Administrator", sAdminPassword)
' Create EventLog Object.
Set oEventLog = CreateObject("hMailServer.EventLog")
oEventLog.Write("Sub OnBackupCompleted() firing.")

I am having problems with BU but I highly suspect it is because the code above is not firing -- none of it!

The only suspect I can think of is in the INI file. The paths listed are correct but do not have "quote marks" around the actual paths. Which is not so suspect as the StartBackup.Vbs (in same dir) fires just fine.

I suspect either a very dumb mistake I am overlooking or for some reason HMS is not firing the code to execute code contained in EventHandlers.Vbs. One SUB seems to fire OK but second (Sub OnBackupCompleted()) does not.

Any ideas?

Soren -- Yes the code is overdone but I posted a disclaimer. ;-) I said it was "exaggerated" which means I know it is over done. I spent many years writing code and tend to make it as "bulletproof" as possible. And over commented is usually less problems with other coders than under commented.
Last edited by tohare on 2016-08-25 04:59, edited 1 time in total.
Thanks,
Thomas

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-25 04:56

OK, there is a rouge record/email again (seems to happen 1x a day) and blowing BU operations out of the water. Yes, it may be caused by the current scripts still not 100% but I feel it is off that a misplaced record/email causes so much havoc in HMS.

"ERROR" 6280 "2016-08-24 17:00:01.128" "Severity: 2 (High), Code: HM4208, Source: ExceptionHandler::Run, Description: An error occured while executing 'Task-BackupTask', Error code: 80, Message: boost::filesystem::copy_file: The file exists: "C:\Program Files (x86)\hMailServer\Data\RedTile.Com\Thomas\17\{17C83931-A86C-46B3-A843-62D261618514}.eml", "D:\Files\hMailserver\Mail_Server_BU\160824\DataBackup\RedTile.Com\Thomas\17\{17C83931-A86C-46B3-A843-62D261618514}.eml""
Thanks,
Thomas

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-25 16:21

tohare wrote:OK, there is a rouge record/email again (seems to happen 1x a day) and blowing BU operations out of the water. Yes, it may be caused by the current scripts still not 100% but I feel it is off that a misplaced record/email causes so much havoc in HMS.

"ERROR" 6280 "2016-08-24 17:00:01.128" "Severity: 2 (High), Code: HM4208, Source: ExceptionHandler::Run, Description: An error occured while executing 'Task-BackupTask', Error code: 80, Message: boost::filesystem::copy_file: The file exists: "C:\Program Files (x86)\hMailServer\Data\RedTile.Com\Thomas\17\{17C83931-A86C-46B3-A843-62D261618514}.eml", "D:\Files\hMailserver\Mail_Server_BU\160824\DataBackup\RedTile.Com\Thomas\17\{17C83931-A86C-46B3-A843-62D261618514}.eml""
Hmm... "D:\Files\hMailserver\Mail_Server_BU\160824" is your backup path, hMailServer append "\DataBackup" and this is the directory I search for in my CheckState.vbs based on the assumption that once the backup is finished and compressed, hMailServer will delete this directory again.

But it will only work if you have "compression" selected.
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-27 11:44

Soren,

Compression is set ON and creates the temp BU dir as expected. I will look at your CheckState.Vbs.

I had to disable the scheduled backup as the other problem -- The after backup SUB -- is not firing which can cause problems. The BU is not reliable now and has taken HMS offline at least 2x because the BU cleanup code will not fire.
Thanks,
Thomas

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-30 10:33

Still trying to get the EventHandlers.OnBackupCompleted() SUB to fire. I had to disable it until I can figure out why the cleanup is not firing -- which is causing HMS to fail.

The first SUB OnBackupFailed(sReason) fires just fine. Here is the code:

Sub OnBackupCompleted()
' BlowFish Hash of Admin Password.
' All vars declared here.
Dim oApp, oEventLog
Dim sBlowFishPW, sAdminPassword
sBlowFishPW = "6f4015a66b98e17c65cd2fbed19f6b74"
' Create Application Object.
Set oApp = CreateObject("hMailServer.Application")
' Derypt BlowFish Encrypted PW.
sAdminPassword = oApp.Utilities.BlowfishDecrypt(sBlowFishPW)
' Authenticate the user.
Call oApp.Authenticate ("Administrator", sAdminPassword)
' Create EventLog Object.
Set oEventLog = CreateObject("hMailServer.EventLog")
oEventLog.Write("Sub OnBackupCompleted() firing.")
' Check for Stopped Server.
If oApp.ServerState = 1 Then
oEventLog.Write("Backup COMPLETE.")
' Clean up and re-start server service.
oEventLog.Write("Starting Server.")
Call oApp.Start
Else
' Check for Stopped Server.
oEventLog.Write("*** Server is in an UNDETERMINED STATE.***")
End If
' Check Server State and write it to the Backup Log File.
If oApp.ServerState = 3 Then
oEventLog.Write("Server Started.")
Else
oEventLog.Write("*** Server is in an UNDETERMINED STATE.***")
End If
' Write an ending block to log file.
oEventLog.Write("^--ENDING Backup Operation.--^")
End Sub
Thanks,
Thomas

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-30 14:02

tohare wrote:Still trying to get the EventHandlers.OnBackupCompleted() SUB to fire. I had to disable it until I can figure out why the cleanup is not firing -- which is causing HMS to fail.

The first SUB OnBackupFailed(sReason) fires just fine.
Why disable it?

If OnBackupCompleted() does not fire and OnBackupFailed(sReason) fire OK then you have a problem with your backup.

Best way to monitor is if the backup folder hMailServer create (DataBackup) is removed after backup completes.

A couple of indicators can be...
- Compression must be selected, otherwise the folder stays until manually deleted.
- Permissions allow hMailServer to create, overwrite and delete files/folders.
- hMailServer crash...

On my server (Win 2003 Server, Core2 Duo 2.33 MHz, 2 GB RAM) backup of 21.000 emails (2.4 GB) take about 28 minutes.
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-31 00:21

Soren,

This is what has me confused. I cannot get a good log as to what actually happens during backup, especially with Task Scheduler. I have the HMS logs but they just have an over view of the operation.

The BU can run 3 or 6 times fine then WHAM! It will fail due to prior service still running or temp folder still there. I just ran BU and the temp dir still remained but on 1 message was in the 1 account folder (was not deleted). It was an old message also.

But the biggest problem is OnBackupCompleted() not firing at all, the Temp BU dir deleting/not deleting randomly, no way to see the process to see what happens. As stated, the HMS logs give an overview but low level operations (especially via Task Scheduler) cannot be viewed.

What user permissions do you use for your BU folders?

The system uses a Citrix XenCenter 6.5 VM box with a 10k RPM WD 1 terabyte drive, 4 - 1 Gbps NICs, liquid cooled and pictured:
Clipboard01.jpg
Thanks,
Thomas

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-31 01:05

tohare wrote:Soren,

This is what has me confused. I cannot get a good log as to what actually happens during backup, especially with Task Scheduler. I have the HMS logs but they just have an over view of the operation.

The BU can run 3 or 6 times fine then WHAM! It will fail due to prior service still running or temp folder still there. I just ran BU and the temp dir still remained but on 1 message was in the 1 account folder (was not deleted). It was an old message also.

But the biggest problem is OnBackupCompleted() not firing at all, the Temp BU dir deleting/not deleting randomly, no way to see the process to see what happens. As stated, the HMS logs give an overview but low level operations (especially via Task Scheduler) cannot be viewed.

What user permissions do you use for your BU folders?

The system uses a Citrix XenCenter 6.5 VM box with a 10k RPM WD 1 terabyte drive, 4 - 1 Gbps NICs, liquid cooled and pictured:
Clipboard01.jpg
My hMailServer sits on top of a cubbord next to my central heating, fuse box and home automation (IHC) so physically protected from intruders and it's only doing mail - webmail is on a 'Nix box sitting next to it. So... It's got admin rights. :mrgreen:

I remember some time back I got some weird results including some IOCP errors using "NT AUTHORITY\SYSTEM" so I changed all (ClamAV, SpamAssassin & hMailServer) jobs to <servername>/ADMINISTRATOR.
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-08-31 06:23

I set the permissions on the Scripts dir and the BU file dir to "EVERYONE" and enabled ALL permissions. I ran 6 test runs from the Task Scheduler dialog. 2 runs left the temp BU dir with only 1 message in them (different emails). 1 left what appeared as all emails. 3 ran fine and temp dir was deleted.

On all the runs the "Sub OnBackupCompleted()" never appeared to fire.

I gather from this test permissions is not the problem with my install. Basically same result I have consistently had.
Thanks,
Thomas

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

Re: HMS Backup Script

Post by mattg » 2016-08-31 14:11

I think that OnBackupCompleted will ONLY fire if the inbuilt backup is triggered
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
SorenR
Senior user
Senior user
Posts: 3567
Joined: 2006-08-21 15:38
Location: Denmark

Re: HMS Backup Script

Post by SorenR » 2016-08-31 15:33

mattg wrote:I think that OnBackupCompleted will ONLY fire if the inbuilt backup is triggered
You guys really need to start reading from the top and not just shoot off answers.
SørenR.

“With age comes wisdom, but sometimes age comes alone.”
- Oscar Wilde

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

Re: HMS Backup Script

Post by mattg » 2016-09-01 00:50

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

tohare
Normal user
Normal user
Posts: 181
Joined: 2014-12-07 13:35
Location: Florida!

Re: HMS Backup Script

Post by tohare » 2016-09-02 12:25

Well come to find out that "neither" of the SUBS in EventHandlers.Vbs is firing. I am running latest version of HMS 5.6.5. I have set "full" permissions to "everyone". If anyone can confirm that VBS is firing and maybe any additional info for the VBS file that will be appreciated.
Thanks,
Thomas

Post Reply