2021年1月

This is a basic guide on how to install BackupPC version 4.3.1 from tarball (or git) on CentOS 7.6. We use the epel-release repository for several packages. We also temporarily use the epel-testing repository to install BackupPC-XS and rsync-bpc.

1. Enable the epel-release repo.

yum --enablerepo=extras -y install epel-release

2. Install BackupPC-XS and rsync-bpc

yum --enablerepo=epel-testing -y install BackupPC-XS rsync-bpc

3. Install the following requisites for BackupPC version 4.3.1

yum -y install bzip2 httpd mod_perl par2cmdline perl-Archive-Zip perl-CGI \
perl-Compress-Raw-Zlib perl-Data-Dumper perl-Digest-MD5 perl-File-Listing \
perl-File-RsyncP perl-Net-FTP-AutoReconnect perl-Net-FTP-RetrHandle \
perl-Time-ParseDate perl-XML-RSS perl-version rrdtool samba-client

4. Lets set up some directories that we are going to use later.

My backuppc server has a raid6 array mounted at /data0/. I am going to use this to store the data for backuppc. Lets create the backuppc folder on my raid. Note: this folder can grow to be extremely large.

mkdir -p /data0/backuppc

Now lets create one more folder for BackupPC to store some web interface files.

mkdir -p /var/www/html/backuppc

And create the cgi-bin directory for backuppc

mkdir -p /var/www/cgi-bin/backuppc

Make note of those 2 directories. The installer will ask for them if we don't explicitly set them below.

5. Create and setup the backuppc user.

Create group backuppc.

groupadd backuppc

Create backuppc user, and tell it where its home folder is. My backuppc user's home folder is /opt/backuppc. Change this to whatever you'd like.

useradd --home-dir /opt/backuppc --create-home --shell /bin/bash --base-dir /opt/backuppc --gid backuppc backuppc

6. Set Permissions on the directories we created:

chown -R backuppc:backuppc /data0/backuppc
chown -R backuppc:backuppc /opt/backuppc

7. Download the BackupPC tar.gz archive and extract it.

cd ~
wget https://github.com/backuppc/backuppc/releases/download/4.3.1/BackupPC-4.3.1.tar.gz
tar zxf BackupPC-4.3.1.tar.gz
cd BackupPC-4.3.1

8. Run the configure.pl script

Pay close attention to the paths in this command.

perl configure.pl --batch --cgi-dir /var/www/cgi-bin/backuppc \
--data-dir /data0/backuppc --hostname backuppc --html-dir /var/www/html/backuppc \
--html-dir-url /backuppc --install-dir /opt/backuppc

Alternatively, you can execute the perl script with no arguments and it will walk you through the install step by step. This is the preferred method if you are upgrading a version 3.X install. (Not supported by this guide)

perl configure.pl

9. Apache config

I chose the CGI route (not S-CGI) and chose the directory /var/www/cgi-bin/backuppc for my CGI directory. I chose /var/www/html/backuppc as my images directory. You may need to set this path in the config if you ran the configure.pl script with no arguments.

Now we need to copy the Apache config into the apache conf.d directory.

cp httpd/BackupPC.conf /etc/httpd/conf.d/

Note: This file contains "deny from all" and "allow from 127.0.0.1". This makes it so you can only load the BackupPC web interface from the server its self. You can modify this to your liking. I deleted the line "allow from 127.0.0.1" and changed "deny from all" to "allow from all".

We need to modify the user that apache runs as.

vim /etc/httpd/conf/httpd.conf

Edit httpd.conf and change: User apache to User backuppc

Note: This has the potential to break things if you use Apache for any purpose other than BackupPC. I wasn't able to figure out how to get this working without modifying this. If you have any information that would help, please update this wiki!

10. Install the included systemd script:

cp systemd/backuppc.service /etc/systemd/system/
systemctl daemon-reload
systemctl start backuppc
systemctl enable backuppc

11. Create the backuppc authentication file.

htpasswd -c /etc/BackupPC/BackupPC.users backuppc

Note: this sets the username to backuppc (modify it to your liking)

Set permissions on this file.

chown backuppc:backuppc /etc/BackupPC/BackupPC.users

