Author Topic: Automatically Backup Emails to Remote Server  (Read 7677 times)

0 Members and 2 Guests are viewing this topic.

Offline
*
Automatically Backup Emails to Remote Server
« on: September 26, 2019, 06:28:53 PM »
I have the problem to make regular backups for users emails. The problem is that the admin module "Backup" DOES NOT INCLUDE EMAILS, only public_html dir and mysql DB. The same is with "remote backup": no emails are backed up, the only way to accomplish a mail backup using CWP options is under User Panel > File Management > Backup > Full Account Backup, but I didn't find a way to make this automatic. So, I implemented this solution:


Prerequisites

I'm assuming you have the REMOTE BACKUP option enabled and working, since this solution uses "ssh -i" authentication method (same as "remote backup").


Incremental Backup for Emails to Remote Server

I created in local server a file in "/" dir called "mailBackup.sh" with this code:

rsync -av -e 'ssh -p 2200 -i /root/.ssh/backup/id_rsa' /var/vmail backup@xxx.xxx.xxx.xxx:/home/backup/cwp_remote/email/server6

As you may notice, I'm connecting to the remote server's IP (obfuscated here) via SSH using a user I already setup there called "backup" (must be able to connect via SSH, so check user's permissions in CWP). As I already mention, SSH KEY must be setup properly in remote backup option (locally and remote) for this to work.

The backup is made using incremental "rsync" command, where I'm coping everything under local server "/var/vmail" dir to remote server dir "/home/backup/cwp_remote/email/server6", this, because I have several servers, all making backups to the same Backup Server but to it's own directory.

Finally, in order to make this backups automatic, I just added a "root cron job" in CWP panel as follows:

35 01 * * sun /bin/bash /mailBackup.sh

Here, I'm programming the email backup to be executed every Sunday at 01:35 hrs.

I hope this helps! :)
« Last Edit: September 26, 2019, 06:39:17 PM by Zeticloud Services »

Offline
*
Re: Automatically Backup Emails to Remote Server
« Reply #1 on: September 26, 2019, 10:05:43 PM »
Note: If you are setting up the Remote Backup for the first time BEFORE you can get the "Connection_OK" message in the Remote Backup module you MUST add the remote server to the "known_hosts" file at the local server (/root/.ssh/known_hosts). For me, the easy way to do so is to SSH login to your local server, and then SSH login to the remote server, in this way the system in local server is going to ask you if you want to add the remote server to known hosts, just type "yes".

Good luck!
« Last Edit: September 26, 2019, 10:12:29 PM by Zeticloud Services »