How to backupninja a samba share ?

I will explain how to configure backupninja to do an automatic incremental backup of a remote samba share. The main difficulty is that I consider that the samba share is sometime offline.

First of all we have to install backupninja, rdiff-backup and smbfs:

sudo aptitude install backupninja rdiff-backup

Then we have to create a customized backupninja handler. This is required because we have to test if the samba share is online before starting the incremental backup process.

Finally we will create a simple action to backup a samba share. Of course we could create as many actions as we need (if we had several samba share to backup).

Create the handler

Our own handler name will be zekra.

  1. We copy the rdiff handler:
    cp /usr/share/backupninja/rdiff /usr/share/backupninja/zekra
  2. We edit the file and we add this code at the end of the ### GET CONFIG ### section:
    # get the samba config
    setsection samba
    getconf smb_remote_path
    getconf smb_mount_path
    getconf smb_credentials
    # mount the samba share and check its status
    umount $smb_mount_path
    output=`smbmount $smb_remote_path $smb_mount_path -o credentials=$smb_credentials 2>&1`
    if [ $? = 0 ]; then
      info "Samba share mounted ($smb_remote_path on $smb_mount_path)"
      error $output
      fatal "Samba share cannot be mounted ($smb_remote_path on $smb_mount_path)"
  3. On the same file, we put this code at the end just before the return 0:
    output=`umount $smb_mount_path`
    if [ $? = 0 ]; then
      info "Samba share succesfully unmounted ($smb_remote_path on $smb_mount_path)"
      info $output
      info "Samba share cannot be unmounted ($smb_remote_path on $smb_mount_path)"

At this point our customized handler is ready. So we have to create a first backup action.

Create an action

In order to use our customized handler (zekra), our action filename has to be ended with the .zekra suffix.

  1. We create a standard rdiff action using the ninjahelper utility:
    sudo ninjahelper

    (for example 90.rdiff)

  2. We have to rename it to match the .zekra suffix:
    mv /etc/backup.d/90.rdiff /etc/backup.d/90.zekra
  3. We have to add the [samba] section to the end of the 90.zekra file:
  4. Take care that the /path/that/will/be/backuped/ exists and that it is listed in the include directives (above in the file in the [source] section).

Notice: the credential file format should respect what the smbmount command wants. Example:

username = stephane
password = secret


Enter your comment

Recent changes RSS feed Valid XHTML 1.0 Valid CSS Driven by DokuWiki