备份/恢复系统BAREOS的设置

本文将介绍如何设置bareos系统,将分别介绍Bareos系统主机设置(含Director Daemon、Storage Daemon和Storage Daemon)、客户机安装/设置和系统集成测试。

在介绍设置前,我们先简单介绍一下bareos系统架构,方便大家理解。

备份/恢复系统BAREOS的安装、设置和使用(二)-LMLPHP

管理终端:
bconsole:全功能CLI管理终端。
WebUI:只能用于备份和恢复,同时包含基于Web的CLI界面。

管理服务(Director Daemon):
运行在bareos管理机上,包含全部管理功能、CLI管理服务、WebUI后台支持、目录(catalog)数据库支持等。

存储服务(Storage Daemon):
运行在bareos管理机上,支持不同的物理存储媒体(如硬盘存储系统、磁带存储系统等),管理数据的读取和存储。

文件服务(File Daemon):
运行在客户机上,管理本地文件的备份和恢复。

储存媒体:
物理存储媒体(如硬盘存储系统、磁带存储系统等)。


Bareos系统设置

配置Bareos存储服务(Storage Daemon)模块

Bareos存储服务(Storage)模块为bareos系统提供数据存储服务模块。它的配置文件位于/etc/bareos/bareos-sd.d目录下。

root@bareos:/etc/bareos/bareos-sd.d# ls -l
total 16
drwxr-x--- 2 bareos bareos 4096 Sep 16 11:37 device
drwxr-x--- 2 bareos bareos 4096 Sep 16 11:37 director
drwxr-x--- 2 bareos bareos 4096 Sep 16 11:44 messages
drwxr-x--- 2 bareos bareos 4096 Sep 16 11:43 storage
root@bareos:/etc/bareos/bareos-sd.d#

配置Storage的存储设备

device下放的是存储媒体配置文件,bareos系统是基于文件的备份/恢复系统,device下只有一个配置文件FileStorage.conf。

可能的FileStorage.conf如下:

# HDD 存储设备
Device {
  Name = FileStorage                  # 设备名称
  Media Type = File                   # 类型,bareos是基于文件的备份/恢复系统,类型永远是文件
  Archive Device = /bareos/hdd        # Ubuntu下的备份文件目录(或mount point)
  LabelMedia = yes;                   # lets Bareos label unlabeled media
  Random Access = yes;                # 可随机读写
  AutomaticMount = yes;               # 自动加载
  RemovableMedia = no;                # 媒体介质不可移除
  AlwaysOpen = yes;                   # 总是打开
}

# 磁带存储设备
Device {
  Name = TapeStorage                  # 设备名称
  Media Type = File                   # 类型,bareos是基于文件的备份/恢复系统,类型永远是文件
  Archive Device = /bareos/tape       # Ubuntu下的mount point
  LabelMedia = yes;                   # lets Bareos label unlabeled media
  Random Access = no;                 # 不能随机读写
  AutomaticMount = no;                # 不自动加载
  RemovableMedia = yes;               # 媒体介质可移除
  AlwaysOpen = no;                    # 按需打开
}

在上述配置文件中,我们配置了二种存储设备,分别是硬盘和磁带。在配置时,请注意被配置存储设备的物理属性。硬盘类的存储设备是可随机读写,磁带类的是不可随机读写。
现在公司一般很少配磁带备份,我们的备份方案是:在/bareos/hdd下挂载SAN设备,然后通过rsync将/bareos/hdd目录下的内容同步到远程SAN上,从而保证数据的安全。

实例中的FileStorage.conf文件:

/etc/bareos/bareos-sd.d/device/FileStorage.conf

# HDD 存储设备
Device {
  Name = FileStorage                  # 设备名称
  Media Type = File                   # 类型,bareos是基于文件的备份/恢复系统,类型永远是文件
  Archive Device = /bareos/hdd        # Ubuntu下的mount point
  LabelMedia = yes;                   # lets Bareos label unlabeled media
  Random Access = yes;                # 可随机读写
  AutomaticMount = yes;               # 自动加载
  RemovableMedia = no;                # 媒体介质不可移除
  AlwaysOpen = yes;                   # 总是打开
}

配置Storage的ACL
director下有二个配置文件bareos-dir.confbareos-mon.conf,分别用于管理director和monitor对storage模块的授权。

/etc/bareos/bareos-sd.d/director/bareos-dir.conf

Director {
  Name = bareos-dir                                             # 名字
  Password = "JgwtSYloo93DlXnt/cjUfPJIAD9zocr920FEXEV0Pn+S"     # 密码
  Description = "允许操作此storage的Director设置"
}

/etc/bareos/bareos-sd.d/director/bareos-mon.conf

Director {
  Name = bareos-mon
  Password = "4wdzVcvZAFgTz+IWlB4C5hd09czTXhsAd8SnZQ1VZn4X"
  Monitor = yes
  Description = "允许读取此storage状态的Monitor设置"
}

monitor是bareos的GUI监视程序。

配置 storage 相关信息服务

/etc/bareos/bareos-sd.d/messages/Standard.conf

Messages {
  Name = Standard
  Director = bareos-dir = all # bareos-dir:发送信息到bareis-dir,all:所有信息
  # mailcommand =  # 可执行命令或脚本
  # operatorcommand = # 可执行命令或脚本
  Description = "Send all messages to the Director."
  # 可用参数
  # %% = %
  # %c = Client’s name
  # %d = Director’s name
  # %e = Job Exit code (OK, Error, ...)
  # %h = Client address
  # %i = Job Id
  # %j = Unique Job name
  # %l = Job level
  # %n = Job name
  # %r = Recipients
  # %s = Since time
  # %t = Job type (e.g. Backup, ...)
  # %v = Read Volume name (Only on director side)
  # %V = Write Volume name (Only on director side)
}

配置 storage 相关特性或功能

Storage {
  Name = bareos-sd
  Maximum Concurrent Jobs = 20

  # remove comment from "Plugin Directory" to load plugins from specified directory.
  # if "Plugin Names" is defined, only the specified plugins will be loaded,
  # otherwise all storage plugins (*-sd.so) from the "Plugin Directory".
  #
  # Plugin Directory = /usr/lib/bareos/plugins
  # Plugin Names = ""
}