12. Edit the config.pl file in /etc/BackupPC/

vim /etc/BackupPC/config.pl

Check the image directory and image url variables.

$Conf{CgiImageDir} = '/var/www/html/backuppc';
$Conf{CgiImageDirURL} = '/backuppc';

Also add backuppc as the administrative user: $Conf{CgiAdminUsers} = 'backuppc';

13. Now lets start apache

systemctl start httpd
systemctl enable httpd

14. Access the BackupPC Admin interface:

http://yourserverip/BackupPC_Admin

Log in with the username and password we created in step 11.


Centos在安装时使用了默认磁盘安装,系统装好后/home空间较大,/下的空间一般会默认分50G给/分区,在使用一段时间后/分区的空间会不够用情况,但是/home空间还剩余很多,我们可以动态的将/home空间分配给/,具体的话可以根据自己的情况去分配,分配前记得“备份”。

以我司为例,我先在测试环境测试,避免在生产环境出现问题,模拟/分区磁盘不够,扩容/分区的磁盘空间,磁盘总空间为1TB。

1、查看系统的空间。

df -hT

因很多的服务使用yum安装,或有些服务装在了/下面,慢慢的/的磁盘空间就会存在空间不足,而/home分区的空间又很大。

2、 先将home分区进行备份,删除/home文件系统所在的逻辑卷,增加/文件系统的大小,最后重新创建/home分区,并恢复/home下的数据。

