1 准备环境
准备Windows操作系统环境
-
- 提前安装需要用到的软件
提前需要用到的软件如下:
Cygwin
Python3
Postgresql
MinGW-w64(下载w64devkit)
注意:D:\w64devkit\x86_64-w64-mingw32\lib目录中缺少libpthread.dll.a动态库文件,需要从Cygwin的lib目录拷贝一份到w64devkit这边的x86_64-w64-mingw32\lib目录下。如果Cygwin的lib目录也没有的话,这需要在Cygwin环境中安装MinGw-w64-gcc工具链,安装方法参照1.3。
1.2 获取源码
可选择拉取github中最新代码或解压代码压缩包。
github:git clone https://github.com/bareos/bareos.git
解压代码命令unzip bareos-master.zip
1.3 使用Cygwin下载编译bareos会依赖到的库
运行setup-x86_64.exe
选择下载而不安装
下一页,设置好下载目录,我这里设置的是D:\Downloads
一直下一步到选择软件包的界面,选择以下这些软件包之后,点击下一页
mingw64-x86_64-readline
mingw64-x86_64-zlib
libintl-devel-0.22.4-1
mingw64-x86_64-json-c
mingw64-x86_64-libxml2
mingw64-x86_64-lzo2
mingw64-x86_64-ncurses
mingw64-x86_64-openssl
下载后的软件包在如下目录可以找到。
D:\Downloads\https%3a%2f%2fmirrors.163.com%2fcygwin%2f\noarch\release
解压软件包后usr\x86_64-w64-mingw32\sys-root\mingw目录下有bin,lib,include等目录。这些是我们之后编译会用到的内容。
2 编译源码
2.1 切换到源码目录
cd bareos-master
2.2创建编译目录并切换到build目录
md build
cd build
2.3 设置编译版本
执行命令
echo "set(VERSION_STRING \"20.3.4\")" > ../core/cmake/BareosVersion.cmake
echo "set(VERSION_TIMESTAMP \"1234567890\")" >> ../core/cmake/BareosVersion.cmake
cp ../core/cmake/BareosVersion.cmake ../webui/cmake/BareosVersion.cmake
2.4 配置各种编译过程中会用到的变量
我这里把需要用到的软件包都拷贝到D:/mingw64-x86_64-thirdparty这个目录下。手动把每个软件包解压后usr目录下的bin、include、lib等目录拷贝出来,组织成如下结构。
把用到的软件包都放到一起
新建文件SetVariablesWin.cmake在D:\bareos-master根目录下。文件中配置各种编译过程中会用到的变量,大部分是各种软件包的路径,还有一些系统参数。文件内容如下。
set(HAVE_WIN32 1)
set(WINDOWS_BITS 64)
set(CMAKE_SYSTEM_NAME "Windows")
set(JANSSON_LIBRARY "C:/Program Files (x86)/jansson/lib/libjansson.a")
set(JANSSON_INCLUDE_DIR "C:/Program Files (x86)/jansson/include")
set(Readline_ROOT_DIR "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-readline")
set(Readline_INCLUDE_DIR "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-readline/include")
set(Readline_LIBRARY "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-readline/lib/libreadline.dll.a")
set(ZLIB_INCLUDE_DIR "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-zlib/include")
set(ZLIB_LIBRARY "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-zlib/lib/libz.a")
set(Intl_LIBRARY "D:/mingw64-x86_64-thirdparty/libintl-devel-0.22.4-1/lib")
set(Intl_INCLUDE_DIR "D:/mingw64-x86_64-thirdparty/libintl-devel-0.22.4-1/include")
set(JSONC_INCLUDE_DIRS "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-json-c/include")
set(JSONC_LIBRARIES "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-json-c/lib/libjson-c.a")
set(LIBXML2_LIBRARY "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-libxml2/lib/libxml2.dll.a")
set(LIBXML2_INCLUDE_DIR "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-libxml2/include")
set(LZO2_INCLUDE_DIRS "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-lzo2/include")
set(LZO2_LIBRARIES "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-lzo2/lib/liblzo2.a")
set(PostgreSQL_INCLUDE_DIR "C:/Program Files/PostgreSQL/16/include")
set(PostgreSQL_LIBRARY "C:/Program Files/PostgreSQL/16/lib/libpq.dll")
set(Python3_INCLUDE_DIRS "C:/Users/DELL/AppData/Local/Programs/Python/Python311/include")
set(Python3_LIBRARIES "C:/Users/DELL/AppData/Local/Programs/Python/Python311/python311.dll")
set(Ncurses_LIBRARY "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-ncurses/lib/libncursesw.a")
set(OPENSSL_ROOT_DIR "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-openssl")
set(OPENSSL_INCLUDE_DIR "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-openssl/include")
set(OPENSSL_LIBRARIES "D:/mingw64-x86_64-thirdparty/mingw64-x86_64-openssl/lib64/libssl.dll.a;D:/mingw64-x86_64-thirdparty/mingw64-x86_64-openssl/lib64/libcrypto.dll.a")
2.5 修改cmake文件
修改D:\bareos-master\CMakeList.txt
添加include(SetVariablesWin.cmake),使在文件中定义的变量生效
修改D:\bareos-master\core\CMakeList.txt
删除掉设置路径的行,因为上一步中已经全部放到SetVariablesWin.cmake统一管理。
修改前:
修改后:
修改D:\bareos-master\core\src\fastlz\CMakeList.txt
新增zlib的头文件路径include_directories(${ZLIB_INCLUDE_DIR})
修改后如下
修改D:\bareos-master\core\src\filed\CMakeList.txt
新增zlib的头文件路径include_directories(${ZLIB_INCLUDE_DIR})
修改后如下
修改D:\bareos-master\core\src\plugins\dird\python\CMakeLists.txt
新增target_include_directories(bareosdir-python3-module PUBLIC ${OPENSSL_INCLUDE_DIR})
修改D:\bareos-master\core\src\plugins\stored\CMakeLists.txt
新增target_include_directories(autoxflate-sd PUBLIC ${ZLIB_INCLUDE_DIR})
修改D:\bareos-master\core\src\plugins\filed\CMakeLists.txt
注释掉mssqlvdi-fd相关的插件模块添加。
mssqlvdi-fd.cc文件中包含了以下三个头文件。需要安装VDI支持的开发包才能编译通过。
// Microsoft® MSSQL Virtual Device Interface (VDI)
#include "vdi.h"
#include "vdierror.h"
#include "vdiguid.h"
2.6 修改部分引起编译报错的代码
修改D:\bareos-master\core\src\win32\compat\include\compat.h
注释掉三行,不然类型定义会有冲突
/*
#ifndef INT64
# define INT64 long long int
#endif
*/
修改后如下
修改D:\bareos-master\core\src\win32\include\vss.h文件名字为bareos_win32_vss.h。目的是与系统库自带的vss.h区分开。
修改所有对D:\bareos-master\core\src\win32\include\vss.h的引用。即"vss.h"改为"bareos_win32_vss.h"
修改D:\bareos-master\core\src\win32\filed\vss_generic.cc
修改头文件包含路径。原代码中"Win2003/vss.h"这些头文件无法找到,使用新版的替代。
/*
# include "Win2003/vss.h"
# include "Win2003/vswriter.h"
# include "Win2003/vsbackup.h"
*/
# include <vss.h>
# include <vswriter.h>
# include <vsbackup.h>
修改D:\bareos-master\core\src\win32\filed\vss_generic.cc第876行
会导致编译报错,原代码用无符号数与有符号数进行比较。
// while ((unsigned)hr == VSS_E_SNAPSHOT_SET_IN_PROGRESS) {
while (hr == VSS_E_SNAPSHOT_SET_IN_PROGRESS) {
修改D:\bareos-master\core\src\stored\backends\win32_tape_device.cc
free(pGetMediaTypes);这一行放到后续的if代码块中。因为可能realloc已经成功了,这时候还去free(pGetMediaTypes)会出错。
2.7 配置编译项
进入bareos_master/build。根据不同需求选择下面中的一项
配置release版:
cmake -G "MinGW Makefiles" ..
配置debug版:
cmake -G "MinGW Makefiles" .. -Dconverage=yes
3 编译
进入bareos_master/build。根据不同需求选择下面中的一项
编译dir,fd, sd全套,可以执行命令make
只编译其中一个,可以选择执行如下命令的其中一个:
make bareos-dir
make bareos-fd
make bareos-sd
4 安装
使用管理员权限打开cmd,进入bareos_master/build执行make install。
默认安装目录在C:\Program Files (x86)\bareos
5 修改配置文件
新建文件"C:\Program Files (x86)\bareos\etc\bareos\bareos-fd.conf"
输入内容如下
Director {
Name = bareos-dir
Address = 192.168.7.84
Password = "fdpw"
Description = "Allow the configured Director to access this file daemon."
Enable kTLS = no
TLS Enable = no
TLS Require = no
}
Director {
Name = bareos-mon
Address = 192.168.7.84
Password = "monpw"
Monitor = yes
Description = "Restricted Director, used by tray-monitor to get the status of this file daemon."
Enable kTLS = no
TLS Enable = no
TLS Require = no
}
Client {
Name = ZhangYao-fd
Maximum Concurrent Jobs = 20
SD Connect Timeout = 30
Heartbeat Interval = 2
PKI Signatures = no
PKI Encryption = no
Enable kTLS = no
TLS Enable = no
TLS Require = no
}
Messages {
Name = Standard
Director = bareos-dir = all, !skipped, !restored
Description = "Send relevant messages to the Director."
}
6 运行服务
进入目录C:\Program Files (x86)\bareos\sbin
运行命令如下
.\bareos-fd.exe -f -c "C:\Program Files (x86)\bareos\etc\bareos\bareos-fd.conf"
这样就可以等待Director下发命令。