Bacula Backup Client – Part 2


In previous post we have seen how to setup the bacula backup server. Now we need to test to take the backup of the one linux server.

File Daemon server:
Hostname: client.lguru.local
IPAddress: 192.168.1.174
OS: CentOS 6.9

Step 1: Install bacula backup agent packages

[root@client ~]# yum -y install bacula-client bacula-console

Step 2: Configure File daemon

[root@client ~]# vi /etc/bacula/bacula-fd.conf
Director {
Name = bacula-dir
Password = "password" # Give Director Daemon password in line 15
}
# line 22-26: delete them
#Director {
# Name = bacula-mon
# Password = "@@MON_FD_PASSWORD@@"
# Monitor = no
#}

Step 3: Start the bacula client service

[root@client ~]# /etc/init.d/bacula-fd start
Starting bacula-fd: Error: Default password in config [FAILED]

If you get above error after step 2 then follow the below changes

[root@client ~]# vi /etc/init.d/bacula-fd

#Comment out the Line 36-46
#checkconf() {
# Check if we still have our @@PLACEHOLDERS@@ in the config.
# If yes, refuse to start, the user has never touched the config.
# grep -q '_PASSWORD@@' $CONFIG
# if [ $? -eq 0 ]; then
# echo -n "Error: Default password in config"
# echo_failure
# echo
# exit 6
# fi
#}

# Comment out Line no 53

start() {
[ "$EUID" != "0" ] && exit 4


echo -n "Starting $prog: "
# checkconf
daemon $prog $OPTS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}

[root@client ~]# /etc/init.d/bacula-fd start
Starting bacula-fd: [ OK ]

[root@client ~]# chkconfig bacula-fd on


[root@client ~]# netstat -anp | grep 9102
tcp 0 0 0.0.0.0:9102 0.0.0.0:* LISTEN 1550/bacula-fd

[root@client ~]# vi /etc/bacula/bconsole.conf
Director {
Name = bacula-dir
DIRport = 9101
address = mgmtsrv.lguru.local # Director Daemon hostname
Password = "password" # Director Daemon password
}

Copy some file to /opt file system to check bacula director server backup these files

[root@client ~]# cp /etc/passwd /etc/shadow /etc/group /opt/
[root@client ~]# ls -l /opt/
total 12
-rw-r--r-- 1 root root 456 Sep 13 03:18 group
-rw-r--r-- 1 root root 924 Sep 13 03:18 passwd
---------- 1 root root 614 Sep 13 03:18 shadow

Bacula Backup Server – Part 1


Bacula is an Open Source, computer programs that permit system administrator to manage backup, recovery, and verification of computer data across a network of computers of different kinds. Bacula is relatively easy to use and very efficient, while offering many advanced storage management features that make it easy to find and recover lost or damaged files. In technical terms, it is an Open Source, network based backup program.

Director & Storage server:
Hostname: mgmtsrv.lguru.local
IPAddress: 192.168.1.173
OS: CentOS 6.9

Step 1: Install Bacula director and storage daemon packages

[root@mgmtsrv ~]# yum -y install bacula-director-mysql bacula-storage-mysql bacula-console mysql-server mysql-devel

Step 2: Configure Bacula MySQL database

Set the mysql root password

[root@mgmtsrv ~]# mysqladmin -u root password password

Enter the mysql root password for below database configuration

[root@mgmtsrv ~]# /usr/libexec/bacula/grant_mysql_privileges -p
Enter password:
Privileges for user bacula granted on database bacula.

[root@mgmtsrv ~]# /usr/libexec/bacula/create_mysql_database -p
Enter password:
Creation of bacula database succeeded.

[root@mgmtsrv ~]# /usr/libexec/bacula/make_mysql_tables -p
Enter password:
Creation of Bacula MySQL tables succeeded.

Set the password for bacula database.