tar -zcvf /opt/home.tar.gz /home/*

如果数据比较大,可以将备份放到/home下,然后下载到本地,或者通过scp传到其它服务器零时保存。

3、 卸载/home空间,如在/home目录下安装过服务,请先关闭服务,并结束进程,避免恢复都启动不起来。

终止/home下面所有进程。

fuser -km /home

卸载/home空间

umount /home

df -hT

删除/home所在的逻辑卷lv

lvremove /dev/mapper/centos-home

4、扩大/分区的空间,这里增加100G,增加100G后,还剩870G还是给/home,根据你自己的需求,进行扩容。

lvextend -L +100G /dev/mapper/centos-root

扩大/文件系统。

xfs_growfs /dev/mapper/centos-root

5、 重建/home文件系统所系的逻辑卷

/home空间总共971G,分配的100G给/还剩871G,因此我门这里创建的逻辑卷大小为871G。

lvcreate -L 871G -n/dev/mapper/centos-home

上图报空间不足,是文件系统的一种机制吧,感兴趣的可以去研究一下。我们试试分配870G,看是否可以。

lvcreate -L 870G -n/dev/mapper/centos-home

逻辑卷已经创建好了。

创建xfs文件系统。

mkfs.xfs /dev/mapper/centos-home

还是将文件系统挂载至/home目录下。

mount /dev/mapper/centos-home

df -hT

可以看到已经达到我们的目的,现在我们将/home下的数据恢复。

cd /opt/   :切换至备份目录,将其解压。

tar -zxvf home.tar.gz -C /

数据已经恢复,启动看看服务是否正常运行。

本文参考地址:https://blog.csdn.net/u013431916/article/details/80548069


情况:

  1. home:500G

  2. root:50G

  3. root分区不够用

思路:把home分区的空间划一部分到root分区

1
2
3
4
5
6
7
8
# 设置home分区大小为200G,释放300G空间
$ lvreduce -L 200G /dev/centos/home
 
# 将空闲空间扩展到root分区
$ lvextend -l +100%FREE /dev/centos/root
 
# 使用XFS文件系统自带的命令集增加分区空间
$ xfs_growfs /dev/mapper/centos-root

实例

situation

挂载在根目录的分区 /dev/mapper/centos-root 爆满,占用100%

1
2
3
4
5
6
7
8
9
10
$ df -h
Filesystem        Size Used Avail Use% Mounted on
/dev/mapper/centos-root  50G  50G  19M 100% /
devtmpfs         32G   0  32G  0% /dev
tmpfs           32G   0  32G  0% /dev/shm
tmpfs           32G 2.5G  29G  8% /run
tmpfs           32G   0  32G  0% /sys/fs/cgroup
/dev/mapper/centos-home 476G  33M 476G  1% /home
/dev/sda1        497M 238M 259M 48% /boot
tmpfs          6.3G   0 6.3G  0% /run/user/0

analyze

挂载在根目录的分区空间太小,只有50G,而服务器 home 目录为非常用目录,挂在了近500G的空间。

思路:从 centos-home 分区划出300G空间到 centos-root 分区。

operation

1.查看各分区信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$ lvdisplay
--- Logical volume ---
LV Path        /dev/centos/home
LV Name        home
VG Name        centos
LV UUID        1fAt1E-bQsa-1HXR-MCE2-5VZ1-xzBz-iI1SLv
LV Write Access    read/write
LV Creation host, time localhost, 2016-10-26 17:23:47 +0800
LV Status       available
# open         0
LV Size        475.70 GiB
Current LE       121778
Segments        1
Allocation       inherit
Read ahead sectors   auto
- currently set to   256
Block device      253:2
 
--- Logical volume ---
LV Path        /dev/centos/root
LV Name        root
VG Name        centos
LV UUID        lD64zY-yc3Z-SZaB-dAjK-03YM-2gM8-pfj4oo
LV Write Access    read/write
LV Creation host, time localhost, 2016-10-26 17:23:48 +0800
LV Status       available
# open         1
LV Size        50.00 GiB
Current LE       12800
Segments        1
Allocation       inherit
Read ahead sectors   auto
- currently set to   256
Block device      253:0

2.减少/home分区空间

1
2
3
4
5
6
7
8
# 释放 /dev/centos/home 分区 300G 的空间
# 命令设置 /dev/centos/home 分区 200G空间
$ lvreduce -L 200G /dev/centos/home
WARNING: Reducing active logical volume to 200.00 GiB.
 THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce centos/home? [y/n]: y
 Size of logical volume centos/home changed from 475.70 GiB (121778 extents) to 200.00 GiB (51200 extents).
 Logical volume centos/home successfully resized.

3.增加/root分区空间

1
2
3
$ lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from 50.06 GiB (12816 extents) to 325.76 GiB (83394 extents).
Logical volume centos/root successfully resized.

4.扩展XFS文件空间大小

1
2
3
4
5
6
7
8
9
10
11
$ xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256  agcount=4, agsize=3276800 blks
     =            sectsz=512  attr=2, projid32bit=1
     =            crc=0    finobt=0 spinodes=0
data   =            bsize=4096  blocks=13107200, imaxpct=25
     =            sunit=0   swidth=0 blks
naming  =version 2       bsize=4096  ascii-ci=0 ftype=0
log   =internal        bsize=4096  blocks=6400, version=2
     =            sectsz=512  sunit=0 blks, lazy-count=1
realtime =none          extsz=4096  blocks=0, rtextents=0
data blocks changed from 13107200 to 85395456

完成

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。


BackupPC安装所需的主要的安装包下载地址:http://pan.baidu.com/s/1bnCGCY7 (BackupPC的版本为3.2.1)

(该版本的BackupPC是支持中文的,BackupPC配置好后,可以在其Web页面设置其显示语言即可)

1、添加backuppc组及用户

groupadd   backuppc

useradd   -g   backuppc   backuppc

2、安装httpd、mod_perl及BackupPC

yum   install   httpd   mod_perl

(以下安装的BackupPC和Perl*均在之前的下载包里面)

rpm   -ivh   BackupPC-3.2.1-10.el6.i686.rpm

rpm   -ivh   perl-*

3、设置页面访问权限

vim /etc/httpd/conf.d/BackupPC.conf

修改内容如下

# htpasswd   -c   /etc/BackupPC/apache.users   yourusername

order allow,deny

allow   from   all    ——》将 deny   from   all改成allow   from   all

#allow from 127.0.0.1 114.255.58.130

AuthType Basic

AuthUserFile   /etc/BackupPC/apache.users

AuthName   “BackupPC

require valid-user

</Directory>

Alias           /BackupPC/images        /usr/share/BackupPC/html/

ScriptAlias     /BackupPC               /usr/share/BackupPC/sbin/BackupPC_Admin

4、更改目录的属用户/组

chown   -R   backuppc:backuppc   /etc/BackupPC

chown   -R   backuppc:backupc   /var/lib/BackupPC

5、编辑BackupPC主配置文件

$Conf{CgiAdminUsers} = ‘backuppc’;  ——》查找到$Conf{CgiAdminUsers} 在其后面加上backuppc

6、建立用户验证文件

htpasswd -c  /etc/BackupPC/apache.users backuppc

New password: 1234

Re-type new password:1234

Adding password for user backuppc

7、启动Apache服务并设置run level 3自启动

service    httpd    start

chkconfig   –level    3    httpd   on

8、设置Backuppc用户运行指定命令

运行:visudo

修改如下:

##查到到 Defaults requiretty,并将其注释掉

##并加入以下两行信息.

Defaults !lecture

backuppc ALL=NOPASSWD:/bin/gtar,/bin/tar

9、Windows客户端配置

安装cygwin-rsyncd-3.0.9.0_installer(下载包中有)

安装完毕,修改rsyncd.conf的配置文件

#

[cDrive]    ——》与截图中位置的信息保持一致

path = /cygdrive/【要备份的盘符】/

read only = true

transfer logging = no

#auth users = backup

#secrets file = passwd

以上配置完毕后,即可开始备份了

BackupPC使用中的几个常见问题:


1、当开始完全备份时,无法正常开始备份,会提示以下错误:

Can’t call method “getStats” on an undefined value at /usr/share/BackupPC/bin/BackupPC_dump line 1160.

解决方法:

# vim   /usr/share/BackupPC/bin/BackupPC_dump

找到其1159行,内容如下:

if   ( $type   eq   “full” )    将其改成:if ( $type eq   “full”   &&   defined  ($xfer))

2、挂载其它的磁盘到BackupPC的备份目录(/var/lib/BackupPC)下时,backuppc服务无法启动,提示以下错误:

Can’t create a test hardlink between a file in /var/lib/backuppc/pc and /var/lib/backuppc/cpool

解决方法:

1)挂载后,在BackupPC的目录下新建4个文件夹:cpool、pc、pool、trash

创建方法:mkdir /var/lib/BackupPC//pc /var/lib/BackupPC//cpool /var/lib/BackupPC//pool  /var/lib/BackupPC//trash

(注意:我上面写的是没有错的,多的一个/是不能省的,不然还会出现其它错误(后期的PC数据备份中,会导致无法浏览其备份的数据信息,还有备份时所产生的日志)。)

2)将其创建的4个文件夹的权限都设置为backuppc:  chown  -R  backuppc:backuppc  cpool  pc  pool  trash


【CentOS】部署开源企业级Linux备份工具—BackupPC,布布扣,bubuko.com


Contents

 [hide

Setup

  • apt-get install apache2 backuppc libfile-rsyncp-perl

  • add to /etc/aliases

backuppc: root

If you use a dedicated disk or partition:

  • prefer reiserfs over ext3 to avoid any inode shortage problem.

  • mount it with "noatime" for better performances

  • If you've to move an existing setup, move /var/lib/backuppc to the dedicated partition but preserve hardlinks (use cp -a), then create /var/lib/backuppc symlink

To create/change http passwords:

 htpasswd /etc/backuppc/htpasswd backuppc

To create a new user:

htpasswd /etc/backuppc/htpasswd user

add to /etc/aliases

user: user@email.com

To prepare backuppc to access the hosts:

su - backuppc
ssh-keygen -t rsa -N ''

For a full restoration from scratch, see the backuppc paragraph in Harddrive

Whenever you change the config files, be sure to have the proper permissions:

chown backuppc:www-data /etc/backuppc/*
chmod go-rwx /etc/backuppc/*pl

Apache2

ln -s /etc/backuppc/apache.conf /etc/apache2/sites-enabled/backuppc

Add a host for backup

  • add it to /etc/backuppc/hosts

  • create a file such as /etc/backuppc/<host>.pl with the same name and with variables from config.pl that you want to adapt for your host

  • scp /var/lib/backuppc/.ssh/id_rsa.pub root@<host_to_backup>:

  • on the host:

    • cat id_rsa.pub >> ~/.ssh/authorized_keys

    • prepend the line in authorized_keys by sth like
      from="<my_backup_server>"
      so that only the backup host can log with this key.

    • install a ssh server if not yet done

    • install rsync

  • Try once as user backuppc to log as root on your host, first to accept the fingerprint, second to check if you are in without prompt for pwd

  • Reload hosts in backuppc: /etc/init.d/backuppc reload

Troubleshooting

Backup failed and you've only a very poor error message?

For example:

Got fatal error during xfer (Unable to read 4 bytes)

There are more complete logfiles in /var/lib/backuppc/pc/*yourmachine*/XferLOG.bad.z
But they're compressed with libz (I think) so to read the file:

