Easy Linux backups with Backupninja

There are actually three ways to make scheduled backups on Linux:

  1. Spend the rest of your life learning how to setup Bacula
  2. Spend the rest of your life writing shell scripts
  3. Spend 15 minutes to install and setup backupninja and go enjoing life (or trolling on imageboards;)

I've tried with 1-2 but found that this ways are not for me and suggesting the same decision to you. First of all install it with friends:

$sudo apt-get install backupninja duplicity rdiff-backup

Then have a look at: /usr/share/doc/backupninja/examples/ and copy your example to /etc/backup.d with the numbered and extensioned file name and edit it to suit your needs, for example to make daily bakcup of MySQL databases I have the following /etc/backup.d/50-dailyallbases.mysql file:

#when = everyday at 16:28 # by default when is daily 1:00 AM but you can override it

databases   = all
backupdir   = /mnt/store/backups/mysql/daily
hotcopy     = yes
sqldump     = yes
compress    = yes

first number in filename defines order of script execution, if two or more scripts are scheduled at one time, the one prefixes with less number will be executed first and only when it's finished the second will start. This allows to have simple dependecy e.g. to deliver my backups to storage server I use another script /etc/backup.d/60-dailymydqldeliver.dup that uses duplicity to create backup of local catalog. Here is it's contents:

testconnect = no

sign = no
password = somepassword # to decrypt backuped data

## files to include in the backup
include = /mnt/store/backups/mysql
incremental = no
desturl = scp://someshelluser:someshellpass@someservernameorip/pathtostorebackuponserver

As and alternative you may use key authentication. Create key and add it's public part to your backup host:

#ssh-keygen -t dsa
#ssh-copy-id -i /root/.ssh/ backup@desthost

then instead

sshoptions = -o IdentityFile=/root/.ssh/id_dsa
desthost = someservernameorip
destdir = /path/to/backups
destuser = someshelluser

Pay attention to sshoptions directive, it's changed for newer versions, and old variant  (from official docs with using -i key to use identity file) will not work. Also you probably should no start destdir with / in case you are not storing the data outside home of backup user. If you experiencing any problems with, feel free and brave to open helper files from /usr/share/backupninja/ and investigate how things are working.

So backup delivery will start atfter database backup is finished. Your should create user on your server and either give it paswordless access (with ssh certificates) or use scp for delivery.

Don't forget to create all necessarry catalogs, give permissions and test your configurations with running backupninja with keys -t and -n