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.
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.
sudo apt-get install backup-manager
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:
- 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).
- BM_TARBALL_DIRECTORIES “/etc /home /opt” Directories to backup.
- BM_TARBALL_BLACKLIST “/home/nobackup” Exclude some directories.
- 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
- 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
- BM_PRE_BACKUP_COMMAND "" Execute a command before the backup
- BM_POST_BACKUP_COMMAND "" Execute a command after the backup
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’;
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”
Mysql database compression after dump.
- export BM_MYSQL_FILETYPE="bzip2"*
Make sure that bzip2 is intalled
sudo apt-get install bzip2
Execute a command once bakcup done. You can,for example, use this to send an email after the backup.
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
test -x /usr/sbin/backup-manager || exit 0
And now you can add this script to your contab
1 0 * * * /etc/backup-manager.sh
Here is ubuntu cron doc, easy to understand (https://help.ubuntu.com/community/CronHowto)
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