一般情况下,我们只需要修改FileStorage.conf配置文件中的Archive Device,默认的Archive Device/var/lib/bareos/storage,默认的bareos-sd配置能满足一般需求。

修改bareos-sd的配置后,必须重启bareos-sd。在重启bareos-sd前,请首先使用bareos-sd -t -v检查bareos-sd配置文件。如bareos-sd -t -v没有任何输出,说明配置文件没有任何语法问题,可以重启bareos-sd


配置Bareos管理(Director)模块

Bareos管理(Director)模块为bareos系统管理模块。它的配置文件位于/etc/bareos/bareos-dir.d目录下。

root@bareos:/etc/bareos/bareos-dir.d# ls -l
total 48
drwxr-x--- 2 bareos bareos 4096 Sep 11 09:13 catalog
drwxr-x--- 2 bareos bareos 4096 Sep 11 09:13 client
drwxr-x--- 2 bareos bareos 4096 Sep 11 11:08 console
drwxr-x--- 2 bareos bareos 4096 Sep 15 20:42 director
drwxr-x--- 2 bareos bareos 4096 Sep 11 09:13 fileset
drwxr-x--- 2 bareos bareos 4096 Sep 11 09:13 job
drwxr-x--- 2 bareos bareos 4096 Sep 11 09:13 jobdefs
drwxr-x--- 2 bareos bareos 4096 Sep 18 17:18 messages
drwxr-x--- 2 bareos bareos 4096 Sep 11 09:13 pool
drwxr-x--- 2 bareos bareos 4096 Sep 15 20:45 profile
drwxr-x--- 2 bareos bareos 4096 Sep 11 09:13 schedule
drwxr-x--- 2 bareos bareos 4096 Sep 11 09:13 storage
root@bareos:/etc/bareos/bareos-dir.d#

配置文件的文件名可任意,但必须以.conf结尾。

目录(catalog)数据库链接方式配置文件
/etc/bareos/bareos-dir.d/MyCatalog.conf

Catalog {
  Name = MyCatalog          # catalog名字
  dbdriver = mysql          # 使用MySQL驱动(兼容MariaDB)
  dbname = bareos           # 数据库名
  dbuser = bareos           # 该数据库之用户名
  dbpassword = bareos       # 该用户之密码
}

该文件在安装bareos-mysql时已被初始化,一般情况下无需修改。

客户端(File Daemon)配置文件
/etc/bareos/bareos-dir.d/client/clientname-fd.conf

下面是bareos服务器的默认File Daemon配置文件:

Client {
  Name = bareos-fd                                                   # Director中使用的客户端名字
  Description = "Client resource of the Director itself."            # 解释
  Address = localhost                                                # 客户端FQDN或IP地址
  Password = "QGSqraVyf7kQfpdTxv+j/h27nesW7ypmGP5wLPLXltE9"          # 密码
}

配置客户端可以直接建立/修改配置文件,也可以通过bconsole来完成。

下面是使用bconsole建立客户端示例:
root@bareos:~# bconsole
Connecting to Director localhost:9101
1000 OK: bareos-dir Version: 17.2.4 (21 Sep 2017)
Enter a period to cancel a command.
*configure add client name=lscms-fd address=lscms.lswin.cn password=lscmsFdPasswd

我们可以在/etc/bareos/bareos-dir.d/client下见到新的客户端配置文件lscms-fd.conf。内容为:

Client {
  Name = lscms-fd
  Address = lscms.lswin.cn
  Password = lscmsFdPasswd
}

终端(console)配置文件
在该目录(/etc/bareos/bareos-dir.d/console)下有二个配置文件:admin.conf 和 bareos-mon.conf
/etc/bareos/bareos-dir.d/console/admin.conf:Web GUI 配置文件
/etc/bareos/bareos-dir.d/console/bareos-mon.conf:Bareos 托盘监测配置文件

Web GUI 配置文件 /etc/bareos/bareos-dir.d/console/admin.conf

Console {
  Name = admin
  Password = pwd111111
  Profile = webui-admin             # 指明是为WebGUI,该名字必须是webui-admin
}

托盘监测配置文件/etc/bareos/bareos-dir.d/console/bareos-mon.conf

Console {
  Name = bareos-mon
  Description = "Restricted console used by tray-monitor to get the status of the director."
  Password = "8ipdQxiufhgskdNWk4ydvVWZfXGa9SmVBG690X+Mh9Ph"
  CommandACL = status, .status             # 只有 status 命令或 .status命令被授权
  JobACL = *all*                           # 所有任务都被授权
}

一般情况下,这些文件无需修改。

控制端(Director)配置文件
/etc/bareos/bareos-dir.d/director/bareos-dir.conf

Director {                                                          # 配置控制端
  Name = bareos-dir
  QueryFile = "/usr/lib/bareos/scripts/query.sql"
  Maximum Concurrent Jobs = 10                                      # 同时可执行10个任务,更多任务需排队
  Password = "LiYwqsOHIEhfjPts14Pvenk9YMfmWEN81PxugpdOHt3C"         # 控制端 password
  Messages = Daemon                                                 # 只接受驻留任务消息
  Auditing = yes                                                    # 开启审计

  # Enable the Heartbeat if you experience connection losses
  # Heartbeat Interval = 1 min                                      # 如Director不在本地,可能需要开启
}

一般情况,无需修改。

