Talk:User Tips & Tricks

From QmailToaster wiki
Jump to navigation Jump to search

Automated Backup and restore[edit]

How to Backup your qmailtoster server to an other server. Through necessity, I have created a Backup server ( server2 ) to act as a copy of my main qmailserver ( server1 ) and automated the process.

Note this is not the only method , and I give no guarantees it will work for you. I installed two server identically using QMT.iso Centos 5 version from our great friend Jake Vickers. I also purchased and installed qcontrol for ease , and it is great.

Login to server 1 (your IP address ) 192.168.1.100 cd /root

Create the Key file ssh-keygen -t dsa ( this will be called id_dsa_pub ) in the /root/.ssh/ folder

Check the file exists cd .ssh/ ls

Copy file to Server 2 ( your IP address ) 192.168.1.101 scp id_dsa.pub root@192.168.1.101:/root/.ssh/ enter root password on server 2

SSH to server 2 ssh root@192.168.1.101 enter root password again

Check the file came across cd /root/.ssh ls

Add the key to the authorized_keys files cat id_dsa.pub >> /root/.ssh/authorized_keys


Your server 2 is now setup to allow root to login from server1. Exit and login again, it should not ask for a password if all went well.

ssh root@192.168.1.101 exit, back to server 1.

Your back up should be in the /backup/ Called something like 200904280102-backup.tar.gz

 ( year, month, date, time-backup.tar.gz )

Depending on your system, it can take hours. So I created a script, to backup then SCP the backup to server 2

Here is mine: /root/backup.sh

mkdir /saved ( for older backup tar files )

#!/bin/sh
# run backup command
/usr/sbin/qtp-backup
#
# Copy file to server 2 using SCP to the /root folder
cd /backup
scp *-backup.tar.gz root@192.168.1.101:/root/
exit

save the file , and make it executable: chmod +x backup.sh

On server 1 make a cron job to run the backup (mine is at 02:00 ) crontab -e

* 2 * * * /root/backup.sh

The scrip will copy all *-backup.tar.gz, so make sure there is only the current, move older backups to other folder. On server2

Thanks to Erik, modify the qtp-restore script. Change: read -p "Please enter your MySQL Root password: " mysqlrootpass

to read -p "Please enter your MySQL Root password: " mysqlrootpass mysqlrootpass=your_password

Save it ..

create a cron job for the restore : i run mine at 04:00

* 4 * * * /usr/sbin/qtp-restore

Login to server2 and double check everything restored, you may have to reboot , not sure yet.

Hope this helps someone, as it was to late for me. All my tests worked, this is a true working environment, not a Lab test.

MadMac