Skip to content
Alexey B. edited this page Jun 16, 2015 · 11 revisions
Barch An open source LVM backup utility for linux based systems. Barch conducts automatic and predefined volume structure recognition. Supports full/incremental backups. Based on duplicity.

Contents:


Installation

Clone files to a temporary folder on target host, then run:

git clone git@github.com:sysboss/Barch.git
./INSTALL

Follow the installer instructions.

Usage and maintenance

Barch v6.1 - LVM backup Solution
Copyright (c) 2015 Alexey Baikov <sysboss[@]mail.ru>

usage:  /usr/local/bin/barch [options] FROM

Options:
  -c|--cleanup             Recovery mode
  -o|--only                Single logical volume to backup
  -h|--help                Help (this info)
  -d|--daemon              Run as a daemon
  --graceful               Graceful stop
  --version                Display version
  --syntax                 Verify config file syntax

Debug Options:
  -v|--verbose             Log to stdout
  --debug                  Debug mode (very verbose)
  --dry-run                Discover only mode

Once configuration complete, check barch.conf syntax with:

barch --syntax

Before the first execution it's highly recommended to create a test volume to prevent any possible damage!

That could be done by running Barch with --only option, to initiate single specified volume backup and --dry-run flag to skip the actual backup process, as shown:

barch --verbose --dry-run --only testLVname

Verbose mode will let you see the flow. --debug flag will show all the command executed.
In case of any failure or warning, see problems resolution section below.

Documentation

Introduction - How it works?

Barch conducts LVM incremental backups by discovering entire hierarchy of each logical volume (such as partitions, file systems and even another LVM structure).

Before backup starts, Barch creates a snapshot of the volume and mount it to a temporary mount point. This method allows the backup tool to sync changes (increments) between the last backup and the current state.

Barch is written in Perl and depends on duplicity, rsync and kpartx. Please make sure this tools installed.

Configuration

Default config file can be found at /etc/barch/barch.conf.
Adjust the following settings according your needs:

Section 1: Global Environment

  [global]
      facility  = deamon
      lock_dir  = /var/lock/barch
      pidfile   = barch.pid
      work_dir  = /var/cache/barch
      report    = /var/cache/barch/status
      listen    = 127.0.0.1
      port      = 3088

facility - syslog facility
report - report file contains information regarding each volume, such as backup status, last backup date etc.
Used by monitor.pl tool to check backups.
listen - bind address and port for the HTTP interface.

Section 2: Default backups behavior

  [default]
      instance  = name
                  # instance name used as prefix.
                  # hostname will be used by default.

      # Handle DRBD
      # check if volume is a drbd device (true/false)
      check_drbd  = false

      # Handle LVM
      # Backup volumes with internal LVM structure (true/false)
      #backup_lvm = false

Notice
Internal volume group could have the same name as the local volume group (such as vg0).
Enable this option carefully to avoid naming conflict.

      # skip filesystem types
      skip_always = swap|luks

skip_always - Pipe separated file system types which will never be backed up.

      # grace period for a new volumes
      # since created (eg. 5M, 12H, 1D, 1W)
      vol_grace = 24H

vol_grace - Wait period before backing up a new volume. 1M is a minimum.

      # volume backup cycle
      # eg. 20M, 1H, 1D, 1W
      vol_cycle = 12H

vol_cycle - Defines the backup cycle for each volume

Section 3: LVM snapshots behavior

  [snapshots]
      # snapshot size
      snap_size = 10G
                  # Snapshot size in MB/GB
                  # used to store changed since the snapshot was taken
      max_snap  = 90
                  # Abort backup if snapshot is full (in %)

Section 4: DRBD Devices

This section is relevant for DRBD only. If check_drbd set to true.

[drbd]
    # drbd states to backup Primary/Secondary/any
    drbd_state  = any
    # connection states to backup Connected/Disconnected/any
    drbd_conn   = Connected
    # device status UpToDate/Outdated/DUnknown/any
    drbd_status = UpToDate

