Saturday, November 28, 2015

BackupPC installation (RHEL 6)





Table of contents:

A. BackupPC installation
B. BackupPC, some important points
1. Backup location parameter
2. backuppc user parameter
3. cgiadmin user parameter
4. Enabling passwordless SSH between server and client
5. Understanding taking backup options in config.pl file
C. BackupPC administration
1. Adding Host to server
1.1 By CLI
1.2 By GUI
2. Taking backup of client system
2.1 By CLI
2.2 By GUI
3. Restoring backup to client
4. Taking backup from crontab



 A. BackuPC Installation:
1. Download and install EPEL & remi repo:

2. Enable remi repo:
enabled=1

3. Register system to RHN:
And select channel “Server optional”.

4.  Now install the packages:
# yum -y install perl-Compress-Zlib perl-Archive-Zip perl-File-RsyncP perl-suidperl openssh-clients expect perl-XML-RSS httpd

5. Add backuppc user and give password:
# useradd backuppc
# passwd backuppc

6. Now install BackupPC
# yum install  BackupPC
(It will take the package from the repo).

7. Keep On the httpd and backuppc services:
# chkconfig backuppc on
# chkconfig httpd on

8. Now set the password for the backuppc user to use apache service:
# htpasswd -c /etc/BackupPC/apache.users backuppc
Give password here.

9. Make changes in backuppc.conf file for apache:
# vim  /etc/httpd/conf.d/BackupPC.conf
File should look like this:
order deny,allow
deny from all
#allow from 127.0.0.1
#allow from ::1
allow from all
AuthType Basic
AuthUserFile /etc/BackupPC/apache.users
AuthName “backuppc”

10. Take backup of the backuppc mail config file:
# cp /etc/BackupPC/config.pl /etc/BackupPC/config.pl.ORIG

11. Now make changes in backuppc mail config file:
# vim  /etc/BackupPC/config.pl

Make following changes:
$Conf{ServerInitdPath} = '/etc/init.d/backuppc';
$Conf{ServerInitdStartCmd} = '$sshPath -q -x -l root $serverHost$serverInitdPath start';
$Conf{CgiAdminUsers} = 'backuppc';

Also, cross check if the following values are correct:
$Conf{ServerHost} = 'localhost';
$Conf{BackupPCUser} = 'backuppc';
$Conf{TopDir} = '/var/lib/BackupPC/';
$Conf{ConfDir} = '/etc/BackupPC/';
$Conf{LogDir} = '/var/log/BackupPC';
$Conf{InstallDir} = '/usr/share/BackupPC';
$Conf{CgiDir} = '/usr/share/BackupPC/sbin/';

12. Grant passwordless sudo for user backuppc:
# visudo

Add these entries (in the end):
Defaults !lecture
backuppc ALL=NOPASSWD:/bin/gtar,/bin/tar

And comment this entry:
#Defaults requiretty

13. Restart apache and backuppc service:
# /etc/init.d/http restart
# /etc/init.d/backuppc restart

14. Now open your browser and type:
Note: systems might require DNS lookup enabled.



B. BackupPC: Some important points

1. Backup location parameter:
Relevant parameter in config.pl file:
$Conf{TopDir} = '/var/lib/backuppc';
On this path, the clients backup will be stored on the server.
If you want to store backup onto another media, just give the mount point path here.

2. Backuppc user parameter:
Relevant parameter in config.pl file:
$Conf{BackupPCUser} = 'backuppc';
The backuppc user must be present in the system before installation other it will prompt you a message while installing from backuppc.tar.
The web GUI should be accessed by backuppc user.

3. cgiadmin user parameter:
Relevant parameter in config.pl file:
$Conf{CgiAdminUsers} = 'backuppc';
The cgiadminuser should be set to backuppc, otherwise you might not get a proper web based GUI.

4. Enabling password-less SSH between server and client:
To be able to restore from server to client, password-less SSH must be enabled between backuppc user on server to any user on client system, whose backup has to be taken.

