HOW TO: Ready-To-Go Backup and Cleardown script
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I found a simple service notification powershell script. I commented out the bit with attempting to restart the service. Email bits are commented out too as I'm using http get to trigger the sms message. It works. Run at startup from windows scheduler.
Last edited by mattg on 2019-02-20 02:48, edited 1 time in total.
Reason: code removed as per poster's request. Modified code below.
Reason: code removed as per poster's request. Modified code below.
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I get these shutdown issues almost every time I try and 'Pause' hmailserver or stop the service
That the main reason that I don't shutdown or pause to run backups, I just run backups live.
I suspect that it is because some SMTP connections are not closed properly.
RvdH shared some code saved as disconnect.exe >> viewtopic.php?f=20&t=32739&p=206184#p206167
I've used it a bit in my eventhandlers.vbs but I haven't been logging the use.
I'll do that for a while and see if that helps me...
That the main reason that I don't shutdown or pause to run backups, I just run backups live.
I suspect that it is because some SMTP connections are not closed properly.
RvdH shared some code saved as disconnect.exe >> viewtopic.php?f=20&t=32739&p=206184#p206167
I've used it a bit in my eventhandlers.vbs but I haven't been logging the use.
I'll do that for a while and see if that helps me...
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: HOW TO: Ready-To-Go Backup and Cleardown script
My issue is that I run hMailserver in a HyperV VM, and HyperV doesn't allow access the USB ports of the bare metal server. I do have a network device with a SIM card, a Netgear LTE Modem LB2120, but I am yet to work out how to send SMS from a network attached device via a script. I can do it from the GUI of the device, so I'm sure it will be possible...palinka wrote: ↑2019-02-18 01:22I bought the cheapest usb modem i could find on Amazon. $10 huawei e352. Getting gammu to work was kind of a pain since the project is kind of old and windows was a side thought. You'll have many more options on linux. Or you can jump through hoops like me.
You can use an old mobile phone too. I considered that too (free) but i tried it with an android app a long time ago and it didn't work well and caused the phone to crash after a day or 2. I think it's better to have computer hardware.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Http getmattg wrote: ↑2019-02-19 01:26My issue is that I run hMailserver in a HyperV VM, and HyperV doesn't allow access the USB ports of the bare metal server. I do have a network device with a SIM card, a Netgear LTE Modem LB2120, but I am yet to work out how to send SMS from a network attached device via a script. I can do it from the GUI of the device, so I'm sure it will be possible...palinka wrote: ↑2019-02-18 01:22I bought the cheapest usb modem i could find on Amazon. $10 huawei e352. Getting gammu to work was kind of a pain since the project is kind of old and windows was a side thought. You'll have many more options on linux. Or you can jump through hoops like me.
You can use an old mobile phone too. I considered that too (free) but i tried it with an android app a long time ago and it didn't work well and caused the phone to crash after a day or 2. I think it's better to have computer hardware.
https: //yoursmsgateway.tld/index.php/plugin/rest_api/send_sms?phoneNumber=1234567890&message=whatever message you want. Including punctuation and spaces! Yay!
I put a space after https: so it wouldn't break up the url that has spaces in it in the message section.
I'm using kalkun as the front end for gammu. Gammu has a service ans kalkun is a php web app. But like i said, they're both old and there are better options for linux, but they do basically the same thing.
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I worked out a way easier powershell script for checking service status. This is notify only. The other one i posted doesn't work. I jumped the gun on that one. This one is thoroughly tested. Maybe a mod can delete the other one.
Run from task scheduler. I set mine to run every hour so i don't get spammed if something breaks while I'm sleeping.
Also, this only works on one service, so i made one for each of the services i want to monitor and put them all into a single task in scheduler.
Delete the sms bit if you don't use it or use the api url from your own gateway. By the way, this throws an error because even though it works to post the message, it's a get command that is looking for a response but my gateway gives a 404 as response. Still working that out. Doesn't affect operation, but the run status in scheduler is 0x1 because of the 404 error. Need to figure out either straight post or ignore error in powershell.
It took me a while to figure this one out. I don't know why, but "exit" in the if statement didn't work. Finally i ran across something on the web and changed it to "exit 1" and it worked straight off. Weird.
Run from task scheduler. I set mine to run every hour so i don't get spammed if something breaks while I'm sleeping.
Also, this only works on one service, so i made one for each of the services i want to monitor and put them all into a single task in scheduler.
Delete the sms bit if you don't use it or use the api url from your own gateway. By the way, this throws an error because even though it works to post the message, it's a get command that is looking for a response but my gateway gives a 404 as response. Still working that out. Doesn't affect operation, but the run status in scheduler is 0x1 because of the 404 error. Need to figure out either straight post or ignore error in powershell.
Code: Select all
if((get-service hMailServer).Status -eq 'Running'){exit 1}
else {
# Send the problem services via email
$EmailFrom = "notify@domain.net"
$EmailTo = "admin@domain.com"
$Subject = "Windows Service Failure"
$Body = "ATTENTION! Server reporting that the hMailServer service is not running. Check status NOW."
$SMTPServer = "localhost"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $false
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("notify@domain.net", "SecretPassword");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
# Send the problem services via SMS
$uri = "https://mysmsgateway/sms/index.php/plugin/rest_api/send_sms?phoneNumber=1234567890&message=ATTENTION! Server reporting that the hMailServer service is not running. Check status NOW."
$response = Invoke-RestMethod -Uri $uri
}
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I reread your post and looked up the device. That's a hotspot modem, correct? Yeah I'm not sure if that could work. All the gateway software I've seen use at commands which require the device be connected by cable. Mine is usb and the driver fakes the serial port for access. But the usb ones are cheap if you want to go that route. Or you could try using an old phone connected by usb.
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Some of us have NBN in Australia, which stands for National Broadband Network.
I have FTTP = Fibre to the premises
I have a fibre optic cable running to a NBN router at my premises, which offers a LAN type connector to my own router/modem commonly supplied by ISPs. This is much like cable in many regards.
Problem is that it can drop out for what ever reason.
My LTE modem fits between my router/firewall/modem and the NBN router, and offers failover to 4G via a SIM Card when the NBN connection is down. I can't get static IP on 4G, so this is only for outgoing internet traffic, not incoming traffic.
And yeah, I haven't found much on how I can achieve a message via http get, but that would be the plan
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation
https://www.hmailserver.com/documentation
Re: HOW TO: Ready-To-Go Backup and Cleardown script
If you just want to test, there are a bunch of android gateway apps that connect via wifi. The ones i tried were not very stable. Or it could have been my phone.mattg wrote: ↑2019-02-20 02:56Some of us have NBN in Australia, which stands for National Broadband Network.
I have FTTP = Fibre to the premises
I have a fibre optic cable running to a NBN router at my premises, which offers a LAN type connector to my own router/modem commonly supplied by ISPs. This is much like cable in many regards.
Problem is that it can drop out for what ever reason.
My LTE modem fits between my router/firewall/modem and the NBN router, and offers failover to 4G via a SIM Card when the NBN connection is down. I can't get static IP on 4G, so this is only for outgoing internet traffic, not incoming traffic.
And yeah, I haven't found much on how I can achieve a message via http get, but that would be the plan
For your backup internet, you could assign a backup mx record to a dynamic domain that the lte router updates. Most of these devices come with a few ddns providers built in. Shoot, you could leave it running all the time like that and never skip a beat.
I have fibre too. It's always worked even when the power goes out. I have a ups attached to the fibre hardware, all my networking gear and my server. I get about 40 minutes which is usually enough time for the power to come back on. I only remember the fibre going down once and that was very early on a Sunday morning. I think they may have been upgrading hardware.
Re: HOW TO: Ready-To-Go Backup and Cleardown script
We're waaaay off topic here but i just had to share this. I run apcupsd to monitor my ups. I had it set up to email me via my cell carrier's sms gateway so i would get text messages for power events. I already changed the scripts to use my personal sms gateway. After writing the last post and thinking about the power situation, i looked to see if the utility here accepts text messages to report outages and they do. So i registered my gateway's cell number with the utility and now when the power goes out, my server will automatically send the utility an outage text. I set it up with a 2 minute delay so it wouldn't fire on momentary outages, which are common here. Hehe.. i don't even have to be home to know about it, or if it happens while I'm sleeping they still get notified. I know my neighbors will appreciate that too.
Also, one of the reasons i wanted an sms gateway is because sometimes my email > carrier gateway messages would get trapped in the carrier's sms spam filter. No matter how i experimented with "unspammy" messages, some still got trapped and i couldn't figure out why. It was random. So this solves that problem.
Also, one of the reasons i wanted an sms gateway is because sometimes my email > carrier gateway messages would get trapped in the carrier's sms spam filter. No matter how i experimented with "unspammy" messages, some still got trapped and i couldn't figure out why. It was random. So this solves that problem.
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Anyway, back on topic. It happened again last night. This time I paid a little closer attention before rebooting.
Service status was "running". My notification script didn't work because it tests "not running".
Log shows the same shutdown errors:
Code: Select all
"DEBUG" 2760 "2019-02-23 23:58:11.869" "Still 1 remaining threads in queue Server queue. First task: IOService"
"DEBUG" 9524 "2019-02-23 23:58:11.900" "Still 1 remaining threads in queue IOCPQueue. First task: IOCPQueueWorkerTask"
"DEBUG" 2760 "2019-02-23 23:58:12.135" "Given up waiting for threads to join in queue Server queue."
"DEBUG" 2760 "2019-02-23 23:58:12.135" "WorkQueueManager::RemoveQueue - Stopped Server queue"
"DEBUG" 2760 "2019-02-23 23:58:12.135" "WorkQueueManager::RemoveQueue - Erased Server queue"
"DEBUG" 2760 "2019-02-23 23:58:12.135" "Destructing work queue Server queue"
"DEBUG" 9524 "2019-02-23 23:58:12.166" "Given up waiting for threads to join in queue IOCPQueue."
"DEBUG" 9524 "2019-02-23 23:58:12.166" "WorkQueueManager::RemoveQueue - Stopped IOCPQueue"
"DEBUG" 9524 "2019-02-23 23:58:12.166" "WorkQueueManager::RemoveQueue - Erased IOCPQueue"
"DEBUG" 9524 "2019-02-23 23:58:12.166" "IOService::Stop() - Complete"
"DEBUG" 9524 "2019-02-23 23:58:12.166" "Destructing work queue IOCPQueue"
Something else - maybe just a coincidence, but this seems to always happen on a Saturday night. At first I thought maybe it had something to do with me fooling around with the system on Saturdays (the time I usually do), but yesterday I did not install anything, reboot or anything like that. Weird.
Re: HOW TO: Ready-To-Go Backup and Cleardown script
The issue seems to be oapp.stop insofar as it pauses hmailserver, not stop hmailserver service. Therefore, the way I tried to detect problems didn't work as I was using service status. So I figured I would need another method - telnet would tell me if things are not working. After some goolaging and experimentation, I came up with this powershell script.
To be safe that there's not some temporary issue, it checks a full 3 times before attempting to restart hmailserver service. The script is run on the same machine as hmailserver and there's no chance for temporary network issues, but I'm playing it safe for circumstances I can't even think of at the moment.
If powershell cannot connect by telnet after 3 tries, it will restart the service and send me a text letting me know. Then it will wait 60 seconds and check service status again. If the service is not running, I'll get another message telling me.
If powershell can't connect either once or twice, but does successfully connect on the second or third try, it will finish and exit without attempting to restart hmailserver.
To be safe that there's not some temporary issue, it checks a full 3 times before attempting to restart hmailserver service. The script is run on the same machine as hmailserver and there's no chance for temporary network issues, but I'm playing it safe for circumstances I can't even think of at the moment.
If powershell cannot connect by telnet after 3 tries, it will restart the service and send me a text letting me know. Then it will wait 60 seconds and check service status again. If the service is not running, I'll get another message telling me.
If powershell can't connect either once or twice, but does successfully connect on the second or third try, it will finish and exit without attempting to restart hmailserver.
Code: Select all
$ErrorActionPreference = 'silentlycontinue'
$remotehost = "localhost"
$port = 25
$ServiceName = 'hMailServer'
$socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port)
if($socket -eq $null) {
Start-Sleep -seconds 300
$socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port)
if($socket -eq $null) {
Start-Sleep -seconds 300
$socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port)
if($socket -eq $null) {
Restart-Service $ServiceName
$uri = "https://smsgateway/index.php/plugin/rest_api/send_sms?phoneNumber=1234567890&message=ATTENTION! hMailServer service is being RESTARTED due to a fault. Check status NOW."
$response = Invoke-RestMethod -Uri $uri
Start-Sleep -seconds 60
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'Running')
{
$uri = "https://smsgateway/index.php/plugin/rest_api/send_sms?phoneNumber=1234567890&message=ATTENTION! BrianServer reporting that the hMailServer service is not running. Check status NOW."
$response = Invoke-RestMethod -Uri $uri
}
}
}
}
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Hot damn! It worked. Not only that, but the backup script, which got hung up on oapp.stop, picked up when hmailserver service actually stopped and completed without errors.
I have my backup script set to run at 11:58pm. My telnet check script runs at 12:15. Note: it's supposed to wait 5 minutes between tries but i had it set to 10 seconds when i was testing it and forgot to change it back. Just fixed that. You'll see that in the log timestamps. The reason for the two 5 minute waits is just in case hmailserver is still running the backup, or other momentary communication errors.
Checking communication turned out to be a good idea because when it hangs like this, the service status is still "running" so checking service status won't do anything.
Real life test: PASS
I have my backup script set to run at 11:58pm. My telnet check script runs at 12:15. Note: it's supposed to wait 5 minutes between tries but i had it set to 10 seconds when i was testing it and forgot to change it back. Just fixed that. You'll see that in the log timestamps. The reason for the two 5 minute waits is just in case hmailserver is still running the backup, or other momentary communication errors.
Checking communication turned out to be a good idea because when it hangs like this, the service status is still "running" so checking service status won't do anything.
Real life test: PASS
Code: Select all
Backup Start: Wed 03/06/2019 23:58:01.18
HMS Server Start Time: 2019-03-05 23:58:36
HMS Daily Spam Reject count: 16
HMS Daily Viruses Removed count: 10
0:15:29.94 Stopping Hmailserver service...
The hMailServer service was stopped successfully.
Ok!
0:15:30.75 Stopping Spamassassin service...
..
The spamassassin service was stopped successfully.
~~~~SNIP~~~~
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Effectively your oapp.stop process is erroring/ freezing. By restarting the service your backup script then got control of the service (which is now running again) to stop it and continue. This is effectively the same as not having the oAp.stop in the first place.
[Entered by mobile. Excuse my spelling.]
[Entered by mobile. Excuse my spelling.]
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
The main reason its there is because the number of "hangs" was worse before I put it in. But it certainly can't hurt removing it, which I'll do tonight and see how it goes.jimimaseye wrote: ↑2019-03-07 15:08Effectively your oapp.stop process is erroring/ freezing. By restarting the service your backup script then got control of the service (which is now running again) to stop it and continue. This is effectively the same as not having the oAp.stop in the first place.
[Entered by mobile. Excuse my spelling.]
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I looked back in this thread and found the reason i added oapp.stop.
https://hmailserver.com/forum/viewtopic ... 60#p206367
In retrospect, it appears better to leave it in. Without it, the backup script fails. With it included, plus with my telnet monitor script, the service gets restarted and the backup continues successfully.
https://hmailserver.com/forum/viewtopic ... 60#p206367
In retrospect, it appears better to leave it in. Without it, the backup script fails. With it included, plus with my telnet monitor script, the service gets restarted and the backup continues successfully.
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
So attempting to stop the service times out at 30000 milliseconds. Probably for the same reason the oApp.stop doesnt work (whatever that is). So you issue another NET STOP and net start (to then go on and issue a net stop).
OR....
Try removing the oApp.stop and changing the initial script to:
As you have seen that a 2nd attempt to stop seems to work then the above should more than suffice.
OR....
Try removing the oApp.stop and changing the initial script to:
Code: Select all
:1st
:maildata
echo %time% Stopping Hmailserver service...>> %BackLog%&net stop hmailserver >> %BackLog%
set FailedHmailservice=Ok
set bold=%noBold%&set fontcolor=%fontBlack%
if errorlevel 1 echo %time% Stopping Hmailserver service (2nd try)...>> %BackLog%&net stop hmailserver >> %BackLog%
if errorlevel 1 echo %time% Stopping Hmailserver service (3rd try)...>> %BackLog%&net stop hmailserver >> %BackLog%
if errorlevel 1 set Failed=true&set FailedHmailservice=Failed to stop. Backup of emails not performed!&set bold=b&set fontcolor=%colorfill%
echo %FailedHmailservice%! >> %BackLog%
echo ^<tr^>^<td^>^<%fontcolor%^>^<%bold%^>Hmailserver service shutdown:^</td^>^<td^>^<%fontcolor%^>^<%bold%^>%FailedHmailservice%^</td^>^</tr^> >>%outf%
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I was actually thinking about that but i wasn't sure if the error checking resolves back to the first net stop command or if it would work sequentially the way you did it. I guess that answers my question and also simplifies things greatly. Thanks!jimimaseye wrote: ↑2019-03-08 10:08So attempting to stop the service times out at 30000 milliseconds. Probably for the same reason the oApp.stop doesnt work (whatever that is). So you issue another NET STOP and net start (to then go on and issue a net stop).
OR....
Try removing the oApp.stop and changing the initial script to:As you have seen that a 2nd attempt to stop seems to work then the above should more than suffice.Code: Select all
:1st :maildata echo %time% Stopping Hmailserver service...>> %BackLog%&net stop hmailserver >> %BackLog% set FailedHmailservice=Ok set bold=%noBold%&set fontcolor=%fontBlack% if errorlevel 1 echo %time% Stopping Hmailserver service (2nd try)...>> %BackLog%&net stop hmailserver >> %BackLog% if errorlevel 1 echo %time% Stopping Hmailserver service (3rd try)...>> %BackLog%&net stop hmailserver >> %BackLog% if errorlevel 1 set Failed=true&set FailedHmailservice=Failed to stop. Backup of emails not performed!&set bold=b&set fontcolor=%colorfill% echo %FailedHmailservice%! >> %BackLog% echo ^<tr^>^<td^>^<%fontcolor%^>^<%bold%^>Hmailserver service shutdown:^</td^>^<td^>^<%fontcolor%^>^<%bold%^>%FailedHmailservice%^</td^>^</tr^> >>%outf%
Maybe you should add this to the OP.
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Woke up to this today:
I'm stumped. There's 1 minute 8 seconds between first and second attempt but only 3 seconds between 2nd and 3rd.
Code: Select all
Backup Start: Tue 03/26/2019 23:58:01.14
HMS Server Start Time: 2019-03-25 23:58:38
HMS Daily Spam Reject count: 19
HMS Daily Viruses Removed count: 12
23:58:01.23 Stopping Hmailserver service...
23:59:01.31 Stopping Hmailserver service (2nd try)...
23:59:01.34 Stopping Hmailserver service (3rd try)...
Failed to stop. Backup of emails not performed!!
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Not 3 seconds but 3 tenths between 2nd and 3rd.
Go to services, properties (on hmailserver service), advanced and check the "what to do" options on failures. Just tinker.
[Entered by mobile. Excuse my spelling.]
Go to services, properties (on hmailserver service), advanced and check the "what to do" options on failures. Just tinker.
[Entered by mobile. Excuse my spelling.]
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Hmmm... i overlooked that. At least i got the minute part right.
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Next time you have a failure to stop, check out this directory (and look at the contents): C:\ProgramData\Microsoft\Windows\WER\ReportQueue
You might find it useful. (Or you might not).
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I will. Thanks. I'll update what i find.
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I had a service stop failure yesterday (very rare for me). That folder had dump files and a readable xml. Perhaps useful to someone.
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I've been super busy lately. Finally had a chance to look. …/ReportQueue and …/Temp folders were empty. …/ReportArchive had lots of entries but none related to hmailserver except one for hmailadmin.exe. Tons of apache crashes. Looks like several per day going back to Feb 8. Does this folder auto-clear? I'm wondering if this has been a regular thing for years and I never knew.
Anyway, next time it happens I'll have a look as soon as possible as well as windows event log.
Anyway, next time it happens I'll have a look as soon as possible as well as windows event log.
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Another great tutorial! Thanks to everyone, who is helping out beginners like me, it helps a lot and I really appreciate your effort and time.
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Speak of the devil! I will check out TCPView as soon as I can.jimimaseye wrote: ↑2019-05-07 22:22Read this: https://www.hmailserver.com/forum/viewt ... =7&t=33965
However, just today I also became fed up with these errors. As you know, I installed RvdH's hmail version and for the past 3 days the backup script failed at NET START hmailserver (not STOP). So today I made a powershell script to stop and also one to start hmailserver. I haven't tested this yet in production except for just making sure the new parts work. I'll let you know tomorrow if I have any problems.
It seems that net stop/start command doesn't wait long enough to return a proper result. The powershell script will stomp the guts out of the service until it submits and then notify you if there were any errors. I guess the notification thing is not really necessary since the backupmail script will do the same thing. However, if, like me the past 3 days, the script errors on net start hmailserver, even though the backup completes successfully the script thinks that hmail is not running and will not attempt to email the log. So I've been receiving the cleardown email but not the backup email.
Code: Select all
:1st
:maildata
echo %time% Stopping Hmailserver service...>> %BackLog%
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\scripts\HMSBackupCleardown\hmstop.ps1'" >> %BackLog%
SC query hmailserver | FIND /i "STOPPED"
set FailedHmailservice=Ok
set bold=%noBold%&set fontcolor=%fontBlack%
if errorlevel 1 set Failed=true&set FailedHmailservice=Failed to stop. Backup of emails not performed!&set bold=b&set fontcolor=%colorfill%
echo %FailedHmailservice%! >> %BackLog%
echo ^<tr^>^<td^>^<%fontcolor%^>^<%bold%^>Hmailserver service shutdown:^</td^>^<td^>^<%fontcolor%^>^<%bold%^>%FailedHmailservice%^</td^>^</tr^> >>%outf%
Code: Select all
:6th
if not "%FailedHmailservice%" == "Ok" set section=7th & goto 7th
echo %time% Starting Hmailserver service... >> %BackLog%
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\scripts\HMSBackupCleardown\hmstart.ps1'" >> %BackLog%
SC query hmailserver | FIND /i "RUNNING"
set bold=%noBold%&set fontcolor=%fontBlack%
if errorlevel 1 set Failed=true&set FailedHmailservice=Failed to restart&set bold=b&set fontcolor=%colorfill%
echo %FailedHmailservice%! Errorlevel=%errorlevel% >> %BackLog%
echo ^<tr^>^<td^>^<%fontcolor%^>^<%bold%^>Hmailserver service startup:^</td^>^<td^>^<%fontcolor%^>^<%bold%^>%FailedHmailservice%^</td^>^</tr^> >>%outf%
Code: Select all
$ErrorActionPreference = 'silentlycontinue'
$ServiceName = 'hMailServer'
Function CkSvcMail($Body) {
$EmailFrom = "notification.account@gmail.com"
$EmailTo = "1234567890@tmomail.net" # or any email address
$SMTPServer = "smtp.gmail.com"
$SMTPAuthUser = "notification.account@gmail.com"
$SMTPAuthPass = "supersecretpassword"
$Subject = "Windows Service Failure"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPAuthUser, $SMTPAuthPass);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}
Stop-Service $ServiceName
Start-Sleep -seconds 60
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'Stopped'){
Stop-Service $ServiceName
Start-Sleep -seconds 60
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'Stopped'){
$Body = "ATTENTION! hMailServer backup script (powershell hmstop) could not shut down service."
CkSvcMail $Body
}
}
Code: Select all
$ErrorActionPreference = 'silentlycontinue'
$ServiceName = 'hMailServer'
Function CkSvcMail($Body) {
$EmailFrom = "notification.account@gmail.com"
$EmailTo = "1234567890@tmomail.net" # or any email address
$SMTPServer = "smtp.gmail.com"
$SMTPAuthUser = "notification.account@gmail.com"
$SMTPAuthPass = "supersecretpassword"
$Subject = "Windows Service Failure"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPAuthUser, $SMTPAuthPass);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}
Start-Service $ServiceName
Start-Sleep -seconds 60
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'Running'){
Start-Service $ServiceName
Start-Sleep -seconds 60
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'Running'){
$Body = "ATTENTION! hMailServer backup script (powershell hmstart) could not restart hMailServer service."
CkSvcSMS $Body
CkSvcMail $Body
}
}
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Updated hmstop and hmstart to be more verbose.
This works. It beats hmailserver service into submission. There's a bit of code in the backupmail.bat file (above) to double check if it worked by checking service status. If error on status, script resumes as with error the same as it was before.
hmstop.ps1
hmstart.ps1
This works. It beats hmailserver service into submission. There's a bit of code in the backupmail.bat file (above) to double check if it worked by checking service status. If error on status, script resumes as with error the same as it was before.
hmstop.ps1
Code: Select all
$ErrorActionPreference = 'silentlycontinue'
$ServiceName = 'hMailServer'
Function CkSvcMail($Body) {
$EmailFrom = "notification.account@gmail.com"
$EmailTo = "1234567890@tmomail.net" # or other email address - i just like txt notifications
$SMTPServer = "smtp.gmail.com"
$SMTPAuthUser = "notification.account@gmail.com"
$SMTPAuthPass = "SuperSecretPassword"
$Subject = "Windows Service Failure"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPAuthUser, $SMTPAuthPass);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp Now executing powershell hmstop shutdown script."
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'RUNNING'){
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer already not RUNNING. Nothing to shut down."
exit
}
else {
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer RUNNING. Preparing to shut down."
}
Stop-Service $ServiceName
Start-Sleep -seconds 60
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'STOPPED'){
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer failed to shut down. Wait 60 seconds and try again."}
else {
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer shut down. Good to go."
exit
}
Start-Sleep -seconds 60
Stop-Service $ServiceName
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'STOPPED'){
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer failed to shut down on 2nd attempt. Wait 60 seconds and try again."}
else {
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer shut down. Good to go."
exit
}
Start-Sleep -seconds 60
Stop-Service $ServiceName
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'STOPPED'){
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer failed to shut down on 3rd attempt. Giving up and sending notification."
$Body = "ATTENTION! hMailServer backup script (powershell hmstop) could not shut down service."
CkSvcMail $Body
}
else {
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer shut down. Good to go."
}
Code: Select all
$ErrorActionPreference = 'silentlycontinue'
$ServiceName = 'hMailServer'
Function CkSvcMail($Body) {
$EmailFrom = "notification.account@gmail.com"
$EmailTo = "1234567890@tmomail.net" # or other email address - i just like txt notifications
$SMTPServer = "smtp.gmail.com"
$SMTPAuthUser = "notification.account@gmail.com"
$SMTPAuthPass = "SuperSecretPassword"
$Subject = "Windows Service Failure"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPAuthUser, $SMTPAuthPass);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp Now executing powershell hmstart startup script."
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'STOPPED'){
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer already RUNNING. Nothing to start."
exit
}
else {
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer STOPPED. Preparing to start service."
}
Start-Service $ServiceName
Start-Sleep -seconds 60
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'RUNNING'){
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer failed to start. Wait 60 seconds and try again."}
else {
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer started. Good to go."
exit
}
Start-Service $ServiceName
Start-Sleep -seconds 60
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'RUNNING'){
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer failed to start on 2nd attempt. Wait 60 seconds and try again."}
else {
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer started. Good to go."
exit
}
Start-Service $ServiceName
Start-Sleep -seconds 60
(get-service $ServiceName).Refresh()
if ((get-service $ServiceName).Status -ne 'RUNNING'){
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer failed to start on 3rd attempt. Giving up and sending notification."
$Body = "ATTENTION! hMailServer backup script (powershell hmstart) could not shut down service."
CkSvcMail $Body
}
else {
$timestamp = "{0:HH:mm:ss.ff}" -f (get-date)
write-output "$timestamp hMailServer started. Good to go."
}
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Interesting read but I’m wondering if beating the server back into submission has any side effects on data quality or stability.
The question is why does the API to stop hang in the first place?
The question is why does the API to stop hang in the first place?
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I haven't experienced any issues.
Likely caused by this: https://www.hmailserver.com/forum/viewt ... =7&t=33965
I don't understand the issue completely, but my basic understanding is that the request to pause or stop times out before all open threads are able to close. That's why my powershell thing works. Because if the first request times out, the second or third will definitely knock it out. I never got past the second request so i never had a scenario where it simply couldn't be stopped.
I have another script that runs 17 minutes after the backup starts that checks telnet for connectivity and if no communication, does effectively the same routine to shut it down. That one has only been triggered when i was using vbs oApp.stop to pause the server and got the hang. I stopped using oApp.stop to pause and the redundant one never triggered again.
Re: HOW TO: Ready-To-Go Backup and Cleardown script
with Emailclearup.vbs, how to get folders with extended chars in their names?
for example, many Turkish android clients create Trash as "Çöp". i tried "&AMcA9g-p" as in DB table but no avail.
for example, many Turkish android clients create Trash as "Çöp". i tried "&AMcA9g-p" as in DB table but no avail.
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Tried as they appear in hmailadmin (folders)?
[Entered by mobile. Excuse my spelling.]
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
yes, but nothing deleted and no entry in email report.jimimaseye wrote: ↑2020-02-28 15:28Tried as they appear in hmailadmin (folders)?
[Entered by mobile. Excuse my spelling.]
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Try entering a log write event that outputs the names of the folders to see what it translates them as?katip wrote: ↑2020-02-28 15:51yes, but nothing deleted and no entry in email report.jimimaseye wrote: ↑2020-02-28 15:28Tried as they appear in hmailadmin (folders)?
[Entered by mobile. Excuse my spelling.]
Find
Code: Select all
sMessage = sMessage & ListFolders(obFolder.SubFolders, iRecursion, rootFolder )
Next
Code: Select all
sMessage = sMessage & ListFolders(obFolder.SubFolders, iRecursion, rootFolder )
Eventlog.write smessage
Next
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
ok, log writes it perfectly:jimimaseye wrote: ↑2020-02-28 20:31Try entering a log write event that outputs the names of the folders to see what it translates them as?
Code: Select all
3456 "2020-02-29 07:35:13.062" "INBOX|"
3456 "2020-02-29 07:35:13.078" "INBOX|Trash|"
3456 "2020-02-29 07:35:13.078" "INBOX|Trash|Çöp|"
Code: Select all
katip@katip.com inbox* 783 17.246K 0
katip@katip.com trash 0 0K 0
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
Re: HOW TO: Ready-To-Go Backup and Cleardown script
i tried to run the script from command line with all echoes enabled.
this comes out:
this comes out:
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Post your version of script so we can see - there might be something obvious.
[Entered by mobile. Excuse my spelling.]
[Entered by mobile. Excuse my spelling.]
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
same Emailclearup.vbs as on top of this thread.jimimaseye wrote: ↑2020-02-29 09:12Post your version of script so we can see - there might be something obvious.
BTW, what kind of conversion does HMS to produce "&AMcA9g-p" from "Çöp" to save on table ?
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
So for your list of trash folders in the variable did you writekatip wrote: ↑2020-02-29 09:30same Emailclearup.vbs as on top of this thread.jimimaseye wrote: ↑2020-02-29 09:12Post your version of script so we can see - there might be something obvious.
Code: Select all
Const MESSAGES_FOLDER = "Trash|Deleted|Çöp
I would have thought that the output that gets written to log ("Çöp") is what is required in your folder list as it is what vbs sees and it's the script that needs to act on it . However, as you can in the script, there are no settings for translating so it will all be as per vbscript defaults. And I'm afraid i do not know about how vbs handles such extended character translations. Sorry. (Does Google help?)
[Entered by mobile. Excuse my spelling.]
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
yes, i wrote
meanwhile after some Googleing i learnt that IMAP folder names MUST be in UTF-7 (as per RFC whatever). so HMS converts "Çöp" to UTF-7, i.e. +AMcA9g-p to save on table.
http://toolswebtop.com/text/process/encode/utf-7
i too have no idea how to cope with all this in VBS.
in fact i'm rather interested in deleting ALL mails older than a certain date in ALL folders, server wide.
this is an easy job. i better script something from scratch.
thanks anyway.
Code: Select all
Const MESSAGES_FOLDER = "Trash|Deleted|Çöp
http://toolswebtop.com/text/process/encode/utf-7
i too have no idea how to cope with all this in VBS.
in fact i'm rather interested in deleting ALL mails older than a certain date in ALL folders, server wide.
this is an easy job. i better script something from scratch.
thanks anyway.
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Oh thats simple.
Code: Select all
Const DAYS_TO_KEEP_MESSAGES = "14" ' Days old to keep mails
Const MESSAGES_FOLDER = "*"
[Entered by mobile. Excuse my spelling.]
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
yes, that did the job. thks.jimimaseye wrote: ↑2020-02-29 11:06That should do it (for 14 days) across all folders throughout and therefore should avoid needing to match tricky folder names.Code: Select all
Const DAYS_TO_KEEP_MESSAGES = "14" ' Days old to keep mails Const MESSAGES_FOLDER = "*"
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
Re: HOW TO: Ready-To-Go Backup and Cleardown script
things getting more complicated.
script was saved in utf-8 and failed to find folders with extended chars in their names.
when i change encoding in Notepad++ to Windows-1254 or ISO-8859-9 (both Turkish) it works as expected.
what if there were folder names in Turkish, Cyrillic, Greek etc.. mixed?
all would require the script saved in their encodings. only workaround could be to run different copies for each encoding.
suitable editor for non-Latin text is another problem. really complicated..
script was saved in utf-8 and failed to find folders with extended chars in their names.
when i change encoding in Notepad++ to Windows-1254 or ISO-8859-9 (both Turkish) it works as expected.
what if there were folder names in Turkish, Cyrillic, Greek etc.. mixed?
all would require the script saved in their encodings. only workaround could be to run different copies for each encoding.
suitable editor for non-Latin text is another problem. really complicated..
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8
Re: HOW TO: Ready-To-Go Backup and Cleardown script
What if there were a way to backup your server into an AES-256 encrypted archive, then upload it to a free file storage site that allows unlimited storage space and will hold your backups for 60 days, no matter how large the files are?
Would you say I was completely crazy for suggesting such a thing is possible?
(That's a teaser )
Would you say I was completely crazy for suggesting such a thing is possible?
(That's a teaser )
-
- New user
- Posts: 2
- Joined: 2021-07-18 16:24
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Hello,
I am a total beginner and have a few questions regarding the implementation of the two scripts to my hmail server.
After I have set up my hmail server, I saved the two scripts into a single holding 'script' folder as mentioned in the post.
But I'm not sure if I saved the scripts in the right place. I first clicked on Events, and then created the "Scripts" folder where I saved the two scripts:
Is this correct? Do I do something with the EventHandlers file?
Thank you very much in advance and kind regards
Dejan
I am a total beginner and have a few questions regarding the implementation of the two scripts to my hmail server.
After I have set up my hmail server, I saved the two scripts into a single holding 'script' folder as mentioned in the post.
But I'm not sure if I saved the scripts in the right place. I first clicked on Events, and then created the "Scripts" folder where I saved the two scripts:
Is this correct? Do I do something with the EventHandlers file?
Thank you very much in advance and kind regards
Dejan
Re: HOW TO: Ready-To-Go Backup and Cleardown script
The scripts in this topic can be run from anywhere. There is no specific location required.
-
- New user
- Posts: 2
- Joined: 2021-07-18 16:24
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Thank you very much for the answer palinka, it is working now.
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Hi all,
I have started using this script to backup Hmailserver
I am only using the server as an IMAP archive / storage.
I downloaded and edited the script as the instructions.
I Use the internal Database and don't run SpamAssassin on my system.
I have run the backup scrip.
SO...
On my D:/ drive I now have a temp location and a zip which contains 2 sub folders.
1. Database with the HmailServer.sdf
2. hMailData with all the email files in their folders.
The log is saying it completed correctly. I am looking to auto run daily, during night time whilst no one logs/sends emails to it.
My question is:
Is this, with the results I have, all I need for restoring my data? i.e. If I need to reinstall HmailServer on a new pc / reinstall windows, due to anything happening / going wrong?
Am I correct in thinking the following for a correct restore:
Once I install a fresh install of HmailServer, I then need to have MySQL Server 5.5 installed on my system, and to use the inputs shown in the restore guide to have all my settings, domain/s and messages all back to what it is now ready to run again?
Thank you for your time.
I have started using this script to backup Hmailserver
I am only using the server as an IMAP archive / storage.
I downloaded and edited the script as the instructions.
I Use the internal Database and don't run SpamAssassin on my system.
I have run the backup scrip.
SO...
On my D:/ drive I now have a temp location and a zip which contains 2 sub folders.
1. Database with the HmailServer.sdf
2. hMailData with all the email files in their folders.
The log is saying it completed correctly. I am looking to auto run daily, during night time whilst no one logs/sends emails to it.
My question is:
Is this, with the results I have, all I need for restoring my data? i.e. If I need to reinstall HmailServer on a new pc / reinstall windows, due to anything happening / going wrong?
Am I correct in thinking the following for a correct restore:
Once I install a fresh install of HmailServer, I then need to have MySQL Server 5.5 installed on my system, and to use the inputs shown in the restore guide to have all my settings, domain/s and messages all back to what it is now ready to run again?
Thank you for your time.
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
The restore guide attached to the thread is only relevant to backups of mysql database - it is not relevant to your internal database backup.
For you:
1, take a copy of your current hmailserver. INI (from bin directory). This is missing (i have just changed the script to include this in the future)
2, new server: install Hmailserver if needed.
3, copy the backup INI file in to new bin directory tells ing the existing (new) one. Edit the data directory within it to reflect new server data location.
4, copy the data and database from the backup to the new server locations accordingly.
5, restart new hmailserver service.
[Entered by mobile. Excuse my spelling.]
For you:
1, take a copy of your current hmailserver. INI (from bin directory). This is missing (i have just changed the script to include this in the future)
2, new server: install Hmailserver if needed.
3, copy the backup INI file in to new bin directory tells ing the existing (new) one. Edit the data directory within it to reflect new server data location.
4, copy the data and database from the backup to the new server locations accordingly.
5, restart new hmailserver service.
[Entered by mobile. Excuse my spelling.]
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Cheers for this.
Is that just re download the zip file at the beginning of this thread for the new code.
Is that just re download the zip file at the beginning of this thread for the new code.
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I haven't changed the zip contents yet. Take the copy of the code within the post for now.
[Entered by mobile. Excuse my spelling.]
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
I have updated both the restore guide and the Zip file (as well as the copy/paste version) in the original from the post. Re-download the script or simply update the "4th" section to read:
Code: Select all
:4th
if "%DBtype%" == "mysql" (
erase /Q "%BACKUPTEMPdir%"\hMailData\*.mysql >> %BackLog%
"%MYSQLBINdir%"\mysqldump -u"%MYSQLDBuser%" -p"%MYSQLDBpass%" -q -A -l --add-drop-table -PMYSQLDBport >"%BACKUPTEMPdir%\hMailData\MYSQLDump_%inDate%.mysql"
) ELSE (
xcopy /f /I "%HMAILSERVERprogdir%"\Bin\hmailserver.ini "%BACKUPTEMPdir%"\Bin\ >> %BackLog%
robocopy "%InternalDATABASEdir%" "%BACKUPTEMPdir%"\Database /mir /ndl /r:43200 /np /w:1 >> %BackLog%
goto ROBOerrorcheck
)
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Works like a charm. I've even installed hMailserver on another pc as a test. Copied across the files. Bosh ready to run again.
The only thing is, can I tweek the code so the hmaildata folder can be saved as just data in the zip. I Use win rar on all my pcs. So would be just a case to extract into hMailserver directory over writing existing files. And ready to run.
Thank you.
The only thing is, can I tweek the code so the hmaildata folder can be saved as just data in the zip. I Use win rar on all my pcs. So would be just a case to extract into hMailserver directory over writing existing files. And ready to run.
Thank you.
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Feel free to do what you want to it. I offered the original as something that worked for me and a starter for others.
(Nb: data without database is pointless)
[Entered by mobile. Excuse my spelling.]
(Nb: data without database is pointless)
[Entered by mobile. Excuse my spelling.]
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
Re: HOW TO: Ready-To-Go Backup and Cleardown script
No problem. I ment to put rename. So all data is the same just folder name changes. Didn't explain correctly.
I'll have a tinker
I'll have a tinker
Re: HOW TO: Ready-To-Go Backup and Cleardown script
Ok so I'm not sure if its me but I have been running your new code with copying the INI file.
It now gets to the point when it goes to copy it and just sits there. I look into the log file, it has this at the bottom
"XTRA Overwrite C:\EmailBackupTemp\Bin\hMailServer.INI (Yes/No/All)? "
So if I delete the INI file in the "temp" folder that is setup in the code, and the script then runs through perfectly.
What needs to be altered to get it to overwrite the INI file?
It now gets to the point when it goes to copy it and just sits there. I look into the log file, it has this at the bottom
"XTRA Overwrite C:\EmailBackupTemp\Bin\hMailServer.INI (Yes/No/All)? "
So if I delete the INI file in the "temp" folder that is setup in the code, and the script then runs through perfectly.
What needs to be altered to get it to overwrite the INI file?
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
thanks for the feedback - Ill be back shortly......
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829
- jimimaseye
- Moderator
- Posts: 10053
- Joined: 2011-09-08 17:48
Re: HOW TO: Ready-To-Go Backup and Cleardown script
in the "4th" section
change
from
to
(I will update the code later to reflect these changes)
change
from
Code: Select all
xcopy /f /I "%HMAILSERVERprogdir%"\Bin\hmailserver.ini "%BACKUPTEMPdir%"\Bin\ >> %BackLog%
Code: Select all
xcopy /f /I /Y "%HMAILSERVERprogdir%"\Bin\hmailserver.ini "%BACKUPTEMPdir%"\Bin\ >> %BackLog%
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
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829