CentOS Linux Server Installation , FAQ, Tips and Tricks

CentOS Linux Backup

Backup Using Rsnapshot

In our scenario below, we have 2 severs, there are :

 

Server 1: 

Hostname: linuxbackup.example.local

IP :192.168.10.47/255.255.255.0

GW:192.168.10.1

Function: Rsnapshots server , all the data will be stored here.

 

Server 2:

Hostname: linuxmail.example.local

IP :192.168.10.48/255.255.255.0

GW:192.168.10.1

Function: Rsnapshots client, this a Mail server that run on iRedmail

 

Step1: Configure hostname for both servers

At  Server1, Rsnapshot server

vi /etc/hosts

 

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1               linuxbackup.example.local linuxbackup localhost.localdomain localhost

::1             localhost6.localdomain6 localhost6

192.168.10.48 linuxmail.example.local linuxmail

192.168.10.47 linuxbackup.example.local linuxbackup

 

 At  Server2, Mail server

vi /etc/hosts

 

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1               linuxmail.example.local linuxmail localhost.localdomain localhost

::1             localhost6.localdomain6 localhost6

192.168.10.48 linuxmail.example.local linuxmail

192.168.10.47 linuxbackup.example.local linuxbackup

 

Step 2: Install the Rsnaphot package via  Dag RPM Repository

At linuxbackup.example.local, first we need to install the Dag RPM Repository

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

 

Next, we  install Rsnapshot via Dag RPM Repository

yum install rsnapshot –y

 

Step3: Create RSA keys for SSH

Create SSH  access with key access, so that the access from our Linux Backup server can access our Mail Sever.

Note: please DO NOT enter passphrase

AT linuxbackup.example.local, just press <Enter> to accept all default values.

yum install rsnapshot –y

cd /root

 

ssh-keygen -t dsa

Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx root@linuxbackup.example.local

 

Next, copy the ssh key over to linuxmailserver 

ssh-copy-id -i  ~/.ssh/id_dsa.pub linuxmail.example.local

root@linuxmail's password: <your linuxmail password here>

Now try logging into the machine, with ssh command

ssh linuxmail

 

Check the hostname you just login

whoami

 

The command, ssh-copy-id is to copy the ssh key generated and copy it to the target server and appended into authorized_keys, you can check the content of the yet

cat .ssh/authorized_keys

Note:  if your remote /target server does not have .ssh, please  create a folder call .ssh under root home directory .

 

Step4: Configure Rsnapshot backup location

AT linuxbackup.example.local

cp  /etc/rsnapshot.conf  /etc/rsnapshot.conf.ori

vim /etc/rsnapshot.conf

 

Modify the following lines in /etc/rsnapshot.conf

Change the snapshot root directory. By changing this setting all  backup (aka. snapshots) will be stored under this root directory.

snapshot_root   /backup/

 

Next, Let us uncomment this to enable remote ssh backups over rsync.

cmd_ssh /usr/bin/ssh

ssh_args        -p 22

 

Add in, this the backup location, we will dump our rsnapshot backup to /backup/linuxmail

backup root@linuxmail.example.local:/vmail/  linuxmail/
backup root@linuxmail.example.loca:/var/www/ linuxmail/
backup root@linuxmail.example.loca:/etc/ linuxmail/
backup root@linuxmail.example.loca:/var/lib/ldap linuxmail/
backup root@linuxmail.example.loca:/opt/iRedAPD-1.3.0/ linuxmail
backup root@linuxmail.example.local:/opt/iredapd/ linuxmail

backup root@linuxmail.example.local:/opt/iredapd/ linuxmail

 

Note:

By performing above configuration. Our backup of linuxmail will be  backup at the linuxbackup under /backup/X.Y/ linuxmail, you will see in detail later

X – is either hourly, daily or weekly

Y- is 0-n , the number we keep the copy

 

Commented or remove  the following local backup

#backup /etc/passwd     localhost/

#backup /home/foo/My Documents/         localhost/

 

Step5: Configure Backup Intervals

At /etc/rsnapshot.conf change BACKUP INTERVALS,  Must be unique and in ascending order

interval        hourly  6

