Wednesday, March 7, 2012

How to Backup SquirrelMail on Ubuntu 9.04

If you have been looking for ways to backup SquirrelMail then this is the place for you.
To start with, I found that the emails are stored one in each file in /var/vmail/our-domain-name/user/cur when read and in /var/vmail/our-domain-name/user/new when unread. I tried to make a test user using ISPConfig and copied the mail folder /var/vmail/our-domain-name/user to /var/vmail/our-domain-name/testuser but I did not get the results that I was looking for. After searching the Net and learning a few things, I have come up with this how-to for other Linux enthusiasts so that they can easily backup SquirrelMail.

After logging in as sudo su:
1. Create a folder called imap_tools under /usr/local.

2. Download these files to this folder : 
    imapdump.pl : This is to backup the squirrel mail folders or IMAP folders 
   dumptoIMAP.pl : This is to put the backed up folders back into SquirrelMail if ever the need arises due to a server crash or some such.  

3. Create a folder called backup under root (/). You can create one with a different name or in some other location if you wish. 

4. /usr/local/imap_tools/imapdump.pl -f /backup/user -S localhost/user@yourdomain/users-passwd
This command will backup SquirrelMail folders belonging to user to the /backup/user folder. You will have one folder for each mailbox and the emails will be stored therein, one file per e-mail.

5. zip -r /backup/user_`date '+%d%m%Y'` /backup/user/
This command will create a file called user_07032012 (if today's date is 07/03/2012) in the /backup folder by zipping the folders and files under /backup/user. This is your answer if you did not know how to zip a folder with its subfolders in Linux or how to zip folder recursively on Linux.

6.  Next download pscp.exe from here. The one I downloaded earlier gave me the error : pscp.exe is not a valid win32 application. Hence, I downloaded it from here.

7. On your Windows PC, create a folder. I created d:\sqbak on my WIN XP PC and copied the pscp.exe here. I also created and ran a batch file called sqbak.bat which contains:
pscp.exe -pw users_password user@server_ip_addr:/backup/*.zip d:\sqbak 
This is your answer to copy a file from Linux to Windows.
To schedule this task to automatically copy a file from Linux to Windows, you can make use of the Scheduler available in Windows. For more information, click here.

8. The zipped file will now be backed up from your Linux server onto your Windows PC in d:\sqbak.

9. To check whether your SquirrelMail backup is authentic or to restore SquirrelMail backup in case of a server crash or when you upgrade to a new server or a later version of Linux.

0 comments:

Post a Comment