Nicolas Alpi, Web developer

A blog about productivity, startups and me.

Starting With Backup-manager, or How to Never Loose Data Again!

Loosing data can be quite ... annoying.

The last thing you want is to have a disaster on your server and being unable to recover your data.
I run all my projects and different blogs on one server, hosted by OVH. So I have multiple databases, gems, websites and configurations that I want to backup.
Hopefully, OVH provide with every dedicated server an external FTP server dedicated to backups.
So I’ve installed backup-manager and make it runs twice a day.

Warning

Because backup-manager compress your files into archives, it will cost you some space on the disk, so be sure to change the default value of the target and do your backup on a proper partition.
If you don’t, backup-manager will do the backups in / by default, so when it’ll be full, your sever will not work properly.

Installation

sudo apt-get install backup-manager

Tweacking

Installation create a default config file. You’ll need to edit it to match you configuration.

sudo vim /etc/backup-manager.conf

Before I explain you my config file, here is how I’ve config my server:

  • I have 4 PHP Applications (Blogs/apps) and 3 Ruby on Rails apps running on it.
  • Each application has it own directory in /home/ .
  • REE is installed in /opt, and so are the gems.
  • I keep an automatic backup of my server configurations (DNS/Host/Users/Right…) in /home/config (Only accessible by root).
  • I’ve created an new partitions call “/backups”.

So basically, want I want is:

I save my /home/, /etc/, /opt/, all my databases to an external partition then an external FTP.

In backup-manager.conf, you’ll need to set:

Local Storage

  • BM_REPOSITORY_ROOT “/backups” Where to store local backups.
  • BM_ARCHIVE_TTL “3” Local archive time to live.
  • BM_ARCHIVE_METHOD “tarball” Which archive method do you want to use (You can mix and match different types).

Backup directories

  • BM_TARBALL_DIRECTORIES “/etc /home /opt” Directories to backup.
  • BM_TARBALL_BLACKLIST “/home/nobackup” Exclude some directories.

Backup transfer

  • BM_UPLOAD_METHOD “ftp” Backups transfer method.
  • BM_UPLOAD_FTP_USER “myftpusername” FTP login.
  • BM_UPLOAD_FTP_PASSWORD “myFtpPassw0rd” FTP Password.
  • BM_UPLOAD_FTP_HOSTS “ftp.backups.com” FTP Server.
  • BM_UPLOAD_FTP_PURGE “true” Clear the remote directory before to upload.
  • BM_UPLOAD_FTP_DESTINATION “/” Upload existing directory.

Incremental Archives (set BM_ARCHIVE_METHOD = tarball-incremental)

  • BM_TARBALLINC_MASTERDATETYPE “monthly” Complete archive creation frequency (daily or monthly)
  • BM_TARBALLINC_MASTERDATEVALUE “23” Creation day of the complete archive

Mysql databases

  • BM_MYSQL_DATABASES “mysql1 db2 db3”“ALL” mysql db names separate by space or ALL
  • BM_MYSQL_ADMINLOGIN “backupuser” Mysql user (DO NOT USE ROOT!, see below)
  • BM_MYSQL_ADMINPASS “backuppassword” Mysql user password
  • BM_MYSQL_HOST “localhost” Mysql Server
  • BM_MYSQL_PORT “3306” Mysql port
  • BM_MYSQL_FILETYPE “bzip2” Backup compression method

Others

  • BM_PRE_BACKUP_COMMAND "" Execute a command before the backup
  • BM_POST_BACKUP_COMMAND "" Execute a command after the backup

Pratical Backups

Databases

Please be careful, as you’ll need to write in this file the login and password of a user to procede to dabases backups.
Don’t use root!, neither an existing user. You’re going to create a new user, with limited right on databases and tables, and you’ll protect the backup manager config file.

mysql -u root -p

GRANT SHOW DATABASES,SELECT,LOCK TABLES ON . TO ’backupuser’@’localhost’ IDENTIFIED BY ‘secretpassword’;
exit;
sudo chown root:root /etc/backup-manager.conf
sudo chmod 640 /etc/backup-manager.conf

Now you can set the 2 values in the backup-manager config file.

  • export BM_MYSQL_ADMINLOGIN=“backupuser”
  • export BM_MYSQL_ADMINPASS=“secretpassword”

BM_MYSQL_FILETYPE

Mysql database compression after dump.

  • export BM_MYSQL_FILETYPE="bzip2"*

Make sure that bzip2 is intalled

sudo apt-get install bzip2

BM_POST_BACKUP_COMMAND

Execute a command once bakcup done. You can,for example, use this to send an email after the backup.

Automated backups

You can use cron to schedule your backups. Before just create a little script

cat << EOF > /etc/backup-manager.sh && chmod 700 /etc/backup-manager.sh

#!/bin/sh
test -x /usr/sbin/backup-manager || exit 0
/usr/sbin/backup-manager
EOF

And now you can add this script to your contab

crontab -e

And add

1 0 * * * /etc/backup-manager.sh

Here is ubuntu cron doc, easy to understand (https://help.ubuntu.com/community/CronHowto)

Do more

For example, you can call backup-manager with backup-manager -c /path/to/configfile and by this way, having 2 crons. One running every days, executing backups of files and db, and another one, in the middle of the day, only for the db ;).

You can do much more than these options (cd/dvd burning for example), please be sure you read the complete wiki at http://wiki.backup-manager.org/index.php/Main_Page#Documentation

Comments