备份文件组(fileset)配置文件
/etc/bareos/bareos-dir.d/fileset/*.conf

该目录下有一系列配置文件,这些文件用于定义如何备份一组文件(fileset)。
这是最重要的配置之一,而又只能通过终端手工配置,所以我们在此将详细介绍。

一、备份Linux电脑

FileSet {                                     # fileset 开始标志
  Name = "LinuxAll"                           # 该 fileset 的名字,这个名字会在备份任务中使用
  Description = "备份所有系统,除了不需要备份的。"
  Include {                                   # 备份中需要包含的文件
    Options {                                 # 选项
      Signature = MD5                         # 每个文件产生MD5校验文件
      One FS = No                             # 所有指定的文件(含子目录)都会被备份
      # One FS = Yes                          # 指定的文件(含子目录)如不在同一文件系统下不会被备份
      #
      # 需要备份的文件系统类型列表
      FS Type = btrfs                         # btrfs 文件系统需要备份
      FS Type = ext2                          # ext2 文件系统需要备份
      FS Type = ext3                          # ext3 文件系统需要备份
      FS Type = ext4                          # ext4 文件系统需要备份
      FS Type = reiserfs                      # reiserfs 文件系统需要备份
      FS Type = jfs                           # jfs 文件系统需要备份
      FS Type = xfs                           # xfs 文件系统需要备份
      FS Type = zfs                           # zfs 文件系统需要备份
    }
    File = /                                  # 所有目录和文件
  }
  # 定义不需要备份的文件和目录
  Exclude {                                   # 备份中不应该包含的文件
    # 无需备份文件/目录列表
    File = /var/lib/bareos                    # /var/lib/bareos 下放的是bareos的临时文件
    File = /var/lib/bareos/storage            # /var/lib/bareos/storage 下放的是备份文件
    File = /proc                              # /proc 无需备份
    File = /tmp                               # /tmp无需备份
    File = /var/tmp                           # /var/tmp无需备份
    File = /.journal                          # /.journal 无需备份
    File = /.fsck                             # /.fsck无需备份
  }
}

一般情况下,您只需要修改该文件来达到不同的备份需求。如子备份/home目录:

......
      FS Type = xfs                           # xfs 文件系统需要备份
      FS Type = zfs                           # zfs 文件系统需要备份
    }
    File = /home                              # /home下的所有目录和文件
  }
  # 定义不需要备份的文件和目录
  Exclude {                                   # 备份中不应该包含的文件
    # 无需备份文件/目录列表
    File = /var/lib/bareos                    # /var/lib/bareos 下放的是bareos的临时文件
......

二、备份Windows电脑

FileSet {
  Name = "Windows电脑备份[A-Z]:/QMDownload"
  Enable VSS = yes                                  # 当YES时,当文件正在被写时也能被备份;如NO,被写文件不会被备份
  Include {
    Options {
      Signature = MD5
      Drive Type = fixed                            # 只备份固定磁盘
      IgnoreCase = yes                              # 忽略字母的大小写
      WildFile = "[A-Z]:/pagefile.sys"              # 指定文件:从磁盘A到Z下的/pagefile.sys
      WildDir = "[A-Z]:/RECYCLER"                   # 指定文件:从磁盘A到Z下的
      WildDir = "[A-Z]:/$RECYCLE.BIN"               # 指定文件:从磁盘A到Z下的
      WildDir = "[A-Z]:/System Volume Information"  # 指定文件:从磁盘A到Z下的
      Exclude = yes                                 # 另一种方式指定不备份上述指定文件
    }
    File ="C: / QMDownload "                    # 备份目录C:/QMDownload
  }
}

如您需要备份不同的文件,只需要修改 File =C: /QMDownload 即可。
如:
File = D:/Data # 备份D:/Data目录

用户可根据不同的需求来定义不同的fileset。

三、下面我们定义一个用于测试任务的fileset(TestSet

    FileSet {                                     # fileset 开始标志
      Name = "TestSet"                            # 该 fileset 的名字,这个名字会在备份任务中使用
      Description = "备份/usr/sbin(用于测试任务)"
      Include {                                   # 备份中需要包含的文件
        Options {                                 # 选项
          Signature = MD5                         # 每个文件产生MD5校验文件
          One FS = No                             # 所有指定的文件(含子目录)都会被备份
          # One FS = Yes                          # 指定的文件(含子目录)如不在同一文件系统下不会被备份
          #
          # 需要备份的文件系统类型列表
          FS Type = btrfs                         # btrfs 文件系统需要备份
          FS Type = ext2                          # ext2 文件系统需要备份
          FS Type = ext3                          # ext3 文件系统需要备份
          FS Type = ext4                          # ext4 文件系统需要备份
          FS Type = reiserfs                      # reiserfs 文件系统需要备份
          FS Type = jfs                           # jfs 文件系统需要备份
          FS Type = xfs                           # xfs 文件系统需要备份
          FS Type = zfs                           # zfs 文件系统需要备份
        }
        File = /"/usr/sbin"                       # 所有目录和文件
      }
    }

因为没有不需要备份的文件,所以我们移除了Exclude。

备份任务定义(jobdefs)配置文件
/etc/bareos/bareos-dir.d/jobdefs/*.conf

实例:测试任务(TestJob)

JobDefs {
  Name = "TestJob"                                          # 测试任务
  Type = Backup                                             # 类型:备份(Backup)
  Level = Incremental                                       # 方式:递进(Incremental)
  Client = bareos-fd                                        # 被备份客户端:bareos-fd (在Client中定义)
  FileSet = "TestSet"                                       # 备份文件组:TesetSet (在FileSet中定义)
  Schedule = "WeeklyCycle"                                  # 备份周期:WeeklyCy(在schedule中定义)
  Storage = File                                            # 备份媒体: File(在Storage中定义)
  Messages = Standard                                       # 消息方式:Standard(在Message中定义)
  Pool = Incremental                                        # 存储池:Incremental(在pool中定义)
  Priority = 10                                             # 优先级:10
  Write Bootstrap = "/var/lib/bareos/%c.bsr"                #
  Full Backup Pool = Full                  # Full备份,使用 "Full" 池(在storage中定义)
  Differential Backup Pool = Differential  # Differential备份,使用 "Differential" 池(在storage中定义)
  Incremental Backup Pool = Incremental    # Incremental备份,使用 "Incremental" 池(在storage中定义)
}

任务(job)配置文件
/etc/bareos/bareos-dir.d/job/*.conf
配置备份任务:实例:在客户端bareos-fa上运行TestJob(备份/usr/sbin下的所有文件)

Job {
  Name = "backup-test-on-bareos-fd"              # 任务名
  JobDefs = "TestJob"                            # 使用已定义的备份任务TestJob (在jobdefs中定义)
  Client = "bareos-fd"                           # 客户端名称: bareos-fd(在client中定义)
}

存储媒体(storage)配置文件
/etc/bareos/bareos-dir.d/storage/*.conf

Storage {
  Name = File
  Address = bareos                # director-sd名字,使用FQDN (不要使用 "localhost" ).
  Password = "JgwtSYloo93DlXnt/cjUfPJIAD9zocr920FEXEV0Pn+S"
  Device = FileStorage            # 在bareos-sd中定义
  Media Type = File
}

注意:Device是在Bareos的Storage Daemon中定义的,Device的名字和Media Type必须一致。

这是在安装时自动生成的存储媒体配置文件,如使用本地硬盘文件系统做存储媒体,不需要做任何修改。

存储池(pool)配置文件
/etc/bareos/bareos-dir.d/pool/*.conf
一般情况下,我们需要四个存储池。分别是:
Full:用于完整备份【Full:备份所有文件】
Incremental:用于递增备份【Incremental:备份所有状态变化的文件】
Differential:用于差异备份【Differential:备份所有修改了(modified标志变化)的文件】
Scratch:当系统找不到需要的Volume时,自动使用该存储池。
Scratch名称不可修改,其他存储池名字可修改。
下面是系统安装时生成的pool定义文件,一般情况下无需修改。

Differential.conf

Pool {
  Name = Differential
  Pool Type = Backup
  Recycle = yes                       # Bareos 自动回收重复使用 Volumes(Volume备份文件标记)
  AutoPrune = yes                     # 自动清除过期的Volumes
  Volume Retention = 90 days          # Volume有效时间
  Maximum Volume Bytes = 10G          # Volume最大尺寸
  Maximum Volumes = 100               # 单个存储池允许的Volume数量
  Label Format = "Differential-"      # Volumes 将被标记为 "Differential-<volume-id>"
}

Full.conf


Pool {
  Name = Full
  Pool Type = Backup
  Recycle = yes                       # Bareos 自动回收重复使用 Volumes(Volume备份文件标记)
  AutoPrune = yes                     # 自动清除过期的Volumes
  Volume Retention = 365 days         # Volume有效时间
  Maximum Volume Bytes = 50G          # Volume最大尺寸
  Maximum Volumes = 100               # 单个存储池允许的Volume数量
  Label Format = "Full-"              # Volumes 将被标记为 "Differential-<volume-id>"
}

Incremental.conf

Pool {
  Name = Incremental
  Pool Type = Backup
  Recycle = yes                       # Bareos 自动回收重复使用 Volumes(Volume备份文件标记)
  AutoPrune = yes                     # 自动清除过期的Volumes
  Volume Retention = 30 days          # Volume有效时间
  Maximum Volume Bytes = 1G           # Volume最大尺寸
  Maximum Volumes = 100               # 单个存储池允许的Volume数量
  Label Format = "Incremental-"       # Volumes 将被标记为 "Differential-<volume-id>"
}

Scratch.conf

Pool {
  Name = Scratch
  Pool Type = Scratch
}

修改bareos-dir的配置后,必须重启Director。在重启Director前,请首先使用bareos-dir -t -v检查bareos-dir配置文件。如bareos-dir -t -v没有任何输出,说明配置文件没有任何语法问题,可以重启Director。

计划(schedule)配置文件
/etc/bareos/bareos-dir.d/schedule/*.conf
实例:
一、每月第一个周六晚9点做完整备份;
二、其余周六晚9点做差异备份;
三、周一至周五晚九点做递增备份。

Schedule {
  Name = "WeeklyCycle"
  Run = Full 1st sat at 21:00                   # 每月第一个周六/晚九点,完整备份
  Run = Differential 2nd-5th sat at 21:00       # 其余周六/晚九点,差异备份
  Run = Incremental mon-fri at 21:00            # 周一至周五,递增备份
}

提示信息(message)配置文件
/etc/bareos/bareos-dir.d/message/*.conf
用于配置任务(job)完成后如何发送提示信息
示例:

Messages {
  Name = Standard
  Description = "Reasonable message delivery -- send most everything to email address and to the console."
  # operatorcommand = "/usr/bin/bsmtp -h localhost -f \"\(Bareos\) \<%r\>\" -s \"Bareos: Intervention needed for %j\" %r"
  # mailcommand = "/usr/bin/bsmtp -h localhost -f \"\(Bareos\) \<%r\>\" -s \"Bareos: %t %e of %c %l\" %r"
  operator = root@localhost = mount                                 # 执行operatorcommand命令,用户:root@localhost,操作:mount
  mail = root@localhost = all, !skipped, !saved, !audit             # 执行mailcommand,用户:root@localhost,操作:所有(除skipped,saved和audit)
  console = all, !skipped, !saved, !audit                           # 所有操作,除skipped,saved和audit
  append = "/var/log/bareos/bareos.log" = all, !skipped, !saved, !audit  # 所有操作,除skipped,saved和audit
  catalog = all, !skipped, !saved, !audit                           # 所有操作,除skipped,saved和audit
   # 可用参数
  # %% = %
  # %c = Client’s name
  # %d = Director’s name
  # %e = Job Exit code (OK, Error, ...)
  # %h = Client address
  # %i = Job Id
  # %j = Unique Job name
  # %l = Job level
  # %n = Job name
  # %r = Recipients
  # %s = Since time
  # %t = Job type (e.g. Backup, ...)
  # %v = Read Volume name (Only on director side)
  # %V = Write Volume name (Only on director side)
  # console:定义发送到console的信息
  # append:定义发送到日志文件的信息
  # catalog:定义发送到数据库的信息
}

bsmtp只适用于有本地SMTP服务器,一般情况并不适用。我们将另文介绍如何使用外部SMTP邮件服务器发送bareos的信息邮件。

Bareos的Director已配置完成,在开始备份任务前,我们还需要配置客户端(File Daemon)。


配置Bareos客户端(File Daemon)模块

Bareos客户端(File Daemon)模块的配置文件位于/etc/bareos/bareos-dir.d目录下。

一、添加/配置客户机

需要在Director和客户机上分别配置。

首先在Director上有 bconsole 新增客户机 scm.lswin.cn(这是示例用Ubuntu客户机)

root@bareos:~# bconsole
Connecting to Director localhost:9101
1000 OK: bareos-dir Version: 17.2.4 (21 Sep 2017)
Enter a period to cancel a command.
*
You have messages.
*configure add client name=scm-fd address=scm.lswin.cn password=scmFdPass
Exported resource file "/etc/bareos/bareos-dir-export/client/scm-fd/bareos-fd.d/director/bareos-dir.conf":
Director {
  Name = bareos-dir
  Password = "[md5]94d9e38bace980feecc1be983f379823"
}
Created resource config file "/etc/bareos/bareos-dir.d/client/scm-fd.conf":
Client {
  Name = scm-fd
  Address = scm.lswin.cn
  Password = scmFdPass
}
*

再新增客户机 lswin7-1.lswin.cn(这是示例用Windows客户机)

root@bareos:~# bconsole
Connecting to Director localhost:9101
1000 OK: bareos-dir Version: 17.2.4 (21 Sep 2017)
Enter a period to cancel a command.
*
You have messages.
*configure add client name=lswin7-1-fd address=lswin7-1.lswin.cn password=lswin7-1FdPass
Exported resource file "/etc/bareos/bareos-dir-export/client/lswin7-1-fd/bareos-fd.d/director/bareos-dir.conf":
Director {
  Name = bareos-dir
  Password = "[md5]c25dfe0e029bfcebc4feb30c0d68f857"
}
Created resource config file "/etc/bareos/bareos-dir.d/client/lswin7-1-fd.conf":
Client {
  Name = lswin7-1-fd
  Address = lswin7-1.lswin.cn
  Password = lswin7-1FdPass
}
*

新增客户机配置后,需要重启Director,否则新增的客户机不会出现在客户机列表中。

二、在Ubuntu客户机上安装bareos-fd软件包。

添加 Bareos 库的APT健

root@scm:~#
root@scm:~# wget -q http://download.bareos.org/bareos/release/latest/Debian_9.0/Release.key -O- | apt-key add -
OK
root@scm:~#

添加 Bareos 库定义(/etc/apt/sources.list.d/bareos.list)

 deb http://download.bareos.org/bareos/release/latest/Debian_9.0 /

更新 APT 库

root@scm:~# apt update

在Ubuntu安装 bareos-fd软件包

root@scm:~# apt install bareos-filedaemon
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  bareos-common libfastlz libjansson4
The following NEW packages will be installed:
  bareos-common bareos-filedaemon libfastlz libjansson4
0 upgraded, 4 newly installed, 0 to remove and 2 not upgraded.
Need to get 756 kB of archives.
After this operation, 2,369 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://mirrors.aliyun.com/ubuntu bionic/main amd64 libjansson4 amd64 2.11-1 [29.3 kB]
......
......
......
Processing triggers for systemd (237-3ubuntu10.3) ...
Processing triggers for ureadahead (0.100.0-20) ...
root@scm:~#

然后将Director机器上的/etc/bareos/bareos-dir-export/client/scm-fd/bareos-fd.d/director/bareos-dir.conf文件复制到本地,文件为/etc/bareos/bareos-fd.d。复制完成后需重启Bareos 的 FileDaemon,否则新的配置不会取作用。

三、在Windows客户机上安装bareos-fd软件包。

软件包下载地址:
64位Bareos File Daemon软件包
32位Bareos File Daemon软件包

安装Bareos File Daemon
备份/恢复系统BAREOS的安装、设置和使用(二)-LMLPHP

备份/恢复系统BAREOS的安装、设置和使用(二)-LMLPHP
备份/恢复系统BAREOS的安装、设置和使用(二)-LMLPHP
备份/恢复系统BAREOS的安装、设置和使用(二)-LMLPHP
备份/恢复系统BAREOS的安装、设置和使用(二)-LMLPHP

将Director机器上文件/etc/bareos# /etc/bareos/bareos-dir-export/client/lswin7-1-fd/bareos-fd.d/director/bareos-dir.conf中的Password复制到Password中;再将/etc/bareos/bareos-dir.d/bareos-dir.d/console/bareos-mon.conf文件中的Password复制到Client Monitor Password中。如不需要Monitor,可忽略复制Client Monitor Password这一步。

后面的只需要按提示进行直到完成即可。

到此为止Bareos的Director,Storage和Client都已经配置完成,可以使用了。


Bareos系统测试

在此我们使用bconsole对已配置的Bareos系统进行测试。

检查安装的版本

root@bareos:~# bconsole
Connecting to Director localhost:9101
1000 OK: bareos-dir Version: 17.2.4 (21 Sep 2017)
Enter a period to cancel a command.
*version
bareos-dir Version: 17.2.4 (21 Sep 2017) x86_64-pc-linux-gnu debian Debian GNU/Linux 9.3 (stretch) Debian_9.0 x86_64
*

安装的bareos-dir版本是 17.2.4 的 Debian_9.0版,ubuntu 18.04是基于Debian_9.0。

检查配置的客户机

*show client
Client {
  Name = "scm-fd"
  Address = "scm.lswin.cn"
  Password = "[md5]94d9e38bace980feecc1be983f379823"
  Catalog = "MyCatalog"
}

Client {
  Name = "lswin7-1-fd"
  Address = "lswin7-1.lswin.cn"
  Password = "[md5]c25dfe0e029bfcebc4feb30c0d68f857"
  Catalog = "MyCatalog"
}

Client {
  Name = "bareos-fd"
  Description = "Client resource of the Director itself."
  Address = "localhost"
  Password = "[md5]33e11c4e5a631bf5620f66e4b4e18e76"
  Catalog = "MyCatalog"
}

*

测试备份任务(backup-test-on-bareos-fd)

*
*run
A job name must be specified.
The defined Job resources are:
     1: RestoreFiles
     2: backup-test-on-bareos-fd
     3: BackupCatalog
     4: backup-bareos-fd
Select Job resource (1-4): 2
Run Backup job
JobName:  backup-test-on-bareos-fd
Level:    Incremental
Client:   bareos-fd
Format:   Native
FileSet:  TestSet
Pool:     Incremental (From Job IncPool override)
Storage:  File (From Job resource)
When:     2018-10-04 18:39:17
Priority: 10
OK to run? (yes/mod/no): mod
Parameters to modify:
     1: Level
     2: Storage
     3: Job
     4: FileSet
     5: Client
     6: Backup Format
     7: When
     8: Priority
     9: Pool
    10: Plugin Options
Select parameter to modify (1-10): 1
Levels:
     1: Full
     2: Incremental
     3: Differential
     4: Since
     5: VirtualFull
Select level (1-5): 1
Run Backup job
JobName:  backup-test-on-bareos-fd
Level:    Full
Client:   bareos-fd
Format:   Native
FileSet:  TestSet
Pool:     Full (From Job FullPool override)
Storage:  File (From Job resource)
When:     2018-10-04 18:39:17
Priority: 10
OK to run? (yes/mod/no): mod
Parameters to modify:
     1: Level
     2: Storage
     3: Job
     4: FileSet
     5: Client
     6: Backup Format
     7: When
     8: Priority
     9: Pool
    10: Plugin Options
Select parameter to modify (1-10): 5
The defined Client resources are:
     1: scm-fd
     2: bareos-fd
Select Client (File daemon) resource (1-3): 1
Run Backup job
JobName:  backup-test-on-bareos-fd
Level:    Full
Client:   scm-fd
Format:   Native
FileSet:  TestSet
Pool:     Full (From Job FullPool override)
Storage:  File (From Job resource)
When:     2018-10-04 18:39:17
Priority: 10
OK to run? (yes/mod/no):
Job queued. JobId=13
*status
Status available for:
     1: Director
     2: Storage
     3: Client
     4: Scheduler
     5: All
Select daemon type for status (1-5): 1
bareos-dir Version: 17.2.4 (21 Sep 2017) x86_64-pc-linux-gnu debian Debian GNU/Linux 9.3 (stretch)
Daemon started 04-Oct-18 18:03. Jobs: run=2, running=0 mode=0 db=mysql
 Heap: heap=409,600 smbytes=260,292 max_bytes=302,389 bufs=1,044 max_bufs=1,458

Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Incremental    Backup    10  04-Oct-18 21:00    backup-test-on-bareos-fd Incremental-0002
Incremental    Backup    10  04-Oct-18 21:00    backup-bareos-fd   Incremental-0002
Full           Backup    11  04-Oct-18 21:10    BackupCatalog      Incremental-0002
====

Running Jobs:
Console connected at 04-Oct-18 18:32
No Jobs running.
====

Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================
     4  Incr          0         0   OK       20-Sep-18 21:00 backup-bareos-fd
     5  Full         62    84.23 K  OK       20-Sep-18 21:10 BackupCatalog
     6  Incr          0         0   OK       24-Sep-18 21:00 backup-bareos-fd
     7  Full         67    96.19 K  OK       24-Sep-18 21:10 BackupCatalog
    10  Full        202    32.57 M  OK       03-Oct-18 15:08 backup-test-on-bareos-fd
    11                1    83.58 K  OK       03-Oct-18 15:17 RestoreFiles
    13  Full        175    30.33 M  OK       04-Oct-18 18:40 backup-test-on-bareos-fd


Client Initiated Connections (waiting for jobs):
Connect time        Protocol            Authenticated       Name
====================================================================================================
====
You have messages.
*messages
04-Oct 18:40 bareos-dir JobId 13: Start Backup JobId 13, Job=backup-test-on-bareos-fd.2018-10-04_18.40.45_37
04-Oct 18:40 bareos-dir JobId 13: Using Device "FileStorage" to write.
04-Oct 18:40 bareos-sd JobId 13: Volume "Full-0001" previously written, moving to end of data.
04-Oct 18:40 bareos-sd JobId 13: Ready to append to end of Volume "Full-0001" size=95925221
04-Oct 18:40 bareos-sd JobId 13: Elapsed time=00:00:01, Transfer rate=30.35 M Bytes/second
04-Oct 18:40 bareos-dir JobId 13: sql_create.c:872 Insert of attributes batch table done
04-Oct 18:40 bareos-dir JobId 13: Bareos bareos-dir 17.2.4 (21Sep17):
  Build OS:               x86_64-pc-linux-gnu debian Debian GNU/Linux 9.3 (stretch)
  JobId:                  13
  Job:                    backup-test-on-bareos-fd.2018-10-04_18.40.45_37
  Backup Level:           Full
  Client:                 "scm-fd" 17.2.4 (21Sep17) x86_64-pc-linux-gnu,debian,Debian GNU/Linux 9.3 (stretch),Debian_9.0,x86_64
  FileSet:                "TestSet" 2018-10-03 15:08:15
  Pool:                   "Full" (From Job FullPool override)
  Catalog:                "MyCatalog" (From Client resource)
  Storage:                "File" (From Job resource)
  Scheduled time:         04-Oct-2018 18:39:17
  Start time:             04-Oct-2018 18:40:47
  End time:               04-Oct-2018 18:40:48
  Elapsed time:           1 sec
  Priority:               10
  FD Files Written:       175
  SD Files Written:       175
  FD Bytes Written:       30,336,281 (30.33 MB)
  SD Bytes Written:       30,354,503 (30.35 MB)
  Rate:                   30336.3 KB/s
  Software Compression:   None
  VSS:                    no
  Encryption:             no
  Accurate:               no
  Volume name(s):         Full-0001
  Volume Session Id:      2
  Volume Session Time:    1538647406
  Last Volume Bytes:      126,307,760 (126.3 MB)
  Non-fatal FD errors:    0
  SD Errors:              0
  FD termination status:  OK
  SD termination status:  OK
  Termination:            Backup OK

*

信息显示备份已成功完成。

测试恢复任务(backup-test-on-bareos-fd)

*restore

First you select one or more JobIds that contain files
to be restored. You will be presented several methods
of specifying the JobIds. Then you will be allowed to
select which files from those JobIds are to be restored.

To select the JobIds, you have the following choices:
     1: List last 20 Jobs run
     2: List Jobs where a given File is saved
     3: Enter list of comma separated JobIds to select
     4: Enter SQL list command
     5: Select the most recent backup for a client
     6: Select backup for a client before a specified time
     7: Enter a list of files to restore
     8: Enter a list of files to restore before a specified time
     9: Find the JobIds of the most recent backup for a client
    10: Find the JobIds for a backup for a client before a specified time
    11: Enter a list of directories to restore for found JobIds
    12: Select full restore to a specified Job date
    13: Cancel
Select item:  (1-13): 5
Defined Clients:
     1: bareos-fd
     2: scm-fd
Select the Client (1-3): 3
Automatically selected FileSet: TestSet
+-------+-------+----------+------------+---------------------+------------+
| JobId | Level | JobFiles | JobBytes   | StartTime           | VolumeName |
+-------+-------+----------+------------+---------------------+------------+
|    13 | F     |      175 | 30,336,281 | 2018-10-04 18:40:47 | Full-0001  |
+-------+-------+----------+------------+---------------------+------------+
You have selected the following JobId: 13

Building directory tree for JobId(s) 13 ...  +++++++++++++++++++++++++++++++++++++++++++
174 files inserted into the tree.

You are now entering file selection mode where you add (mark) and
remove (unmark) files to be restored. No files are initially added, unless
you used the "all" keyword on the command line.
Enter "done" to leave this mode.

cwd is: /
$
$ ls
usr/
$ mark usr
175 files marked.
$ done
Bootstrap records written to /var/lib/bareos/bareos-dir.restore.1.bsr

The job will require the following
   Volume(s)                 Storage(s)                SD Device(s)
===========================================================================

    Full-0001                 File                      FileStorage

Volumes marked with "*" are online.

175 files selected to be restored.

Run Restore job
JobName:         RestoreFiles
Bootstrap:       /var/lib/bareos/bareos-dir.restore.1.bsr
Where:           /tmp/bareos-restores
Replace:         Always
FileSet:         LinuxAll
Backup Client:   scm-fd
Restore Client:  scm-fd
Format:          Native
Storage:         File
When:            2018-10-04 18:56:40
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no):
Job queued. JobId=16
*status
Status available for:
     1: Director
     2: Storage
     3: Client
     4: Scheduler
     5: All
Select daemon type for status (1-5): 1
bareos-dir Version: 17.2.4 (21 Sep 2017) x86_64-pc-linux-gnu debian Debian GNU/Linux 9.3 (stretch)
Daemon started 04-Oct-18 18:03. Jobs: run=5, running=0 mode=0 db=mysql
 Heap: heap=311,296 smbytes=535,619 max_bytes=836,693 bufs=1,209 max_bufs=1,792

Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Incremental    Backup    10  04-Oct-18 21:00    backup-test-on-bareos-fd Incremental-0002
Incremental    Backup    10  04-Oct-18 21:00    backup-bareos-fd   Incremental-0002
Full           Backup    11  04-Oct-18 21:10    BackupCatalog      Incremental-0002
====

Running Jobs:
Console connected at 04-Oct-18 18:32
No Jobs running.
====

Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================
     7  Full         67    96.19 K  OK       24-Sep-18 21:10 BackupCatalog
    10  Full        202    32.57 M  OK       03-Oct-18 15:08 backup-test-on-bareos-fd
    11                1    83.58 K  OK       03-Oct-18 15:17 RestoreFiles
    13  Full        175    30.33 M  OK       04-Oct-18 18:40 backup-test-on-bareos-fd
    16              175    30.33 M  OK       04-Oct-18 18:56 RestoreFiles


Client Initiated Connections (waiting for jobs):
Connect time        Protocol            Authenticated       Name
====================================================================================================
====
You have messages.
*
*messages
04-Oct 18:56 bareos-dir JobId 16: Start Restore Job RestoreFiles.2018-10-04_18.56.47_55
04-Oct 18:56 bareos-dir JobId 16: Using Device "FileStorage" to read.
04-Oct 18:56 bareos-sd JobId 16: Ready to read from volume "Full-0001" on device "FileStorage" (/var/lib/bareos/storage).
04-Oct 18:56 bareos-sd JobId 16: Forward spacing Volume "Full-0001" to file:block 0:95925221.
04-Oct 18:56 bareos-sd JobId 16: End of Volume at file 0 on device "FileStorage" (/var/lib/bareos/storage), Volume "Full-0001"
04-Oct 18:56 bareos-sd JobId 16: End of all volumes.
04-Oct 18:56 bareos-dir JobId 16: Bareos bareos-dir 17.2.4 (21Sep17):
  Build OS:               x86_64-pc-linux-gnu debian Debian GNU/Linux 9.3 (stretch)
  JobId:                  16
  Job:                    RestoreFiles.2018-10-04_18.56.47_55
  Restore Client:         scm-fd
  Start time:             04-Oct-2018 18:56:49
  End time:               04-Oct-2018 18:56:49
  Elapsed time:           0 secs
  Files Expected:         175
  Files Restored:         175
  Bytes Restored:         30,336,281
  Rate:                   0.0 KB/s
  FD Errors:              0
  FD termination status:  OK
  SD termination status:  OK
  Termination:            Restore OK

*

信息显示文件恢复已成功完成。

测试备份Windows电脑(backup-test-on-bareos-fd)

root@bareos:~#
root@bareos:~# bconsole
Connecting to Director localhost:9101
1000 OK: bareos-dir Version: 17.2.4 (21 Sep 2017)
Enter a period to cancel a command.
*run
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
A job name must be specified.
The defined Job resources are:
     1: RestoreFiles
     2: backup-test-on-bareos-fd
     3: BackupCatalog
     4: backup-bareos-fd
Select Job resource (1-4): 2
Run Backup job
JobName:  backup-test-on-bareos-fd
Level:    Incremental
Client:   bareos-fd
Format:   Native
FileSet:  TestSet
Pool:     Incremental (From Job IncPool override)
Storage:  File (From Job resource)
When:     2018-10-05 10:39:59
Priority: 10
OK to run? (yes/mod/no): mod
Parameters to modify:
     1: Level
     2: Storage
     3: Job
     4: FileSet
     5: Client
     6: Backup Format
     7: When
     8: Priority
     9: Pool
    10: Plugin Options
Select parameter to modify (1-10): 1
Levels:
     1: Full
     2: Incremental
     3: Differential
     4: Since
     5: VirtualFull
Select level (1-5): 1
Run Backup job
JobName:  backup-test-on-bareos-fd
Level:    Full
Client:   bareos-fd
Format:   Native
FileSet:  TestSet
Pool:     Full (From Job FullPool override)
Storage:  File (From Job resource)
When:     2018-10-05 10:39:59
Priority: 10
OK to run? (yes/mod/no): mod
Parameters to modify:
     1: Level
     2: Storage
     3: Job
     4: FileSet
     5: Client
     6: Backup Format
     7: When
     8: Priority
     9: Pool
    10: Plugin Options
Select parameter to modify (1-10): 5
The defined Client resources are:
     1: scm-fd
     2: lswin7-1-fd
     3: lscms-fd
     4: bareos-fd
Select Client (File daemon) resource (1-4): 2
Run Backup job
JobName:  backup-test-on-bareos-fd
Level:    Full
Client:   lswin7-1-fd
Format:   Native
FileSet:  TestSet
Pool:     Full (From Job FullPool override)
Storage:  File (From Job resource)
When:     2018-10-05 10:39:59
Priority: 10
OK to run? (yes/mod/no): mod
Parameters to modify:
     1: Level
     2: Storage
     3: Job
     4: FileSet
     5: Client
     6: Backup Format
     7: When
     8: Priority
     9: Pool
    10: Plugin Options
Select parameter to modify (1-10): 4
The defined FileSet resources are:
     1: Windows Test Fileset
     2: Windows All Drives
     3: TestSet
     4: SelfTest
     5: LinuxAll
     6: Catalog
Select FileSet resource (1-6): 1
Run Backup job
JobName:  backup-test-on-bareos-fd
Level:    Full
Client:   lswin7-1-fd
Format:   Native
FileSet:  Windows Test Fileset
Pool:     Full (From Job FullPool override)
Storage:  File (From Job resource)
When:     2018-10-05 10:39:59
Priority: 10
OK to run? (yes/mod/no):
Job queued. JobId=19
You have messages.
*messages
05-Oct 10:18 bareos-dir JobId 19: Start Backup JobId 18, Job=backup-test-on-bareos-fd.2018-10-05_10.18.57_06
05-Oct 10:18 bareos-dir JobId 19: Using Device "FileStorage" to write.
05-Oct 10:18 bareos-sd JobId 19: Volume "Full-0001" previously written, moving to end of data.
05-Oct 10:18 bareos-sd JobId 19: Ready to append to end of Volume "Full-0001" size=126308232
05-Oct 10:18 lswin7-1-fd JobId 19: Created 28 wildcard excludes from FilesNotToBackup Registry key
05-Oct 10:19 lswin7-1-fd JobId 19: Generate VSS snapshots. Driver="Win64 VSS", Drive(s)="C"
05-Oct 10:19 lswin7-1-fd JobId 19: VolumeMountpoints are not processed as onefs = yes.
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "Task Scheduler Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "VSS Metadata Store Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "Performance Counters Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "System Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "ASR Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "Registry Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "Shadow Copy Optimization Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "BITS Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "COM+ REGDB Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "WMI Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 lswin7-1-fd JobId 19: VSS Writer (BackupComplete): "MSSearch Service Writer", State: 0x1 (VSS_WS_STABLE)
05-Oct 10:19 bareos-sd JobId 19: Elapsed time=00:00:18, Transfer rate=2.182 M Bytes/second
05-Oct 10:19 bareos-dir JobId 19: sql_create.c:872 Insert of attributes batch table done
05-Oct 10:19 bareos-dir JobId 19: Bareos bareos-dir 17.2.4 (21Sep17):
  Build OS:               x86_64-pc-linux-gnu debian Debian GNU/Linux 9.3 (stretch)
  JobId:                  19
  Job:                    backup-test-on-bareos-fd.2018-10-05_10.18.57_06
  Backup Level:           Full
  Client:                 "lswin7-1-fd" 17.2.4 (21Sep17) Microsoft Windows 7 Ultimate Edition Service Pack 1 (build 7601), 64-bit,Cross-compile,Win64
  FileSet:                "Windows Test Fileset" 2018-10-05 10:18:57
  Pool:                   "Full" (From command line)
  Catalog:                "MyCatalog" (From Client resource)
  Storage:                "File" (From Job resource)
  Scheduled time:         05-Oct-2018 10:18:57
  Start time:             05-Oct-2018 10:18:59
  End time:               05-Oct-2018 10:19:17
  Elapsed time:           18 secs
  Priority:               10
  FD Files Written:       6
  SD Files Written:       6
  FD Bytes Written:       39,284,012 (39.28 MB)
  SD Bytes Written:       39,285,181 (39.28 MB)
  Rate:                   2182.4 KB/s
  Software Compression:   None
  VSS:                    yes
  Encryption:             no
  Accurate:               no
  Volume name(s):         Full-0001
  Volume Session Id:      2
  Volume Session Time:    1538702289
  Last Volume Bytes:      165,623,141 (165.6 MB)
  Non-fatal FD errors:    0
  SD Errors:              0
  FD termination status:  OK
  SD termination status:  OK
  Termination:            Backup OK

*

备份Windows电脑已成功备份。

最基本的Bareos系统配置已全部完成。Bareos是一个完整的企业级备份恢复系统,上述介绍的只是最简单的配置,详细配置请参阅Bareos文档

下文我们将介绍Bareos-WebUI。

10-05 11:00