Enabling password-less SSH:
Server system:
Hostname: server.example.com
IP: 192.168.1.76
User: backuppc


Remote system:
Hostname: client.example.com
IP: 192.168.1.73
User: root

4.1. Create authentication SSH-keygen keys on server:
[backuppc@server] ssh-keygen –t rsa
Press enter everytime.

4.2. Create .ssh directory on client:
[backuppc@server] ssh root@client mkdir –p .ssh

4.3. Upload generated public keys to client:
[backuppc@server] cat .ssh/id_rsa.pub | ssh root@client 'cat >> .ssh/authorized_keys'

4.4. Set permissions on client:
[backuppc@server] ssh root@client "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"

4.5. Login from server to client without password:
[backuppc@server] ssh root@client

Note: DNS lookup is enabled between both systems.

5. Understanding taking backup options in config.pl file:
Parameter: $Conf{BackupFilesOnly}
Which decides which files to be backed-up from the client.

Example:
$Conf{BackupFilesOnly} = {
  '*' => [
    '/boot',
    '/etc',
    '/home',
    '/usr/local',
    '/var'
  ]
};

Means, whenever the server will go to any client, it will take backup of the above mentioned directories.
Taking specific files backup on a specific client:
Now, if you want to take specific folders from a specific client, do this:
On server. Go to :
# cd /etc/BackupPC/pc
Create new file here:
# vim <client_name>.pl
$Conf{XferMethod} = 'rsync';
$Conf{RsyncClientCmd} = '$sshPath -q -x -l brady $host $rsyncPath $argList+';
$Conf{RsyncClientRestoreCmd} = '$sshPath -q -x -l brady $host $rsyncPath $argList+';
$Conf{BackupFilesOnly} = {
  '*' => [
    '/home/username',
    '/var/www/username'
  ]
};

Now, go to web GUI and start taking backup of the system or system would do it automatically according to its settings.


C. BackupPC administration:

1. Adding a host:
1.1 By CLI:
You need to add host entry in /etc/BackupPC/hosts file.
Then restart the service.

# vim /etc/BackupPC/Hosts
Add in the end
host          dhcp    user    moreUsers     # <--- do not edit this line
#farside     0        craig    jill,jeff     # <--- example static IP host entry
#larson      1         bill                  # <--- example DHCP host entry
test             0        rc          root

1.2 By GUI:
1.2.1. Select “edit config” from left menu list.
Go to “Hosts”.
Click “Add” button.






1.2.2


Here give the required information.
1st Column: hostname i.e. test
(If DNS lookup is enabled, no need to give FQDN).
2nd Column: DHCP, click checkbox (Tick enable) if system IP is not static.
3rd Column: username, give username whose backup has to be taken i.e. rc
4th Column: MoreUsers;
Mention any other user here i.e. root
Click save.
This entry will automatically update in /etc/BackupPC/hosts file.

1.2.3.
Now go to “Host summary” menu from the left.
Added system will be shown.


2. Taking backup of the client system:
2.1 By CLI:
It will take the full backup of the client:
# /usr/share/BackupPC/bin/BackupPC_dump –v –f <client>

It will take the incremental backup of the client:
# /usr/share/BackupPC/bin/BackupPC_dump –v –i <client>


2.2 By GUI:
2.2.1. Go to host summary.
Find the system you want to backup.
Click on it.



2.2.2. Host backup summary page will open.
It will show some backup taking options i.e. start incr backup, start full backup etc
Click button according o your needs.
Click “Start full backup”.


2.2.3. Click on “Start full backup” button.


2.2.4. Request: ok.


3. Restoring backup to client:
3.1. When backup is successful, go to Host backup summary page.
Here, your taken backup will be shown as “0”.
Click on it.


3.2. You taken backup will be shown in tree structure.
Here you can select the files you want to restore.
Click on “Restore selected files”.



3.3. Click on “start restore” button.


