在Ubuntu 20.04上安装和设置BackupPC服务器

备份电脑 是具有基于Web的前端的高性能企业级跨平台备份软件套件。它可用于将Linux,Windows和Mac OSXs PC和便携式计算机备份到服务器磁盘。在本指南中,我们将学习如何在Ubuntu 20.04上安装和设置BackupPC服务器。

BackupPC提供了许多功能。

  • 提供一个 网络界面 它允许管理员查看日志文件,配置,当前状态,并允许用户启动和取消备份以及浏览和还原备份中的文件。
  • 它支持 重复数据删除:同一或不同PC的多个备份中的相同文件仅存储一次,从而大大节省了磁盘存储和磁盘I / O。
  • 它支持数据 压缩:由于仅需要压缩新文件(尚未合并),因此对CPU时间的影响很小。
  • 它是 开源的:BackupPC托管在 Github,并根据GPL许可进行分发。
  • 不需要客户端软件。
  • 支持全套还原选项,包括直接还原(通过smbclient,tar或rsync / rsyncd)或下载zip或tar文件。

阅读更多 关于BackupPC 页。

在Ubuntu 20.04上安装和设置BackupPC服务器

更新系统软件包

首先,请确保您的系统软件包是最新的。

apt update
apt upgrade

在Ubuntu 20.04上安装BackupPC

在撰写本文时,BackupPC 4.3.2是最新的稳定发行版。不幸的是,默认的Ubuntu 20.04仓库提供了BackupPC 3.3.2。

apt show backuppc
Package: backuppc
Version: 3.3.2-3
Priority: optional
Section: utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian BackupPC Team <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 2,314 kB
...
Homepage: https://backuppc.github.io/backuppc/
Download-Size: 460 kB
APT-Sources: http://ke.archive.ubuntu.com/ubuntu focal/main amd64 Packages

因此,我们将从源代码在Ubuntu 20.04上构建BackupPC 4。

安装必需的依赖项

apt install apache2 apache2-utils libapache2-mod-perl2 par2 perl smbclient rsync tar gcc zlib1g zlib1g-dev rrdtool git make perl-doc libnss-winbind winbind libarchive-zip-perl libfile-listing-perl libxml-rss-perl libcgi-session-perl libacl1-dev curl -y

创建BackupPC用户

BackupPC通常由特权较低的人运行 backuppc 使用者 /var/lib/backuppc 作为工作目录。这样,通过执行以下命令创建一个backuppc系统用户;

useradd -r -m -d /var/lib/backuppc -s /bin/bash -c "BackupPC user" backuppc

生成并安装BackupPC XS

BackupPC V4 +需要BackupPC XS,这是一个Perl模块,可在可调用Perl的模块中实现各种BackupPC功能。

下载BackupPC XS源代码;

git clone https://github.com/backuppc/backuppc-xs.git

生成并安装BackupPC XS;

cd backuppc-xs/

要安装此模块,请运行以下命令:

perl Makefile.PL
make

跑过 make test 验证模块编译的正确性;

make test

如果一切正常,则结果应为合格;

t/BackupPC_XS.t .. ok
All tests successful.
Files=1, Tests=1, 0 wallclock secs ( 0.00 usr 0.04 sys + 0.07 cusr 0.03 csys = 0.14 CPU)
Result: PASS

安装BackupPC XS模块;

make install

上面的需求部分中还安装了其他可选的但高度推荐的模块。

安装BackupPC rsync_bpc

为了能够使用备份客户端 rsync 命令,您需要 rsync_bpc 模块已安装。 Rsync-bpc是rsync的自定义版本,用作BackupPC的一部分。

下载rsync_bpc源代码;

cd ~
git clone https://github.com/backuppc/rsync-bpc.git

编译并安装rsync_bpc模块;

cd rsync-bpc
./configure

这将使用默认选项配置rsync_bpc。您可以使用以下命令检查其他配置选项, ./configure --help

编译并安装rsync_bpc;

make
make install

在Ubuntu 20.04上安装BackupPC

完成上述所有操作后,您现在可以自行安装BackupPC。下载克隆Github存储库的源代码;

cd ~
git clone https://github.com/backuppc/backuppc.git

导航到备份源目录;

cd backuppc

从源文件和BackupPC构建工俱生成最新版本的BackupPC tarball;

VER=`curl --silent "https://api.github.com/repos/backuppc/backuppc/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/1/'`
./makeDist --nosyntaxCheck --releasedate "date -u "+%d %b %Y"" --version $VER

这将创建BackupPC tarball,并将其存储在当前工作目录的dist目录下,如下所示: dist / BackupPC-4.3.2.tar.gz

提取源代码;

tar zxf dist/BackupPC-4.3.2.tar.gz

在Ubuntu 20.04上构建并安装和设置BackupPC服务器;

cd BackupPC-4.3.2
perl configure.pl

以这种方式执行时,脚本将以交互方式运行。相应地回答提示。按 输入 接受默认值。

Is this a new installation or upgrade for BackupPC?  If this is
an upgrade please tell me the full path of the existing BackupPC
configuration file (eg: /etc/BackupPC/config.pl).  Otherwise, just
hit return.