interval        daily   0

interval        weekly  0

 

we maintain 6  copies hourly, for example 0-6  hourly copies. Thus, in our linuxbackup server, you will see the following folders under /backup folder

drwxr-xr-x 3 root root 4096 May  6 15:00 hourly.0

drwxr-xr-x 3 root root 4096 May  6 14:00 hourly.1

drwxr-xr-x 3 root root 4096 May  6 13:00 hourly.2

drwxr-xr-x 3 root root 4096 May  6 12:00 hourly.3

drwxr-xr-x 3 root root 4096 May  6 11:00 hourly.4

drwxr-xr-x 3 root root 4096 May  6 10:00 hourly.5

..

..

 

Step 6 make a backup directory

AT linuxbackup.example.local

mkdir /backup

 

Step 7: test the rsnapshot config

rsnapshot configtest

Syntax OK

 

TIPS: Please use <Tab> button when configiure /etc/rsnapshot.conf else the application will complain whitespace error

rsnapshot configtest

----------------------------------------------------------------------------

rsnapshot encountered an error! The program was invoked with these options:

/usr/bin/rsnapshot configtest

----------------------------------------------------------------------------

ERROR: /etc/rsnapshot.conf on line 216:

ERROR: backup root@linuxmail:/etc/ linuxmail/

ERROR: ---------------------------------------------------------------------

ERROR: Errors were found in /etc/rsnapshot.conf,

ERROR: rsnapshot can not continue. If you think an entry looks right, make

ERROR: sure you don't have spaces where only tabs should be.

 

Step 8:Run the Rsnashop Test Manually

AT linuxbackup.example.local

 

Run a manual test of rsnap if this work perfectly

/usr/bin/rsnapshot hourly

 

If you have motile rsnapshot configuration files, specify the config file location, for example

/usr/bin/rsnapshot –c /etc/rsnapshotServerA.conf hourly

 

 

 Step 9: Configure Crontab

AT linuxbackup.example.local

crontab –e

0 * * * * /usr/bin/rsnapshot hourly

30 23 * * * /usr/bin/rsnapshot daily

 

Step10: Check the backup

AT linuxbackup.example.local

 

# ll /backup

 

total 56

drwxr-xr-x 3 root root 4096 May  5 19:58 daily.0

drwxr-xr-x 3 root root 4096 May  6 15:00 hourly.0

drwxr-xr-x 3 root root 4096 May  6 14:00 hourly.1

drwxr-xr-x 3 root root 4096 May  6 13:00 hourly.2

drwxr-xr-x 3 root root 4096 May  6 12:00 hourly.3

drwxr-xr-x 3 root root 4096 May  6 11:00 hourly.4

drwxr-xr-x 3 root root 4096 May  6 10:00 hourly.5

 

Step11: Restore data

(Taking  iRedmail as example)

 

Scenario, one of the user email mailbox was corrupted.

At linuxmail. example.local, Stop all mail activities and services

 

Service  postfix stop

Service dovecot stop

Service httpd stop

 

Backup the usermail box to another location

mkdir /mailboxbck

mv /var/vmail/vmail1/example.cal/w/ww/www  /mailboxbck

 

 AT linuxbackup.example.local

 

For example I want restore my mailbox at hourly.3 user name www to 192.168.10.48

 

scp -rp  /backup/hourly.3/linuxmail/var/vmail/vmail1/example.cal/w/ww/www/ root@192.168.10.48:/var/vmail/vmail1/example.cal/w/ww/

 

 Note: scp using root to copy, thus please change the user name and group priveldges

 

At linuxmail. example.local

First we change the group and user for iRedmail's user, next, we start all the services for mail and web.

chown vmail.vmail –R /var/vmail/vmail1/example.cal/w/ww/

service  postfix start

service dovecot start

service httpd start

 

 

 

Finally, check your mail log if the mail is operating correctly

tail –f /var/log/maillog

Now, you can check if your previous email for user www has been restored successfully.

 

 

 

Back to Home



Like this guide? Why not buy me a coffee?



Knowledge shared by 2010 1A-CentOSserver.com. Please feel free to link

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy