Use backup-manager for system backup on Linux-Alibaba Cloud Developer Community

Whether it is simple or not, we all have the opportunity to understand such a thing, that is, the importance of backup can never be underestimated. Considering that there are so many backup methods, you may want to know how to effectively choose the right tools and appropriate strategies for your system.

In this article, I will introduce backup-manager, an easy-to-use command-line backup tool, which can be seen in most standard software libraries of Linux distributions.

What makes the backup manager stand out from many backup tools or policies? Let me briefly introduce some of its distinctive features:

  • simple design and management : the configuration file is easy to read and edit, and it is easy for beginners to use.
  • Once and for all : it can operate periodically through cron after being configured.
  • Supports remote backup over multiple protocols : seamlessly integrates multiple transmission protocols, applications, and cloud backend (such as FTP,SCP,SSH-GPG,rsync, and AWS S3) to transmit the generated archive packages to a group of remote hosts.
  • Supports database backup. : supports out-of-the-box backup of MySQL, MariaDB, and PostgreSQL databases.
  • Supports encryption. : supports GPG-based encryption during backup.

Install backup manager on Linux

the installation of backup manager is fast and painless because it is included in the basic software libraries of most Linux distributions.

Debian,Ubuntu, and its derivatives

  1. # aptitude install backup - manager

when you install it in a Debian-based system, you are prompted to enter the directory where the backup archive files are to be stored. If the selected directory does not exist, it is automatically created when you run the backup manager for the first time.

Select OK and press enter.

In the next step, you will be asked about all the directories that you want to back up (separated by spaces). We recommend that you list several subdirectories in the same parent directory instead of simply entering the parent directory.

You can skip this step and set the BM_TARBALL_DIRECTORIESb variable in the configuration file later. Otherwise, please add as many directories as possible and select OK:

Fedora or CentOS/RHEL

  1. # yum install backup - manager

on CentOS/RHEL, you must enable EPEL repository before running the yum command above.

Configure backup manager

the primary configuration file of the backup manager is/etc/backup-manager.conf. The file is divided into several chapters, which define backup methods and related variables (or "key values"). These configurations make the backup manager a diversified tool, A wide range of situations can be dealt.

For demonstration purposes, we will consider the following environments:

Open the/etc/backup-manager.conf file with your favorite text editor and edit the following variables. If you like, you don't have to pay attention to those lines starting. In this article, it is only used as a description:

  1. # Specify the backup method ( S ) that will be used .
  2. # tarball : takes a list of directories and builds the corresponding tarballs .
  3. # mysql : archives MySQL databases using mysqldump . To restore the database , you # need use the same tool manually .
  4. Export BM_ARCHIVE_METHOD = "tarball mysql"
  6. # Where to store the backups .
  7. Export BM_REPOSITORY_ROOT = "/var/archives"
  9. # The following directive indicates backup - manager to name
  10. # the generated files after the directory that was backed up .
  11. Export BM_TARBALL_NAMEFORMAT = "long"
  13. # Define the compression type for the generated files .
  14. Export BM_TARBALL_FILETYPE = "tar.gz"
  16. # List the directories that you want to backup .
  17. Export BM_TARBALL_DIRECTORIES = "/etc /home /var/log"
  19. # Exclude some subdirectories or file extensions .
  20. Export BM_TARBALL_BLACKLIST = "/var/log/myotherapp.log *.mp3 *.mp4"
  22. # List the database ( S ) that you want to backup, separated by spaces .
  23. Export BM_MYSQL_DATABASES = "mysql mybase wordpress dotclear phpbb2"
  25. # MySQL username .
  26. Export BM_MYSQL_ADMINLOGIN = "root"
  28. # MySQL password for username .
  29. Export BM_MYSQL_ADMINPASS = "mypassword"
  31. # Add support for DROP statements ( optional ).
  32. Export BM_MYSQL_SAFEDUMPS = "true"
  34. # The hostname or IP address where the database ( S ) reside .
  35. Export BM_MYSQL_HOST = "localhost"
  37. # Port where MySQL server is listening .
  38. Export BM_MYSQL_PORT = "3306"
  40. # Compression type ( optional ).
  41. Export BM_MYSQL_FILETYPE = "gzip"
  43. # Do not archive remote hosts , but only localhost .
  44. BM_TARBALL_OVER_SSH = "false"
  46. # User account for SSH upload .
  47. Export BM_UPLOAD_SSH_USER = "root"
  49. # Absolute path of the user 's private key for passwordless SSH login.
  50. export BM_UPLOAD_SSH_KEY="/root/.ssh/id_rsa"
  52. # Remote hosts (make sure you have exported your public key to them):
  53. export BM_UPLOAD_SSH_HOSTS="dev1 dev3"
  55. # Remote destination for uploading backups. If it doesn' t exist ,
  56. # this directory will be created automatically the first time
  57. # backup - manager runs .
  58. Export BM_UPLOAD_SSH_DESTINATION = "/var/archives/backups/$HOSTNAME"

run the backup manager

to run the backup manager manually, run the following command. You can also choose to add the '-v' identifier to check the running process step by step.

  1. # backup - manager

the directories listed in BM_TARBALL_DIRECTORIES are backed up as tarball to the BM_REPOSITORY_ROOT directory, and then transmitted to the hosts dev1 and dev3 specified by BM_UPLOAD_SSH_DESTINATION through SSH.

As shown in the preceding figure, the backup manager creates a file named/root/.back-manager_my.cnf when running. The MySQL password is specified by BM_MYSQL_ADMINPASS. In this way, mysqldump can be verified to the MySQL server without accepting the password in plaintext format on the command line, which poses security risks.

Run the backup manager through cron

once you decide which day is the best day (best time) for weekly backup, you can have cron run the backup manager for you.

Open the root crontab File (note that you must log on as root):

  1. # crontab - E

assume that you want to run the backup manager at 5:15 a.m. on Sunday, add the following line.

  1. 15 05 * * 0 / usr / sbin / backup - manager > /dev/ null 2- > & 1


in this article, I have shown how simple, powerful and easy-to-use the backup manager is. You may have several other options to consider in your backup policy. Please refer to the manual page or user manual, which also contains several deployment instances and suggestions.

I hope this article is helpful to you, please ask and comment freely below.

Original release date: 2014-01-03

this article is from Yunqi partner linux China"

Selected, One-Stop Store for Enterprise Applications
Support various scenarios to meet companies' needs at different stages of development

Start Building Today with a Free Trial to 50+ Products

Learn and experience the power of Alibaba Cloud.

Sign Up Now