How to backup ?

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.
Post Reply
Vassilis
New user
New user
Posts: 5
Joined: 2011-02-23 11:06

How to backup ?

Post by Vassilis » 2011-02-23 11:11

Hi,
We are using the hmailserver Version 5.3.3-B1879 and i read allover the forum about the built-in backup that only support up to ~1GB of size on the .zip but i cannot find anywhere how to properly backup after you reach the limit.
I have the configuration in .xml so that it is covered, so what happens with the database that contain the actual emails.

What is the proper method of a full backup so in a disaster i can restore it on a different machine and have everything working as normal.

I will appreciate a guideline on this.

thank you.
Vassilis

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to backup ?

Post by ^DooM^ » 2011-02-23 13:25

Vassilis wrote:so what happens with the database that contain the actual emails.
The emails are not stored in the database, they are stored in the data directory.

For disaster recovery, Backup the database contents, the data directory and the hmailserver.ini file. Check the docs for details on how to gain access to builtin database if you are using it.
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

Vassilis
New user
New user
Posts: 5
Joined: 2011-02-23 11:06

Re: How to backup ?

Post by Vassilis » 2011-02-23 13:27

can you point me to the docs you are referring.
I'm using Database MSSQL CE according to the application.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to backup ?

Post by ^DooM^ » 2011-02-23 13:29

Really? You couldn't find that yourself?

http://www.hmailserver.com/documentatio ... t_to_mssql
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

Vassilis
New user
New user
Posts: 5
Joined: 2011-02-23 11:06

Re: How to backup ?

Post by Vassilis » 2011-02-23 13:39

thank you

Tezcatlipoca
Senior user
Senior user
Posts: 309
Joined: 2009-07-21 12:33

Re: How to backup ?

Post by Tezcatlipoca » 2011-02-24 13:07

If it helps, I have my hMailServer on a nightly backup which deals with both the emails themselves and the SQL database running in the background. You would need to change any relevent parts for your own setup, but mine looks like this:

I have a subfolder within the hMail installation, the path of which is 'E:\hMailServer\Emails'.
This folder contains three files: 7za.exe (the command-line version of the free 7zip archive program), backup.bat (a custome written batch file that triggers the backup) and BackupScript.sql (a custom SQL script that backs up the database).

A Windows Scheduled Task kicks everything off automatically by running backup.bat each night at 8pm.


Backup.bat contains the following code

Code: Select all

del /f /q *.bak
del /f /q emails.7z
echo %Date%, %Time%,  Start Database >> E:\hMailServer\Emails\emailbackup.txt
sqlcmd -S VAULT\SQLEXPRESS -u -i E:\hMailServer\Emails\BackupScript.sql
echo %Date%, %Time%,  End Database >> E:\hMailServer\Emails\emailbackup.txt
echo %Date%, %Time%,  Start Emails >> E:\hMailServer\Emails\emailbackup.txt
7za.exe a emails.7z "E:\hMailServer\Data"
echo %Date%, %Time%,  End Emails >> E:\hMailServer\Emails\emailbackup.txt
xcopy "E:\hMailServer\Emails\emailbackup.txt" "\\10.0.1.80\redirects$\<MY-REAL-NAME>\Desktop\Logs" /C /O /Y
del /f /q emailbackup.txt
Lines 1 and 2 delete yesterday's backup data from the local drive, ready for the new. Lines 3, 5, 6 and 8 are used to inject data about the backup into a text file. I use this text file to monitor that the backup was successful, and also to keep an eye on how long the backup takes each night. Line 9 is the textfile being copied over to my roaming profile in the server, so when I come in in the morning the log is waiting for me. Line 10 just cleans the log after I'm done.

The two lines that are the meat of the process are 4 and 7. Line 4 calls an SQL script I've written that contains the following code:

Code: Select all

DECLARE @Path NVARCHAR(1000), @FileName NVARCHAR(255), @FullPath NVARCHAR(1255)
SET @Path = 'E:\hMailServer\Emails\'
SET @FileName = 'MailBox_' + REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') + '.bak'
SET @FullPath = @Path + @FileName
BACKUP DATABASE MailBox
TO DISK = @FullPath
WITH INIT
Here, a backup is made of my database (called 'MailBox'). It is automatically created as a .bak file in the same folder as backup.bat.

