Install and Setup BackupPC Server on Ubuntu 20.04

2
1542

 BackupPC is a high-performance enterprise-grade cross-platform backup software suite with a web-based frontend. It can be used for backing up Linux, Windows and Mac OSXs PCs and laptops to a server’s disk. In this guide, we are going to learn how to install and setup BackupPC Server on Ubuntu 20.04.

BackupPC provides quite a number of features;

  • Provides a web interface which allows administrators to view log files, configuration, current status and allows users to initiate and cancel backups and browse and restore files from backups.
  • It supports Data deduplication: Identical files across multiple backups of the same or different PCs are stored only once resulting in substantial savings in disk storage and disk I/O.
  • It supports data Compression: Since only new files (not already pooled) need to be compressed, there is only a modest impact on CPU time.
  • It is Open-source: BackupPC is hosted on Github, and is distributed under a GPL license.
  • No client-side software is needed.
  • A full set of restore options is supported, including direct restore (via smbclient, tar, or rsync/rsyncd) or downloading a zip or tar file.

Read more on About BackupPC page.

Install and Setup BackupPC Server on Ubuntu 20.04

Update System packages

To begin with, ensure that your system packages are up-to-date.

apt update
apt upgrade

Install BackupPC on Ubuntu 20.04

As of this writing, BackupPC 4.3.2 is the latest stable release version. Unfortunately, the default Ubuntu 20.04 repos provides 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

As such, we are going to build BackupPC 4 on Ubuntu 20.04 from source.

Install Required Dependencies

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

Create BackupPC User

BackupPC is usually run by a low privileged backuppc user with /var/lib/backuppc as the working directory. As such, create a backuppc system user by executing the command below;

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

Build and Install BackupPC XS

BackupPC V4+ requires BackupPC XS, a perl module that implements various BackupPC functions in a perl-callable module.

Download BackupPC XS source code;

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

Build and install BackupPC XS;

cd backuppc-xs/

To install this module, run the following commands:

perl Makefile.PL
make

Run the make test to verify the correctness of the compilation of the module;

make test

If everything is in order, the result should be pass;

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

Install BackupPC XS module;

make install

There are other optional but highly RECOMMENDED modules that have been installed on the requirements section above.

Install BackupPC rsync_bpc

In order to be able to backup clients using rsync command, you need rsync_bpc module installed. Rsync-bpc is a customized version of rsync that is used as part of BackupPC.

Download rsync_bpc source code;

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

Compile and install the rsync_bpc module;

cd rsync-bpc
./configure

This configures rsync_bpc with the default options. You can check other configuration options with the command, ./configure --help.

Compile and install rsync_bpc;

make
make install

Install BackupPC on Ubuntu 20.04

Once all the above is done, you can now install BackupPC itself. Download the source code cloning the Github repository;

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

Navigate to backup source directory;

cd backuppc

Generate the latest release BackupPC tarball from the source file and BackupPC build tools;

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

This creates BackupPC tarball and store is under dist directory in the current working directory as, dist/BackupPC-4.3.2.tar.gz.

Extract the source code;

tar zxf dist/BackupPC-4.3.2.tar.gz

Build and install and setup BackupPC server on Ubuntu 20.04;

cd BackupPC-4.3.2
perl configure.pl

The script when executed in this way, will run interactively. Answer the prompts accordingly. Press ENTER to accept the defaults.

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!

If you want to run non-interactive installation;

./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

Configure Apache Web Server for BackupPC

Copy the sample BackupPC Apache configuration file to Apache enabled configurations directory;

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

Next, configure Apache to allow external access to BackupPC;

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

Configure Apache to run as BackupPC user, backuppc.

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

Remove the set-uid from BackupPC admin CGI file;

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

Configure BackupPC Apache Basic Authentication

Change the Basic authentication file if you so wish;

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

Change the basic authentication message;

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

Create the BackupPC basic authentication user and password. This information should be stored on a file specified by the value of the AuthUserFile parameter above. For example, to create web authentication user called kifarunixadmin;

htpasswd -c /etc/BackupPC/.allowed kifarunixadmin

You can add another user, say kifarunixuser.

htpasswd /etc/BackupPC/.allowed kifarunixuser

Adjust the ownership and permissions of the auth user file;

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

Configure BackupPC Administrative User

