个人工具

UbuntuHelp:BackupPC

来自Ubuntu中文

119.84.131.180讨论2009年5月5日 (二) 15:36的版本 备份Linux的客户端( rsync )

跳转至: 导航, 搜索

序言

BackupPC是一个免费的备份软件与基于Web的前端。可跨平台运行于任何Linux , Solaris操作系统或Unix服务器。没有客户端不是必然的,作为服务器本身就是一个客户端的一些协议,是处理其他服务本地的客户端的操作系统。


备份方法

从客户端备份数据的三种方法如下: SMB (服务器消息块) tar (磁带存档) rsync (文件传输程序的Unix系统)

WinXX Linux/Unix/MacOSX
smb *
rsync * 1. *
tar *
  1. 1 rsync / cygwin软件需要安装在客户端 备份windows系统最简单的方法就是“SMB”协议。详见BackupPC手册

配置

要配置BackupPC有3个选择:

  Web浏览器(最简单)
  文本编辑器(超级用户) 
  两者结合(平衡) 

注: BackupPC用户手册是最重要的“文本”的基础。

BackupPC的配置文件

BackupPC的配置文件中的` / etc / backuppc directory` 。最重要的两个文件是` / etc / backuppc / config.pl `和` / etc / backuppc /hosts` 。您现在应该打开它们并且熟悉所有的配置选项。这两个文件有大量注释和评论,所以当你看到他们你也就应该明白他们能坐什么了。例如,在` / etc / backuppc / config.pl 你可以自定义BackupPC如何以及何时备份,完全备份或者是增量备份,有多少日志文件等。

nano -w /etc/backuppc/config.pl
nano -w  /etc/backuppc/hosts

安装

sudo apt-get install backuppc

添加主机

要给 BackupPC添加客户端 ,我们必须将其添加到 `/etc/backuppc/hosts`.该文件格式如下:

host        dhcp    user      moreUsers
hostname1     0     user1     anotheruser,athirduser
hostname2     1     user2     stillanotheruser

第一栏包含了主机名/ NetBIOS名称的客户端(例如` hostname1 ` ) ,第二栏是否客户端配置通过DHCP ,第三栏中会包含的用户可以登录到BackupPC web界面来管理备份客户端,第四栏(可选)包含更多的用户可以这样做。

浏览网络

smbtree是SMB浏览器程序中的文本模式。它类似于“网上邻居”上发现的Windows电脑。常用于股票服务器

smbtree -b
Password:

不输入密码,按enter键

WORKGROUP
        \\BACKUP                        backup server (Samba, Ubuntu)
                \\BACKUP\IPC$                   IPC Service (backup server (Samba, Ubuntu))
                \\BACKUP\print$                 Printer Drivers
        \\AMD6000
cli_rpc_pipe_open: cli_nt_create failed on pipe \srvsvc to machine AMD6000.  Error was NT_STATUS_ACCESS_DENIED

您的网络会有所不同,备份的名字是我们BackupPC服务器, AMD6000的名字是我们的Windows Vista电脑,我们要备份。虽然` AMD6000 `是通过DHCP配置的,的DHCP只应设置为1 ,如果下面的测试失败:

nmblookup AMD6000

如果测试是成功,它应该显示` ` AMD6000当前的IP地址:

querying amd6000 on 192.168.0.255
192.168.0.50 amd6000<00>

现在您已经知道` AMD6000 `当前的IP地址,运行相同的测试其他方位:

nmblookup -A 192.168.0.50

如果成功的话,输出应该是这样:

Looking up status of 192.168.0.50
        AMD6000         <00> -         B <ACTIVE>
        WORKGROUP       <00> - <GROUP> B <ACTIVE>
        AMD6000         <20> -         B <ACTIVE>
        WORKGROUP       <1e> - <GROUP> B <ACTIVE>

        MAC Address = 00-1A-92-B0-4C-63

这两项测试是成功的, 所以我们可以设置‘DHCP’ 到0,并且把 `AMD6000 0 user` `/etc/backuppc/hosts` 注释掉`本地` 行:

nano -w /etc/backuppc/hosts
[...]
AMD6000      0       user
#localhost   0       backuppc

如果测试没有成功,我们就可以将用户的` 1 ` AMD6000到的` / etc / backuppc /主机`相反,除了我们将不得不改变变量` $设置( DHCPAddressRanges ) `在`的/ etc / backuppc / config.pl ` 。我们已经添加了用户的用户的Hosts档案。这是该系统的用户名BackupPC将发送电子邮件报告关于` AMD6000 ' ,所以我们应该创建该用户的BackupPC服务器现在::

useradd -m user
passwd user

此外,我们必须为用户的BackupPC网络界面创建一个密码:

htpasswd /etc/backuppc/htpasswd user

(如果您喜欢您现在还可以开设第二个浏览器并登录 `user` on `http://192.168.0.51/backuppc/`.)

备份Linux的客户端( rsync )

