Project

General

Profile

Bug #7794

backup to external drive: no check if drive is mounted can cause root partition to fill up

Added by bugmenot about 3 years ago. Updated about 3 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
rdiff-backup handler
Target version:
-
Start date:
08/18/2014
Due date:
% Done:

0%

QA Check:

Description

I set up a weekly full rdiff backup of system files and user data to an external usb drive with the appropriate fstab configuration so plugging the drive would result in the drive being automatically mounted at the right mountpoint.

Problem is backupninja doesn't offer the option to check if the destination is a mountpoint, so when the user failed to plug the external drive the backup process just went on and filled up the ssd based system partition until the computer crashed and rendered the system unusable and impossible to fix remotely (readonly root filesystem).

Bypassing backupninja helpers and using a custom shell script, there is a workaround I found at http://duncanlock.net/blog/2013/08/27/comprehensive-linux-backups-with-etckeeper-backupninja/ but this defeats the point of having helpers in the first place.

here's the example shell script from the previously mentioned web page:

if mountpoint -q /mnt/backups
then
   info "backup drive is mounted, backing up" 
   rsync -vaxAX --delete --ignore-errors --exclude '.cache/' /home/ /mnt/backups/
else
   fatal "backup drive is not mounted, quitting" 
fi

Given the prevalence of external drives, I'm surprised that backupninja is missing this obvious and much needed step.

History

#1 Updated by davekempe about 3 years ago

Hey Bugmenot,
We wrote a handler for this. It wasn't good enough for the backupninja folks to accept, or something, but here is the code:
#!/bin/sh

  1. Mount a block device with the specified label ('label') onto the given
  2. directory ('dest').

getconf label
getconf mountpoint

if [ ! -b "/dev/disk/by-label/$label" ]; then
halt "No partition labelled '$label' is available"
fi

if [ ! -d "$mountpoint" ]; then
halt "Destination directory does not exist"
fi

if grep $mountpoint /proc/mounts; then
umount -f $mountpoint
fi

mount -t auto /dev/disk/by-label/$label $mountpoint || halt "Mount failed"

-----------------
You put it in /usr/share/backupninja/ called labelmount.

Then you can have a config file in /etc/backup.d like this:
#cat /etc/backup.d/799-usbdrive.labelmount

##
  1. This is an example labelmount configuration file. ##
  1. ATTENTION: you have to initialize the partition
  2. with /usr/sbin/initialize-backupdisk first
  1. label of the partition to look for
    label = backupdisk2
  1. where to mount it
    mountpoint = /mnt/backupdisk

---------------
you can label the drive with e2label, this way you can have 2 drives and rotate them.

This handler will halt the entire job if the drive can't be mounted, so you don't fill up your root filesystem.

Hope that helps..
Dave

bugmenot wrote:

I set up a weekly full rdiff backup of system files and user data to an external usb drive with the appropriate fstab configuration so plugging the drive would result in the drive being automatically mounted at the right mountpoint.

Problem is backupninja doesn't offer the option to check if the destination is a mountpoint, so when the user failed to plug the external drive the backup process just went on and filled up the ssd based system partition until the computer crashed and rendered the system unusable and impossible to fix remotely (readonly root filesystem).

Bypassing backupninja helpers and using a custom shell script, there is a workaround I found at http://duncanlock.net/blog/2013/08/27/comprehensive-linux-backups-with-etckeeper-backupninja/ but this defeats the point of having helpers in the first place.

here's the example shell script from the previously mentioned web page:
[...]

Given the prevalence of external drives, I'm surprised that backupninja is missing this obvious and much needed step.

#2 Updated by davekempe about 3 years ago

Oh, we also have a umount handler to unmount it when done

#!/bin/sh

# Unmount the specified directory ('dir'), forcefully if necessary.

getconf mountpoint

if ! umount $mountpoint; then
        warning "Simple unmount failed for $mountpoint; being forceful" 
        if ! umount -f $mountpoint; then
                warning "Forceful unmount failed for $mountpoint; being lazy" 
                if ! umount -l $mountpoint; then
                        warning "Lazy unmount failed for $mountpoint; you're on your own" 
                fi
        fi
fi

# cat /etc/backup.d/899-usbdrive.umount
mountpoint = /mnt/usbdrive

Also available in: Atom PDF