$ /usr/share/backuppc/bin/BackupPC_zcat /var/lib/backuppc/pc/*yourmachine*/XferLOG.bad.z

To continue on the same example, here we got:

full backup started for directory /blabla
Running: /usr/bin/ssh -q -x -l root yourmachine /usr/bin/rsync --server --sender --numeric-ids --perms --owner --group -D --links --hard-links --times --block-size=2048 --recursive --bwlimit=1500 --ignore-times . /blabla
Xfer PIDs are now 10100
Read EOF: Connection reset by peer
Tried again: got 0 bytes
Done: 0 files, 0 bytes
Got fatal error during xfer (Unable to read 4 bytes)
Backup aborted (Unable to read 4 bytes)
Not saving this as a partial backup since it has fewer files than the prior one (got 0 and 0 files versus 0)

Ok ssh command failed. Let's try it:

# su - backuppc
$ /usr/bin/ssh -l root yourmachine ls
The authenticity of host 'yourmachine (1.2.3.4)' can't be established.
RSA key fingerprint is bl:ab:la
Are you sure you want to continue connecting (yes/no)? yes

So that's was the issue! That's what happen when you miss the last step in the paragraph about adding a host, just here above!

To invert tunnelling (if from behind a firewall)

  • On the host:

    • ssh -R 2222:localhost:22 <backup_server>
      Make it passwordless with keys

    • To make it automated: install autossh
      Add somewhere in the startup scripts:
      su <my_local_user> -c 'autossh -N -f -M 29001 -R 2222:localhost:22 <backup_server>' &

    • Or in /etc/network/interfaces
      up su <my_local_user> -c 'autossh -N -f -M 29001 -R 2222:localhost:22 <backup_server>' &
      down su <my_local_user> -c 'killall autossh'

  • On the server:

    • Host <host_to_backup_as_said_to_backuppc>

    • ~HostName <localhost or ip_pub for vservers>

    • Port 2222

    • backuppc ~/.ssh/config:

Restoring

Deleting backups

I was used to do it manually but there is a nice script here, probably handling it less wildly than what I did...

Tips

When upgrading to rsync 2.6.7 on the clients you could face some problems.
This is due to a different interpretation of the option --devices
Use -D instead for sth compatible with all rsync versions.
Change it in config.pl and other host config files: $Conf{RsyncArgs} and $Conf{RsyncRestoreArgs}
cf http://sourceforge.net/mailarchive/forum.php?thread_id=10176480&forum_id=503

Notes on new install

On the Fit PC

http://cdimage.debian.org/mirror/cdimage/unofficial/non-free/cd-including-firmware/current/i386/iso-cd/firmware-8.6.0-i386-netinst.iso

LVM

  • VG fitpc-vg

    • ext4; label HOME; use as /home; noatime,nodirtime; usage:news (more inodes)

    • swap

    • LV swap 2G => crypto; random key

    • LV root 23G => ext4; label ROOT; use as /

    • LV home 500G => crypto

Mounting encrypted home & swap failed during install -> mark them as "do not use" and see later.

  • web server ; ssh server ; standard utils

Reboot

Encrypt swap:

Create /etc/crypttab

 cswap1          /dev/disk/by-id/dm-name-fitpc--vg-swap       /dev/urandom    swap,cipher=aes-xts-plain64,size=256,hash=sha1