[root@mgmtsrv ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password for bacula=password('password');
Query OK, 0 rows affected (0.00 sec)

mysql> set password for bacula@localhost=password('password');
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

Step 3: Configure Bacula director

[root@mgmtsrv ~]# vi /etc/bacula/bacula-dir.conf

[........]

Director {
Name = bacula-dir
DIRport = 9101
QueryFile = "/usr/libexec/bacula/query.sql"
WorkingDirectory = "/var/spool/bacula"
PidDirectory = "/var/run"
Maximum Concurrent Jobs = 1
Password = "password" # Password to connect Director Daemon Line 22
Messages = Daemon
}

FileSet {
Name = "Full Set"
Include {
Options {
signature = MD5
Compression = GZIP # Backup Compression method Line 91
}
File = /opt # Backup target on Client Line 110
}

Client {
Name = bacula-fd
Address = client.lguru.local # Client Hostname Line 158
FDPort = 9102
Catalog = MyCatalog
Password = "password" # Password to connect Client Line 161
File Retention = 30 days
Job Retention = 6 months
AutoPrune = yes
}

Storage {
Name = File
Address = mgmtsrv.lguru.local # Storage Daemon hostname Line 187
SDPort = 9103
Password = "password" # Storage Daemon password
Device = FileStorage
Media Type = File
}

Catalog {
Name = MyCatalog
# Uncomment the following line if you want the dbi driver
# dbdriver = "dbi:sqlite3"; dbaddress = 127.0.0.1; dbport =
dbname = "bacula"; dbuser = "bacula"; dbpassword = "password" # Bacula MySQL password Line 236
}

# line 312-316: make them comments
#Console {
# Name = bacula-mon
# Password = "@@MON_DIR_PASSWORD@@"
# CommandACL = status, .status
#}

[root@mgmtsrv ~]# vi /usr/libexec/bacula/make_catalog_backup.pl
# Add below line in line no 108
exec("HOME='$wd' mysqldump -f -u$args{db_user} -p$args{db_password} --opt $args{db_name} > '$wd/$args{db_name}.sql'");

Step 4: Bacula Storage Daemon configuration

[root@mgmtsrv ~]# vi /etc/bacula/bacula-sd.conf
Director {
Name = bacula-dir
Password = "password" # Storage Daemon password Line 26
}


# line 33-37: make them comments
#Director {
# Name = bacula-mon
# Password = "@@MON_SD_PASSWORD@@"
# Monitor = yes
#}

Step 5: Bacula console configuration

[root@mgmtsrv ~]# vi /etc/bacula/bconsole.conf
Director {
Name = bacula-dir
DIRport = 9101
address = mgmtsrv.lguru.local # Director Daemon hostname
Password = "password" # Director Daemon password
}

Step 6: Start and test the connectivity

[root@mgmtsrv ~]# /etc/init.d/bacula-dir start
Starting bacula-dir: [ OK ]

[root@mgmtsrv ~]# /etc/init.d/bacula-sd start
Starting bacula-sd: [ OK ]

[root@mgmtsrv ~]# chkconfig bacula-dir on
[root@mgmtsrv ~]# chkconfig bacula-sd on

[root@mgmtsrv ~]# netstat -anp | grep 9101
tcp 0 0 0.0.0.0:9101 0.0.0.0:* LISTEN 8414/bacula-dir

[root@mgmtsrv ~]# netstat -anp | grep 9103
tcp 0 0 0.0.0.0:9103 0.0.0.0:* LISTEN 8388/bacula-sd

Backup and Restore LVM partition using Snapshot


A snapshot is the state of a system at a particular point in time and it is also called as photography. LVM also have the feature of snapshot. So that we can easily take the backup of current logical partition and moved to somewhere.

It is mainly used in live production environment, if you need to clone the exact copy of production environment then you will prefer this method.

Here we are going to take a backup of one logical volume and restore it in another machine on same network.

Step 1: Careate a new partition

[root@server ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (265-652, default 265):
Using default value 265
Last cylinder, +cylinders or +size{K,M,G} (265-652, default 652): +1G

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Step 2: Run “partprobe” command to inform the OS/Kernel of partition table changes

[root@server ~]# partprobe

Step 3: LVM setup for taking snapshot for existing logical partition

Create the physical volume (PV)

[root@server ~]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created

Extend Volume Group (VG)

[root@server ~]# vgextend vg01 /dev/sdb3
Volume group "vg01" successfully extended

[root@server ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 1 2 0 wz--n- 19.53g 2.88g
vg01 3 1 0 wz--n- 3.02g 2.54g

Creating snapshot of existing partition

[root@server ~]# lvcreate -L 1G -s -n lv_snap /dev/vg01/lv01
Logical volume "lv_snap" created

Note: Snapshot size should be larger than actual current size of logical volume.

[root@server ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 1 2 0 wz--n- 19.53g 2.88g
vg01 3 2 1 wz--n- 3.02g 1.54g

[root@server ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
LogVol00 VolGroup00 -wi-ao--- 14.65g
LogVol01 VolGroup00 -wi-ao--- 2.00g
lv01 vg01 owi-a-s-- 500.00m
lv_snap vg01 swi-aos-- 1.00g lv01 0.00

[root@server ~]# mkdir /snapdata

Check whether all datas from existing logical volume (/dev/vg01/lv01) copied to lvm snapshot (/dev/vg01/lv_snap)

[root@server ~]# mount /dev/vg01/lv_snap /snapdata
[root@server ~]# cd /snapdata/
[root@server snapdata]# ls
fstab lost+found passwd

So above commands shows that the datas are copied to the new logical volume. Now we need to compress and send this backup to other machine.

[root@server ~]# dd if=/dev/vg01/lv_snap | gzip > /data/lvdata.gz
1024000+0 records in
1024000+0 records out
524288000 bytes (524 MB) copied, 8.07202 s, 65.0 MB/s

Transfer the backup file to client machine

[root@server ~]# scp -r /data/lvdata.gz client:/tmp

Client Side:

Step 1: Create PV, VG, LV

[root@client ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

[root@client ~]# vgcreate vgclient /dev/sdb1
Volume group "vgclient" successfully created

[root@client ~]# lvcreate -L 500M -n restoredata /dev/vgclient
Logical volume "restoredata" created

Step 2: Restore the datas to current lvm

[root@client ~]# gzip -dc /tmp/lvdata.gz | dd of=/dev/vgclient/restoredata
1024000+0 records in
1024000+0 records out
524288000 bytes (524 MB) copied, 63.7254 s, 8.2 MB/s

Execute the below command to make the lvm changes reflect

[root@client ~]# pvscan && vgscan && lvscan

Step 3: Mount the partition

[root@client ~]# mkdir /backup
[root@client ~]# mount /dev/vgclient/restoredata /backup
[root@client ~]# cd /backup
[root@client backup]# ls
fstab lost+found passwd

That’s it!! Enjoy..

LuckyBackup on Linux – An OpenSource Tool


Lucky Backup is a very user-friendly backup tool that will have you backing up remotely or locally in no time.

Follow the below steps to install and configure lucky backup on your environment.

Dependency packages

libqtcore4 (>= 4.4)
libqtgui4 (>= 4.4)
libc6 or glibc (>= 2.7-1)
libgcc1 (>= 4.1.1)
libstdc++6 (>= 4.1.1)
rsync
Fedora users, install “qt-x11” & “qt” packages for required libraries.
For a full compilation from source you will also need the qt4 (libqt4-dev or libqt4-devel or qt4-devel) development (>=4.4) package.

Download and install

Download the lucky backup rpm from below link according to your distribution

http://luckybackup.sourceforge.net/download.html

I used CentOS distribution for backup server.

# rpm -ivh luckybackup-0.4.8-1.x86_64.rpm

The above command executes the installation process. After luckybackup installed open up a terminal from X-window and enter the command “luckybackup”

# luckybackup

This command will open up the user-friendly dialogue window, there you can easily add/remove/edit the backup jobs.

Local Backup:

Step 1: First we need to create a profile for backup. You can create multiple profiles which would allow you to have multiple backup that will be run at different times.

Step 2: Click Add button, in that window you will need full out the necessary information. ie., Profile Name, Type of backup, Source to take the data, Destination – where to store the data.

Step 3: Click Validate button to check our backup settings are good to run.

Step 4: Select the Created Profile, click Schedule and then click the Add button. In that window, set the time when to execute this backup profile.

Step 5: Click Ok and schedule is set. After that click the crontIT button which will automatically create a cron job for each profile.

Remote Backup:

Luckybackup is also used to take the remote machine. For this we need to do the same steps as above and additionally some steps are required.

Click Add button, enter the necessary information and click Advance button. From the Advanced properties click Remote tab and enter remote server details.

Enter Destination, User and Host details, select the ssh checkbox.

Click Validate button and checks out Okay and you are ready to run the job.

While running the remote backup, you will be asked to enter the user password for each time. In order to avoid this problem, we are going to use ssh passwordless method.

Follow this on Local machine.

# ssh-keygen -t dsa

The above command will generate public keys. After that, copy that keys to destination server (luckybackup)

# cd .ssh
# ssh-copy-id -i id_dsa.pub remoteserver_username@destination_hostname

That’s it. Run the job and check everything looks fine.

Enjoy. Great day 🙂