That's the database taken care of, now line 7 of backup.bat handles the actual emails. Because of the sheer amount and size, I compress mine using the command-line automated version of the free 7zip archive utility.
As you can see, the whole data folder is compressed, and the file gets put into the same folder as backup.bat.

Finally, I have other backup procedures running independently that go into my mailserver machine (called VAULT) and grab the database backup and the 7zip archive that were created and copies them to dedicated backup drives.


By this process, my whole hMail system gets backed up every night, taking about five hours.


Hope this helps.

Vassilis
New user
New user
Posts: 5
Joined: 2011-02-23 11:06

Re: How to backup ?

Post by Vassilis » 2011-02-24 13:20

nice one Tezcatlipoca, many thanks i will definitely take a look at that.

xbipin
Normal user
Normal user
Posts: 79
Joined: 2010-05-23 16:24

Re: How to backup ?

Post by xbipin » 2011-04-30 08:10

thanks Tezcatlipoca, ur bat file etc really helped and currently im using this method and works perfect, one note though, if any1 using mysql, then u can use the mysql administrator to create schedule task to backup the hmaislerver DB only, files need to be backed up using the bat file and zip method.

freemailer
Banned
Posts: 95
Joined: 2007-12-30 13:57

Re: How to backup ?

Post by freemailer » 2011-04-30 23:43

Tezcatlipoca wrote:If it helps, I have my hMailServer on a nightly backup which deals with both the emails themselves and the SQL database running in the background. You would need to change any relevent parts for your own setup, but mine looks like this:

I have a subfolder within the hMail installation, the path of which is 'E:\hMailServer\Emails'.
This folder contains three files: 7za.exe (the command-line version of the free 7zip archive program), backup.bat (a custome written batch file that triggers the backup) and BackupScript.sql (a custom SQL script that backs up the database).

A Windows Scheduled Task kicks everything off automatically by running backup.bat each night at 8pm.
I've done the same. But in my opinion it's not "good".
There are inconsistencies when you backup the database and then backup the mails when you get more mails after you did the the sql backup.
I'm working on a script with uses VSS to get everything in a consistent state and backup from this snapshot.

xbipin
Normal user
Normal user
Posts: 79
Joined: 2010-05-23 16:24

Re: How to backup ?

Post by xbipin » 2011-05-01 06:57

yes im aware of it but it does the job on servers with fewer mailboxes so chances r even if mails come in and out u might have more files than DB entries but that will be of concern only when ur in a situation where u need to restore from backup. another thing that could be done on smaller installation is to switch hmail off, then backup and then start it.

freemailer
Banned
Posts: 95
Joined: 2007-12-30 13:57

Re: How to backup ?

Post by freemailer » 2011-05-01 12:55

I have only about 50 accounts but 50gb to backup. This takes a while.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to backup ?

Post by ^DooM^ » 2011-05-01 14:43

Why don't you use something like Ghostfiles to keep the data directory mirrored in a backup location, then stop the Ghostfiles service in your script, Zip the secondary data directory with the database dump, move the zip wherever, then re-enable Ghostfiles service, that way you will always have a snapshot and you never need to disable hMail at all.
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

xbipin
Normal user
Normal user
Posts: 79
Joined: 2010-05-23 16:24

Re: How to backup ?

Post by xbipin » 2011-05-01 15:23

personally, i would prefer a more robust backup and restore feature in hmail itself coz i rent a lot of servers so its not feasible for me to buy the software for all servers and mayb if hmail had a feature such that when in backup progress mode, it continues to accept mails but doesnt copy to data directory or the DB untill the backup is complete that way it can be consistent.

also most of my servers r with 2 HDD's mirrored for HDD failure and a ftp backup for each server so that other software doesn't sync with ftp locations etc and all of the servers have a handful of accounts but use up almost 30GB of space in emails.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to backup ?

Post by ^DooM^ » 2011-05-01 16:42

Feel free to add what you need to 5.4 source
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

xbipin
Normal user
Normal user
Posts: 79
Joined: 2010-05-23 16:24

Re: How to backup ?

Post by xbipin » 2011-05-01 16:58