--> Full path to existing main config.pl []? 

I found the following locations for these programs:

    bzip2        => /usr/bin/bzip2
    cat          => /usr/bin/cat
    df           => /usr/bin/df
    gtar/tar     => /usr/bin/tar
    gzip         => /usr/bin/gzip
    hostname     => /usr/bin/hostname
    nmblookup    => /usr/bin/nmblookup
    par2         => /usr/bin/par2
    perl         => /usr/bin/perl
    ping         => /usr/bin/ping
    ping6        => /usr/bin/ping6
    rrdtool      => /usr/bin/rrdtool
    rsync        => /usr/bin/rsync
    rsync_bpc    => /usr/local/bin/rsync_bpc
    sendmail     => 
    smbclient    => /usr/bin/smbclient
    split        => /usr/bin/split
    ssh/ssh2     => /usr/bin/ssh

--> Are these paths correct? [y]? y

Please tell me the hostname of the machine that BackupPC will run on.

--> BackupPC will run on host [ubuntu20]? 

BackupPC should run as a dedicated user with limited privileges.  You
need to create a user.  This user will need read/write permission on
the main data directory and read/execute permission on the install
directory (these directories will be setup shortly).

The primary group for this user should also be chosen carefully.
The data directories and files will have group read permission,
so group members can access backup files.

--> BackupPC should run as user [backuppc]?

Please specify an install directory for BackupPC.  This is where the
BackupPC scripts, library and documentation will be installed.

--> Install directory (full path) [/usr/local/BackupPC]? 

Please specify a data directory for BackupPC.  This is where all the
PC backup data is stored.  This file system needs to be big enough to
accommodate all the PCs you expect to backup (eg: at least several GB
per machine).

--> Data directory (full path) [/data/BackupPC]? /var/lib/backuppc

BackupPC has SCGI and CGI perl interfaces that run under Apache.  You need
to pick which one to run.

...
The traditional alternative is to use CGI.  In this case, an executable needs
to be installed Apache's cgi-bin directory.  This executable needs to run as
set-uid backuppc, or it can be run under mod_perl with Apache
running as user backuppc.

--> SCGI port (-1 to disable) [-1]? 
--> CGI bin directory (full path, or empty for no CGI) []? /var/www/cgi-bin/BackupPC

BackupPC's CGI and SCGI script need to display various PNG/GIF
images that should be stored where Apache can serve them.  They
should be placed somewhere under Apache's DocumentRoot.  BackupPC
also needs to know the URL to access these images.  Example:

    Apache image directory:  /var/www/htdocs/BackupPC
    URL for image directory: /BackupPC

The URL for the image directory should start with a slash.