现在,我们必须编辑 /etc/backuppc/config.pl. 备份AMD6000的方法将会用到rsync, 所以我们设置$Conf{XferMethod} = 'rsync';. AMD6000只有一个(大)分区( / ), 所以我们设置 $Conf{RsyncShareName} == '/';. 如果你有多个分区的备份,您可以指定类似 $Conf{RsyncShareName} == ['/', '/var', '/data', '/boot']; 代替. rsync将隧道通过SSH (端口22 ). SSH需要知道主机名或IP地址的客户端。除非你有一台DNS 服务器以解决AMD6000其IP地址, 否则SSH将无法解析AMD6000的名称. 因此我们设置$host with $hostIP in $Conf{RsyncClientCmd} and $Conf{RsyncClientRestoreCmd}.

nano -w /etc/backuppc/config.pl
[...]
$Conf{XferMethod} = 'rsync';

$Conf{RsyncClientPath} = '/usr/bin/rsync';
$Conf{RsyncClientCmd} = '$sshPath -q -x -l root $hostIP $rsyncPath $argList+';
$Conf{RsyncClientRestoreCmd} = '$sshPath -q -x -l root $hostIP $rsyncPath $argList+';
$Conf{RsyncShareName} = '/';
#$Conf{RsyncShareName} = ['/', '/var', '/data', '/boot'];
[...]

(You might wonder now how we can specify options for multiple clients because the options for notebook will be different from those for AMD6000. It works like this: the options in /etc/backuppc/config.pl are global values that are valid for all clients unless they have their onw configuration file in /etc/backuppc, named after their hostname. So for notebook we will create /etc/backuppc/notebook.pl, and it will contain only the values that are different from the ones in /etc/backuppc/config.pl. In fact, we could have created /etc/backuppc/falko-desktop.pl for falko-desktop instead of modifying /etc/backuppc/config.pl.)

Enable settings

Next restart BackupPC:

/etc/init.d/backuppc restart

Backup Windows Client (smb)

To make backups of Windows systems using smb, we must share the folder that we want to back up. In this case I want to backup the whole C: drive, so I right-click on it in the Windows Explorer and go to Sharing. As share name I specify C. Next, on server1.example.com, I add a line for notebook to /etc/backuppc/hosts (I do this as root). In this case I use user again as the user. If you use a different username than before, make sure you create it on the system and for the BackupPC web interface, as shown in chapter 5.

vi /etc/backuppc/hosts
[...]
AMD6000      0       user
notebook     0       user
#localhost   0       backuppc

Then create the file /etc/backuppc/notebook.pl and add all options that are different from the ones in /etc/backuppc/config.pl. In this case we add $Conf{XferMethod} == 'smb';. Our share name is C, so we put $Conf{SmbShareName} == 'C'; into it as well as the username and password for the Windows share:

nano -w /etc/backuppc/notebook.pl
$Conf{SmbShareName} = 'C';
$Conf{SmbShareUserName} = 'username';
$Conf{SmbSharePasswd} = 'password';
$Conf{XferMethod} = 'smb';

Enable Settings

Then restart BackupPC:

/etc/init.d/backuppc restart

Then reload the BackupPC web interface again. You should now find notebook in the list of clients: You can start the first backup of notebook manually or wait until BackupPC starts it:

Backup Linux Clients (tar)

BackupPC is a great backup program for an Ubuntu server. However, backing up Ubuntu client machines doesn’t work “out of the box” due to Ubuntu’s lack of a root account. The following describes how to make BackupPC work with Ubuntu's sudo implementation. By adding sudo to the TAR commands in /etc/backuppc/config.pl and adding backuppc to the sudoers list, you’re able to perform both backups and restores directly from the web-based interface.

Modify /etc/backuppc/config.pl

  • Run “sudo gedit /etc/backuppc/config.pl”
  • Add sudo to the TAR Client and ClientRestore commands
  • Change $Conf{TarClientCmd} and $Conf{TarClientRestoreCmd} to read
$Conf{TarClientCmd} = ‘sudo $tarPath -c -v -f - -C $shareName’
. ‘ –totals’;
$Conf{TarClientRestoreCmd} = ‘sudo $tarPath -x -p –numeric-owner –same-owner’
. ‘ -v -f - -C $shareName’;
  • Also remove plus (+) from $incrDate in $Conf{TarIncrArgs} so it won't be double escaped (need to escape only once when running sudo):
$Conf{TarIncrArgs} = '--newer=$incrDate $fileList+';
  • Change $Conf{BackupFilesExclude} (these seem to all be temp files that you don’t really need to backup) to read
$Conf{BackupFilesExclude} = [’/proc’, ‘/dev’, ‘/tmp’, ‘/mnt’, ‘/media’, ‘/sys’, ‘/lost+found’, ‘/usr/src’, ‘/var/lib’, ‘/var/tmp’, ‘/var/cache’, ‘/var/spool’, ‘/var/run’, ‘/var/lock’, ‘/var/games’, ‘/home/*/.Trash’, ‘/home/*/.mozilla/*/*/Cache’, ‘/home/*/.mozilla/*/*/Cache.Trash’];

Add backuppc to the sudoers list

  • Run “sudo visudo”
  • At the bottom of the file add
# Allow backuppc to run tar without a password
backuppc ALL=NOPASSWD: /bin/tar
  • If you are unfamiliar with vi editor: Scroll to the end of last line of the file, press a to start adding text, write magic lines mentioned above, hit esc, type ":w"+enter to save file, ":q" to quit (":q!" to quit without saving changes).

alternatives

For other ways of backing up some or all of your system, see BackupYourSystem .

References

Authors

  • falko