Default Administrative user for BackupPC is defined under CGI user interface configuration settings section. Normal users can only access information specific to their host. They can also start/stop/browse/restore backups. Administrative users have full access to all hosts, plus overall status and log information. In this demo, we set the kifarunixadmin user as BackupPC admin.

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

Define BackupPC Client Backup User

By default, BackupPC uses the root user on the backup clients for backup purposes.

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

It is more secure to allow backup via a low-privileged user. In this demo, we will create a non-privileged user, backuppc, on every client to backup which is only allowed to run rsync command with sudo rights for backup purposes. Therefore, change this user accordingly.

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

We will leave other Rsync settings with the default options.\

Note that all these configurations are overwritable via the per-client configuration.

Enable BackupPC Apache configuration and CGI modules;

Run the commands below to enable BackupPC Apache configuration and CGI modules;

a2enconf BackupPC
a2enmod cgid

Disable Apache default site and Disable directory listing;

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

Hide web server version on error pages;

echo -e 'ServerSignature Off\nServerTokens Prod' >> /etc/apache2/apache2.conf

Check Apache for any errors;

apachectl -t
Syntax OK

Start and enable Apache to run on system boot;

systemctl enable --now apache2

Running BackupPC Service

Copy BackupPC sample systemd service file from the source directory;

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

Edit the service group;

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

Reload systemd service configuration;

systemctl daemon-reload

Start and enable BackupPC service;

systemctl enable --now backuppc

To check the status;

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.

Accessing BackupPC Web User Interface

If firewall is running, allow external access to Apache.

ufw allow 80/tcp

You can now access BackupPC via the URL http://server_IP_OR_hostname/BackupPC_Admin.

Authenticate and proceed to BackupPC web dashboard.

Install and Setup BackupPC Server on Ubuntu 20.04

When you authenticate as admin user, this is the interface you get;

Install and Setup BackupPC Server on Ubuntu 20.04

When you authenticate as non admin user, this is the interface you get;

Install and Setup BackupPC Server on Ubuntu 20.04

BackupPC is now installed on Ubuntu 20.04. You can now go ahead and add hosts for backing up;

Backup Linux systems with BackupPC using Rsync Protocol

Backup Windows System via SMB Using BackupPC

Backup Windows System with BackupPC Using Rsyncd

That marks the end of our guide on how to install and setup BackupPC server on Ubuntu 20.04. Enjoy!

Reference

Installing BackupPC 4 from tarball or git on Ubuntu

BackupPC Documentation: Installing BackupPC

Other Related Tutorials

Install and Configure BackupPC on Debian 10

How to Install and Configure BackupPC as a Backup Server on Ubuntu 18.04

Install and Configure BackupPC on CentOS 8

2 COMMENTS

  1. Hi gen_too,
    Thank you for writing “Install and Setup BackupPC Server on Ubuntu 20.04”.
    Its absolutely brilliant!
    I’m installing on Xubuntu 20.04 long-term support (LTS), and found the errors below.
    Perhaps these errors are very subtle differences between Xubuntu and Ubuntu
    1)
    ./makeDist –nosyntaxCheck –releasedate ‘date -u “+%d %b %Y”‘ –version $VER
    Rather than:
    ./makeDist –nosyntaxCheck –releasedate “date -u “+%d %b %Y”” –version $VER

    2)
    I couldn’t get the following to work:
    echo -e ‘ServerSignature Off\nServerTokens Prod’ >> /etc/apache2/apache2.conf
    nor:
    sudo echo -e ‘ServerSignature Off\nServerTokens Prod’ >> /etc/apache2/apache2.conf
    Error was:
    bash: /etc/apache2/apache2.conf: Permission denied
    I ended up using sudo nano to edit apache2.conf

    Apart from that, everything worked!
    I learn best by analysing practical examples of code and what it does, rather than reading pages of help syntax.
    So there was plenty of examples from different activities to demonstrate this:
    apt, sed, useradd, git, make, grep…
    I could see how all these tools can be used to create a functioning application server, namely BackupPC.
    I’m already somewhat, familiar with BackupPC having run version 3.3.2 as an app installed in ClearOS, however want to investigate using ZFS file system to replicate the BackupPC data pool offsite and need the functionality of BackupPC 4.3.2.

    Xubuntu 20.04LTS provides ZFS “out-of-the-box” and your instructions have allowed a BackupPC 4.3.2, ZFS enabled application server to be quickly built for evaluation.

    Regards,
    Daryl PILKINGTON

LEAVE A REPLY

Please enter your comment!
Please enter your name here