Notice params values are case sensitive. Use only allowed values.

# Remote cluster member
# with HTTP Interface enabled
#[cluster]
#    member      = x.x.x.2
#    port        = 3088
#    # if cluster member unreachable
#    # abort/continue
#    on_error    = abort

Uncomment this section to backup DRBD cluster in parallel from both nodes.
Remember to set source_mismatch to true in duplicity section below.
member - second node IP address
port - Barch instance port
on_error - Defines cluster behaviour if there is no connection between the nodes. set continue - to do backups even if the second node is unreachable.

Section 5: duplicity

  [duplicity]
      # Perform a full backup every
      full              = 1W
      # Number of retries to make on errors before giving up
      retries           = 3
      # Delete all backup sets older than the given time
      remove_older_than = 2W
      # public GPG key ID
      encrypt_key       = ********
      encrypt_pass      = ****************************************

encrypt_key - is the gpg key 'sub' taken from gpg --list-keys
encrypt_pass - password of the gpg key

See GPG how-to: GPG Tutorial

      # Destination backup folder
      remote_snap_dir   = rsync://barch@backupserv//usr/local/backup
                          # ftp://user[:password]@other.host[:port]/some_dir
                          # scp://user[:password]@other.host[:port]/some_dir
                          # file:///some_dir

      # Change the volume size to number Mb. Default is 250Mb.
      volsize           = 250

      # --allow-source-mismatch parameter (allow/deny)
      source_mismatch   = deny
                          # Allow this if you volume is a DRBD member
                          # to allow any host to backup it

      maxtransfertime   = 2H

maxtransfertime - is visibility feature only. Indicates maximum time for single chunk to be collected and transferred to backup server. Default is 2H.

Section 6: Storage

    [ssh]
        # ssh credentials to remote storage
        user     = backup
        server   = x.x.x.x
        path     = /usr/local/backup

SSH credentials used to execute command and create sub-folders on the backup server.

Section 7: Advanced settings

  [advanced]
      # parallel execution
      max_forks = 2
      cpu_nice  = CPU usage priority
                  Can range from -20 to 19, where lower numbers mean higher priority
      io_nice   = IO usage priority
                  Can range from 0 to 7, where lower numbers mean higher priority
      custom    = Custom specifications file location
                  Will be described later

Custom definitions

This config file should contain custom specifications for more advanced filesystem types, such as ocfs2.
Example below, shows how custom.conf file can be used to define OCFS2 (Oracle Cluster File System 2) backup procedure.

    [vg0.ocfs]
        backup     = true
        fs_type    = ocfs2
        mount_opt  = -o ro,localflocks
        pre_mount  = tunefs.ocfs2 -y -L ocfs_bsnap --cloned-volume /dev/vg0/ocfs_bsnap
        post_mount = none

This config also used to exclude volumes from backup procedure by setting backup = false under relevant lv name.

backup     - flag defines if LV should be backed up. If set to false, Barch will skip this LV.  
             No other flags required in this case.
fs_type    - defines filesystem type (eg. ext4, ntfs, ocfs).  
mount_opt  - default Linux mount command parameters.  
pre_mount  - pre-mount script file path. Set 'none' if not required.  
pre_backup - this script runs before snapshot creation. Optional.

Start automatic backups

Barch designed to run as a daemon (--daemon option).
Init script is also included.

Monitoring

Backup monitoring script can be found at /etc/barch/monitor.pl
Usage:

./monitoring.pl [OPTIONS ...]

Options:
  -h|--help                Help (this info)
  -v|--verbose             Verbose mode

  -W|--warn                Warning threshold (default:  18h)
  -C|--crit                Critical threshold (default:  1d)

By default, will monitor backup jobs status and verify that every volume was backed up in time.

FAQ: Problems resolution

Fell free to contact me if you have any questions. Answers will be published here.