当前位置: 移动技术网 > 科技>操作系统>Linux > Linux如何使用backup-manager工具备份系统

Linux如何使用backup-manager工具备份系统

2018年11月08日  | 移动技术网科技  | 我要评论

  只有在电脑出了问题后才理解备份的重要的,在系统操作中,及时备份是很有必要的,backup-manager是一个命令行备份工具,下面小编就给大家介绍下linux如何使用backup-manager备份系统。

  是什么让备份管理器在众多的备份工具或备份策略中脱颖而出呢?让我来简单介绍一些它的与众不同的特性吧。

  简单的设计与管理:配置文件易于读懂和编辑,即便是初学者也很容易上手。

  一劳永逸:它在配置好后就可以通过cron周期性运作。

  支持多种协议远程备份:无缝整合多种传输协议、应用和云后端(如,ftp,scp,ssh-gpg,rsync,aws s3等等)来传输生成的归档包到一组远程主机。

  支持数据库备份:包括支持开箱即用备份mysql/mariadb和postgresql数据库。

  支持加密:备份过程中支持基于gpg文件的加密。

  在linux上安装备份管理器

  备份管理器的安装是快速而无痛的,因为它就包含在大多数linux发行版的基础软件库中。

  debian,ubuntu及其衍生版

  # aptitude install backup-manager

  在基于debian的系统中安装时,会提示你输入要存放备份归档文件的目录。如果选择的目录不存在,那么当你首次运行备份管理器时它会自动创建。

  选择ok并按回车键。

 如何使用backup-manager工具备份linux系统

  在下一步中,会询问你要备份的所有目录(用空格分隔)。建议,但不是严格要求,列出同一父目录中的几个子目录,而不要仅仅输入父目录。

  你可以跳过该步骤并在以后对配置文件中bm_tarball_directoriesb变量进行设置。否则的话,就请尽可能多地添加你想要的目录,然后选择ok:

 如何使用backup-manager工具备份linux系统

  fedora或centos/rhel

  # yum install backup-manager

  在centos/rhel上,在运行以上yum命令前,你将需要先启用epel仓库。

  配置备份管理器

  备份管理器的主配置文件是/etc/backup-manager.conf。该文件被划分为几个章节,里面定义了备份方法和相关的变量(或“键值”),这些配置让备份管理器成为一个多样化的工具,可以广泛地应付各种状况。

  出于演示目的,我们将考虑以下环境:

  每周对/etc,/home以及/var/log目录进行一次完整备份(我们将在下面通过cron设置备份的频率)。

  通过ssh传输.tar.gz备份归档文件到两台不同主机dev1和dev3上指定的目标目录。

  通过ssh备份本地mysql数据库到相同目标主机。

  用你喜爱的文本编辑器打开/etc/backup-manager.conf文件,并编辑以下变量。如果你愿意,你大可不必理会那些#开头的行。在本文中,它只是用作说明的注释: 

  # specify the backup method(s) that will be used.

  # tarball: takes a list of directories and builds the corresponding tarballs.

  # mysql: archives mysql databases using mysqldump. to restore the database, you # need to use the same tool manually.

  export bm_archive_method=“tarball mysql”

  # where to store the backups.

  export bm_repository_root=“/var/archives”

  # the following directive indicates backup-manager to name

  # the generated files after the directory that was backed up.

  export bm_tarball_nameformat=“long”

  # define the compression type for the generated files.

  export bm_tarball_filetype=“tar.gz”

  # list the directories that you want to backup.

  export bm_tarball_directories=“/etc /home /var/log”

  # exclude some subdirectories or file extensions.

  export bm_tarball_blacklist=“/var/log/myotherapp.log *.mp3 *.mp4”

  # list the database(s) that you want to backup, separated by spaces.

  export bm_mysql_databases=“mysql mybase wordpress dotclear phpbb2”

  # mysql username.

  export bm_mysql_adminlogin=“root”

  # mysql password for username.

  export bm_mysql_adminpass=“mypassword”

  # add support for drop statements (optional)。

  export bm_mysql_safedumps=“true”

  # the hostname or ip address where the database(s) reside.

  export bm_mysql_host=“localhost”

  # port where mysql server is listening.

  export bm_mysql_port=“3306”

  # compression type (optional)。

  export bm_mysql_filetype=“gzip”

  # do not archive remote hosts, but only localhost.

  bm_tarball_over_ssh=“false”

  # user account for ssh upload.

  export bm_upload_ssh_user=“root”

  # absolute path of the user‘s private key for passwordless ssh login.

  export bm_upload_ssh_key=“/root/.ssh/id_rsa”

  # remote hosts (make sure you have exported your public key to them):

  export bm_upload_ssh_hosts=“dev1 dev3”

  # remote destination for uploading backups. if it doesn’t exist,

  # this directory will be created automatically the first time

  # backup-manager runs.

  export bm_upload_ssh_destination=“/var/archives/backups/$hostname”

  运行备份管理器

  要手动运行备份管理器,请输入以下命令。你也可以选择添加‘-v’标识以便一步一步详细检查运行过程。

  # backup-manager

  bm_tarball_directories列出的目录将作为tarball备份到bm_repository_root目录,然后通过ssh传输到bm_upload_ssh_destination指定的主机dev1和dev3。

 如何使用backup-manager工具备份linux系统

  正如你在上面图片中看到的那样,备份管理器在运行的时候创建了一个名为/root/.back-manager_my.cnf的文件,mysql密码通过bm_mysql_adminpass指定。那样,mysqldump可以验证到mysql服务器,而不必在命令行以明文格式接受密码,那样会有安全风险。

  通过cron运行备份管理器

  一旦决定哪一天是进行每周备份的最佳日子(最佳时间),你可以让cron来为你运行备份管理器。

  打开root的crontab文件(注意,你必须以root登录):

  # crontab -e

  假定你想要在星期天的上午5:15分运行备份管理器,那么就添加下面这行。

  1505**0/usr/sbin/backup-manager 》/dev/null2》&1

  小结

  上面就是linux使用backup-manager备份系统的方法介绍了,相对于其他的备份工具,backup-manager更加的简单易用,是系统备份的好帮手。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网