^DooM^ wrote:Feel free to add what you need to 5.4 source

only if i hadn't stopped programming so long ago :D

i can donate along with others if there was a bounty section similar to that in pfsense where u can pay and get features added provided any of the developers were willing to take it up

Kelden
Normal user
Normal user
Posts: 44
Joined: 2011-05-02 13:58

Re: How to backup ?

Post by Kelden » 2011-05-02 14:25

I've created a batch file which (it works only with Server 2008/2008 R2)

1) stops hMailServer (in case you use the integrated MSSQL/MYSQL db)
2) creates a shadow copy
3) starts hMailServer
4) backups complete hMailServer folder (excluding logs) with 7zip

I can post the scripts if you are interessted.

Vassilis
New user
New user
Posts: 5
Joined: 2011-02-23 11:06

Re: How to backup ?

Post by Vassilis » 2011-05-02 14:26

Yes Kelden, please post it.

Kelden
Normal user
Normal user
Posts: 44
Joined: 2011-05-02 13:58

Re: How to backup ?

Post by Kelden » 2011-05-02 15:08

Here is the current version I use. It's very basic atm and only does the job when
everything is correctly set up.
I've setup a google code page to improve it
http://code.google.com/p/hmailserver-ba ... loads/list

extract it in any folder you want.
a) you need a folder C:\Backup
create it first or change it in the batch file. It's not automatically created yet.

b) start backup_hMailServer.cmd to start a backup
perhaps you have to change the PRETTY_DATE variable

backup_hMailServer.cmd stops hMailServer and calls diskshadow.script
diskshadow.script does all the work for creating a shadow copy and assigning a drive letter.
diskshadow.script executes ___hMailserver_backup.cmd which does the real job.


TODO:
- automatically create C:\Backup if it doesn't exist
- better names for scripts
- backup real Database instead of the integrated one
- better date format independent of current date format


You can post any whishes and I will try to upgrade it soon.

bescher
Normal user
Normal user
Posts: 123
Joined: 2008-05-26 01:56
Location: Milwaukee Wi
Contact:

Re: How to backup ?

Post by bescher » 2011-05-03 10:10

I am getting this message
C:\backup1>diskshadow -s diskshadow.script
'diskshadow' is not recognized as an internal or external com
operable program or batch file.
Starting hMailServer


I have a c:\backup and I am runnning the script from c:\backup1 and it is in the path and shadow server is enabled
This is on a windows 2003 server


Thanks

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: How to backup ?

Post by ^DooM^ » 2011-05-03 10:52

Kelden wrote:I've created a batch file which (it works only with Server 2008/2008 R2)
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

Kelden
Normal user
Normal user
Posts: 44
Joined: 2011-05-02 13:58

Re: How to backup ?

Post by Kelden » 2011-05-03 13:23

Still trying to figure out how to create a shadow copy on Server 2003

Kelden
Normal user
Normal user
Posts: 44
Joined: 2011-05-02 13:58

Re: How to backup ?

Post by Kelden » 2011-05-21 22:17

I've created a new version I'm currently testing on my server with full backup once a week and incremental backups else.
This will reduce the backup size significantly and it's optional if you don't like it. If it's working well, I will post an update the next days.

mbq
New user
New user
Posts: 1
Joined: 2010-05-02 02:18

Re: How to backup ?

Post by mbq » 2011-06-29 17:25

Is there a way to "pause" the server from receiveing emails without shutting it down? or stop the pop service?

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

Re: How to backup ?

Post by mattg » 2011-06-29 18:13

Using the stop button in the GUI really only 'pauses' the server, but all protocols, SMTP + POP3 [+IMAP]
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

kevinwinters
New user
New user
Posts: 26
Joined: 2008-12-16 13:57

Re: How to backup ?

Post by kevinwinters » 2011-06-29 22:33

Kelden,
To create a shadow copy via script in server 2003 use vshadow.exe from the resource kit

Kelden
Normal user
Normal user
Posts: 44
Joined: 2011-05-02 13:58

Re: How to backup ?

Post by Kelden » 2011-08-02 21:26

Updated to v0.2
I've added incremental backups.

http://code.google.com/p/hmailserver-ba ... loads/list

Post Reply