--> Apache image directory (full path, or empty for no S/CGI) []? /var/www/html/BackupPC
--> URL for image directory (omit http://host; starts with '/', or empty for no S/CGI) []? /BackupPC

Ok, we're about to:

  - install the binaries, lib and docs in /usr/local/BackupPC
  - create the data directory /var/lib/backuppc
  - optionally install the cgi-bin interface
  - create/update the config.pl file /etc/BackupPC/config.pl

--> Do you want to continue? [y]?y
...
Ok, it looks like we are finished.  There are several more things you
will need to do:

  - Browse through the config file, /etc/BackupPC/config.pl,
    and make sure all the settings are correct.  In particular,
    you will need to set $Conf{CgiAdminUsers} so you have
    administration privileges in the CGI interface.

  - Edit the list of hosts to backup in /etc/BackupPC/hosts.

  - Read the documentation in /usr/local/BackupPC/doc/BackupPC.html.
    Please pay special attention to the security section.

  - Verify that the CGI script BackupPC_Admin runs correctly.  You might
    need to change the permissions or group ownership of BackupPC_Admin.
    If this is an upgrade and you are using mod_perl, you will need
    to restart Apache.  Otherwise it will have stale code.

  - BackupPC should be ready to start.  Don't forget to run it
    as user backuppc!  The installation also contains
    a systemd/backuppc.service script that can be installed so
    that BackupPC can auto-start on boot.  This will also enable
    administrative users to start the server from the CGI interface.
    See systemd/README.

Enjoy!

如果要运行非交互式安装;

./configure.pl --batch --cgi-dir /var/www/cgi-bin/BackupPC --data-dir /var/lib/backuppc --hostname ubuntu20 --html-dir /var/www/html/BackupPC --html-dir-url /BackupPC --install-dir /usr/local/BackupPC

为BackupPC配置Apache Web服务器

将示例BackupPC Apache配置文件复制到启用了Apache的配置目录中;

cp backuppc/BackupPC-4.3.2/httpd/BackupPC.conf /etc/apache2/conf-available/

接下来,配置Apache以允许从外部访问BackupPC。

sed -i 's/Require local/Require all granted/' /etc/apache2/conf-available/BackupPC.conf

将Apache配置为以BackupPC用户身份运行, backuppc

sed -i 's/www-data/backuppc/g' /etc/apache2/envvars

从BackupPC管理CGI文件中删除set-uid;

chmod u-s /var/www/cgi-bin/BackupPC/BackupPC_Admin

配置BackupPC Apache基本身份验证

如果愿意,请更改基本身份验证文件;

sed -i 's#^AuthUserFile.*$#AuthUserFile /etc/BackupPC/.allowed#' /etc/apache2/conf-available/BackupPC.conf

更改基本身份验证消息;

sed -i 's/^AuthName.*$/AuthName "Kifarunix-demo BackupPC Restricted Access"/' /etc/apache2/conf-available/BackupPC.conf

创建BackupPC基本身份验证用户和密码。此信息应存储在由 AuthUserFile 上面的参数。例如,创建名为 kifarunixadmin;

htpasswd -c /etc/BackupPC/.allowed kifarunixadmin

您可以添加其他用户,例如 kifarunixuser

htpasswd /etc/BackupPC/.allowed kifarunixuser

调整auth用户文件的所有权和权限;

chmod 666 /etc/BackupPC/.allowed
chown backuppc:backuppc /etc/BackupPC/.allowed

配置BackupPC管理用户

在“ CGI用户界面配置设置”部分中定义了BackupPC的默认管理用户。普通用户只能访问特定于其主机的信息。他们还可以开始/停止/浏览/还原备份。管理用户具有对所有主机的完全访问权限,以及总体状态和日志信息。在此演示中,我们将 kifarunixadmin 用户作为BackupPC管理员。

vim /etc/BackupPC/config.pl
$Conf{CgiAdminUserGroup} = 'kifarunixadmin';
$Conf{CgiAdminUsers} = 'kifarunixadmin';

定义BackupPC客户端备份用户

默认情况下,BackupPC使用备份客户端上的root用户进行备份。

$Conf{RsyncSshArgs} = [
        '-e', '$sshPath -l root',
];

允许通过低特权用户进行备份更加安全。在此演示中,我们将创建一个非特权用户, backuppc,在每个客户端上进行备份 which is only allowed to run rsync command with sudo rights 用于备份。因此,相应地更改此用户。

$Conf{RsyncSshArgs} = [
        '-e', '$sshPath -l backuppc',
];

我们将保留其他Rsync设置为默认选项。

请注意,所有这些配置都可以通过每个客户端配置覆盖。

启用BackupPC Apache配置和CGI模块;

运行以下命令以启用BackupPC Apache配置和CGI模块;

a2enconf BackupPC
a2enmod cgid

禁用Apache默认站点和禁用目录列表;

a2dissite 000-default.conf
mv /var/www/html/index.html /var/www/html/index.html.old
sed -i 's/Options Indexes FollowSymLinks/Options -Indexes +FollowSymLinks/' /etc/apache2/apache2.conf

在错误页面上隐藏Web服务器版本;

echo -e 'ServerSignature OffnServerTokens Prod' >> /etc/apache2/apache2.conf

检查Apache是​​​​否有任何错误;

apachectl -t
Syntax OK

启动并启用Apache以在系统启动时运行;

systemctl enable --now apache2

运行BackupPC服务

从源目录复制BackupPC样本systemd服务文件;

cp backuppc/BackupPC-4.3.2/systemd/backuppc.service /etc/systemd/system/

编辑服务组;

sed -i 's/^#Group/Group/' /etc/systemd/system/backuppc.service
sed -i 's#PIDFile=/var/run/#PIDFile=/run/#' /etc/systemd/system/backuppc.service

重新加载系统服务配置;

systemctl daemon-reload

启动并启用BackupPC服务;

systemctl enable --now backuppc

检查状态;

systemctl status backuppc
● backuppc.service - BackupPC server
     Loaded: loaded (/etc/systemd/system/backuppc.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-05-17 19:29:38 UTC; 7s ago
   Main PID: 3772 (BackupPC)
      Tasks: 1 (limit: 2283)
     Memory: 8.6M
     CGroup: /system.slice/backuppc.service
             └─3772 /usr/bin/perl /usr/local/BackupPC/bin/BackupPC

May 17 19:29:38 ubuntu20 systemd[1]: Started BackupPC server.

访问BackupPC Web用户界面

如果防火墙正在运行,请允许外部访问Apache。

ufw allow 80/tcp

您现在可以通过URL访问BackupPC http://server_IP_OR_hostname/BackupPC_Admin

进行身份验证并进入BackupPC Web仪表板。

当您以管理员用户身份进行身份验证时,这是您获得的界面;

在Ubuntu 20.04上安装和设置BackupPC服务器

当您以非管理员用户身份进行身份验证时,这是您获得的界面;

在Ubuntu 20.04上安装和设置BackupPC服务器

BackupPC现在已安装在Ubuntu 20.04上。现在,您可以继续添加主机进行备份;

使用Rsync协议通过BackupPC备份Linux系统

使用BackupPC通过SMB备份Windows系统

使用Rsyncd使用BackupPC备份Windows系统

这标志着我们关于如何在Ubuntu 20.04上安装和设置BackupPC服务器的指南的结尾。请享用!

参考

在Ubuntu上从tarball或git安装BackupPC 4

BackupPC文档:安装BackupPC

Sidebar