Add to /etc/fstab

 /dev/mapper/cswap1  none        swap    sw            0       0

Mount and format

 cryptdisks_start cswap1
 mkswap /dev/mapper/cswap1

Activate swap

 swapon -a
 free

Handle encrypted home:

Add to /etc/crypttab

 home_crypt      /dev/disk/by-id/dm-name-fitpc--vg-home       none luks,noauto

Add to /etc/fstab

 /dev/mapper/home_crypt     /home_crypt     ext4    noatime,nodiratime,noauto,errors=remount-ro 0 0

Create fs

 cryptdisks_start home_crypt
 mkfs.ext4 -i 4096 /dev/mapper/home_crypt
 mount /home_crypt

Edit /etc/hosts

127.0.1.1 fitpc.xxx.be fitpc
192.168.1.2 fitpc
...

Install stuff

 apt-get install mc screen backuppc

Move backuppc

 systemctl disable backuppc
 /etc/init.d/backuppc stop
 cp -a /var/lib/backuppc/ /home_crypt/
 rm -rf /var/lib/backuppc/
 ln -s /home_crypt/backuppc /var/lib/
 /etc/init.d/backuppc start

/root/backuppc :

 #!/bin/bash
 cryptdisks_start home_crypt
 mount /home_crypt
 /etc/init.d/backuppc start

Fix /etc/backuppc/apache.conf:

Options ExecCGI FollowSymlinks
=>
Options +ExecCGI +FollowSymlinks

then

service apache restart

Update web passwd and create key:

htpasswd /etc/backuppc/htpasswd backuppc
su - backuppc
ssh-keygen -t ed25519 -N 
exit

Sensors:

apt-get install lm-sensors sensord
sensors-detect # use default, no need for optional scans
# -> coretemp
echo -e "chip \"acpitz-virtual-0\"\n        ignore temp1\n        ignore temp" > /etc/sensors.d/fitpc-sensors.conf

Read sensors:

sensors
acpitz-virtual-0
Adapter: Virtual device

coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +51.0°C  (crit = +90.0°C)

Edit /etc/default/sensord

ALARM_INTERVAL=1m
LOG_INTERVAL=30m
SYSLOG_FACILITY=daemon
RRD_FILE=/var/log/sensord.rrd
RRD_INTERVAL=5m
RRD_LOADAVG=yes
service sensord restart

Emails: Change /etc/exim4/update-exim4.conf.conf

dc_eximconfig_configtype='smarthost'
dc_smarthost='smtp.belgacom.net'
update-exim4.conf
service exim4 restart

Change /etc/email-addresses (= From:)

root: some_valid_email
backuppc: some_valid_email

Add to /etc/aliases (= To: for backuppc users)

myuser: some_valid_email

Edit /etc/mailname

xxx.be

Fix localhost backup (auth errors):

apt-get install sudo
echo "backuppc ALL = NOPASSWD: /bin/tar" > /etc/sudoers.d/backuppc

Then edit /etc/backuppc/localhost.pl

$Conf{TarClientCmd} = '/usr/bin/env LC_ALL=C $tarPath -c -v -f - -C $shareName'
=>
$Conf{TarClientCmd} = '/usr/bin/env LC_ALL=C /usr/bin/sudo $tarPath -c -v -f - -C $shareName'

Add a machine:

  • Add machine in /etc/hosts

192.168.x.x mymachine
  • From machine: (assuming fitpc2 is in its /etc/hosts, warning some devices don't seem to support the "from=")

sudo apt-get install openssh-server rsync
(echo -n "from=\"<IP_of_fitpc2>\" ";ssh root@fitpc2 cat /var/lib/backuppc/.ssh/id_ed25519.pub) |sudo tee -a /root/.ssh/authorized_keys
  • Test from the server twice (once to accept fingerprint, once to check):

su -c "ssh root@mercure_eth" - backuppc
  • Add it to /etc/backuppc/hosts

mymachine 0       myuser   backuppc
  • Create a file /etc/backuppc/<host>.pl with the same name as in /etc/hosts and /etc/backuppc/hosts and with variables from config.pl that you want to adapt for your host

  • Reload

service backuppc reload