3.4. Now, it will show you the files which are going to be restored on the client.
Click “Restore”.


3.5. The following screen showing the success of the restore process.


4. Taking backup from crontab:
First login from “backuppc” user on the server system.
Now, create a cron job:
# crontab –e
07 12 * * 1,2,3,4 /usr/share/BackupPC/bin/BackupPC_dump -v -f test

Explanation:
07: min
12: hour
*: day of month
*: no of month of the year
1,2,3,4: starting four days of the week
/usr…: command for backup
test: client system name

save and exit.

Now, at exactly 12:07 am, the taking backup command will execute from crontab and you will get a success message mail which would be something like this.

From root@backuppc.example.com  Mon Sep 30 12:07:02 2013
Return-Path: <root@backuppc.example.com>
X-Original-To: backuppc
Delivered-To: backuppc@backuppc.example.com
Received: by backuppc.example.com (Postfix, from userid 500)
      id 11B8020A27; Mon, 30 Sep 2013 12:07:01 -0400 (EDT)
From: root@backuppc.example.com (Cron Daemon)
To: backuppc@backuppc.example.com
Subject: Cron <backuppc@backuppc> /usr/share/BackupPC/bin/BackupPC_dump -v -f test
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/backuppc>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=backuppc>
X-Cron-Env: <USER=backuppc>
Message-Id: <20130930160702.11B8020A27@backuppc.example.com>
Date: Mon, 30 Sep 2013 12:07:01 -0400 (EDT)
Status: RO

cmdSystemOrEval: about to system /bin/ping -c 1 -w 3 test
cmdSystemOrEval: finished: got output PING test.example.com (192.168.1.71) 56(84) bytes of data.
64 bytes from test.example.com (192.168.1.71): icmp_seq=1 ttl=64 time=0.104 ms

--- test.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.104/0.104/0.104/0.000 ms

cmdSystemOrEval: about to system /bin/ping -c 1 -w 3 test
cmdSystemOrEval: finished: got output PING test.example.com (192.168.1.71) 56(84) bytes of data.
64 bytes from test.example.com (192.168.1.71): icmp_seq=1 ttl=64 time=0.170 ms

--- test.example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.170/0.170/0.170/0.000 ms

CheckHostAlive: returning 0.170
full backup started for directory / (baseline backup #3)
started full dump, share=/
Running: /usr/bin/ssh -q -x -l root test /usr/bin/rsync --server --sender --numeric-ids --perms --owner --group -D --links --hard-links --times --block-size=2048 --recursive --ignore-times . /
Xfer PIDs are now 3205
xferPids 3205
Got remote protocol 30
Negotiated protocol version 28
Sent include: /root
Sent include: /root/Desktop
Sent include: /root/Desktop/taashee
Sent include: /root/rc
Sent include: /etc
Sent include: /etc/resolv.conf
Sent include: /etc/hosts
Sent exclude: /*
Sent exclude: /root/*
Sent exclude: /root/Desktop/*
Sent exclude: /etc/*
Xfer PIDs are now 3205,3206
xferPids 3205,3206
  create d 555       0/0        4096 .
  create d 755       0/0       12288 etc
  same     644       0/0         305 etc/hosts
  same     644       0/0          98 etc/resolv.conf
  create d 550       0/0        4096 root
  create d 755       0/0        4096 root/Desktop
  create d 755       0/0        4096 root/Desktop/taashee
  same     644       0/0          19 root/Desktop/taashee/taashee2
  same     644       0/0          21 root/Desktop/taashee/taashee3
Done: 4 files, 443 bytes
full backup complete


The taken backup will also be shown in the GUI also.
Check out the time stamp of “Backup# 4”.


Useful links:
Installation using repos:
Installation using tar ball:

1 comment:

  1. Everyone loves what you guys tend to be up too.
    This kind of clever work and coverage! Keep up the excellent works guys I've
    included you guys to my personal blogroll.

    ReplyDelete