Backup with LVM

Backup system in Wialon Pro 1301 can be organized on the basis of LVM (Logical Volume Manager).

Perform the following actions to set up the backup system by yourself:

  1. Install and set up LVM.
  2. Move your database to LVM.
  3. Set up FSTAB.
  4. Do the checkup.

1. LVM Setup

Follow the appropriate instructions depending on whether you use already LVM in your system or not.

If LVM is not used in the system yet

LVM can be used either on the working HDD or on a separate one (preferable way).

Maintain disk partition using the program fdisk in the console.

# fdisk /dev/sdb 

To create LVM partition, type n (creating a new partition), and then p (first partition). Then type 1 to create the primary partition (e.g. /dev/sdb1). Press <enter> to the question about the first cylinder. Press <enter> again to the question about the last cylinder in order to make this partition occupy the rest of free disk space. To change partition type, key in t, then 1 (choose /dev/sdb1) and 8e (Linux LVM). At the end press w to save partition table.

n	<-- create a partition
p	<-- primary partition
1	<-- create the first partition 
default		<--  indicate the first cylinder 
default		<--  indicate the last cylinder
t	<-- change partition type
1	<-- choose the first partition  
8e	<-- Linux LVM
w	<-- save and exit 

Then we need to adjust LVM.

Load the appropriate module:

# modprobe dm-mod 

If the console displayed nothing but an invitation, it is OK. Otherwise, you will need to setup and compile Linux kernel.

Scan the disks for available LVM volume groups:

# vgscan

Make previously created volume groups available:

# vgchange -a y 

Prepare partitions:

pvcreate /dev/sdb1 

Create a volume group with the name of the logical group (in the example — berkleydb):

# vgcreate berkleydb /dev/sdb1 

Create a logical volume:

lvcreate -L10G -nstorage  berkleydb 

Grow logical volume id necessary (in the example the logical volume becomes 5 GB larger):

# lvextend -L+5G /dev/berkleydb/storage 

If LVM is already used in the system

If LVM is already used in the system, you just need to adjust it properly. First, find out the name of the logical volume:

# vgdisplay

The command will display the following:

  VG Name	 		berkleydb
  System ID      
  Format 			lvm2 
  Metadata Areas		1 
  Metadata Sequence No 	14 
  VG Access			read/write 
  VG Status 			resizable 
  MAX LV			0 
  Cur LV			6 
  Open LV			6 
  Max PV			0 
  Cur PV			1 
  Act PV			1 
  VG Size			232,64 GiB 
  PE Size			4,00 MiB 
  Total PE 			59557 
  Alloc PE / Size 		59557 / 232,64 GiB 
  Free  PE / Size		0 / 0 
  VG UUID			ed5U2o-Cnfa-dweY-d99r-dQtz-fgxi-mn7pDo

The name of the logical volume in the example is berkleydb.

Then create a logical partition.

lvcreate -L10G -nstorage  berkleydb 

2. Transfer Database to LVM

Format the logical partition storage (in the example below xfs file system is used):

# mkfs.xfs /dev/berkleydb/storage 

Mount storage partition:

# mkdir /mnt/storage 
# mount /dev/berkleydb/storage /mnt/storage 

Copy your database there:

cp -f /var/lib/wialonb3/storage /mnt 

Unmount storage partition:

# umount /mnt/storage 

Rename the old database (or delete — rm -rf /var/lib/wialonb3/storage) :

# mv /var/lib/wialonb3/storage /var/lib/wialonb3/storage0 

Create an empty directory:

# mkdir /var/lib/wialonb3/storage 

3. FSTAB Setup


# nano /etc/fstab 

Add a string:

/dev/berkleydb/storage	/var/lib/wialonb3/storage	xfs	defaults	1 2 

Close the file (Ctrl + x) and say yes (y) to the question about saving it.

At the end reboot the system:

# reboot 

4. Checkup

After you have performed all steps described above, check the operability of both Wialon and backup system.

Start Wialon and check it for errors. If no errors found, you can proceed with LVM checkup.

Create LVM snapshot LVM. :!: IMPORTANT! Snapshot partition must be no less than database partition.

# lvcreate -L1G -s -n storage_snap /dev/berkleydb/storage 

From this moment, you have a backup copy of your database.

It is recommended to save the snapshot on a disk or to a file using the command dd (to make sure, store it on three mediums). Then in case of fall, you could mount this snapshot or restore the original.

To automate the backup procedure, you can write a script and start it according on schedule using cron.

Was this helpful?
Thank you!