Snapshot only if source exists/user-callback to interrupt

Asked by mtu

I have two cases where I can't quite figure out how to configure backintime, and they boil down to the same problem.

1) Network backup
I mount a folder via SSHFS for taking a snapshot of it, but _only_ if I am on my local network (verifiable by ping or so).

2) USB stick backup
I take a snapshot of a USB stick, but only if it is plugged in (verifiable by mount table or so).

In both cases, backintime will still make an empty snapshot of the empty moint point.

I would like to use user-callback to check if the conditions are right (stick is there, network is there). But what if they fail? Can I put some commmand or condition in user-callback that makes backintime stop its snapshot?

Question information

Language:
English Edit question
Status:
Solved
For:
Back In Time Edit question
Assignee:
No assignee Edit question
Solved by:
mtu
Solved:
Last query:
Last reply:
Revision history for this message
Germar (germar) said :
#1

I'm not sure if I got it right. Are the sshfs mount and the USB stick your sources for snapshots or do you want to store snapshots on them (so they are targets)?

Revision history for this message
mtu (mtu) said :
#2

Sorry, I used the wrong word. The network location and USB sticks are my _sources_. My problem is that backintime makes snapshots of the empty mount point if they are not mounted.

Revision history for this message
Germar (germar) said :
#3

You could kill the parent of the parent process with user-callback:

#!/bin/bash
profile_id="$1"
profile_name="$2"
pid=$$

function ppid {
    cat /proc/$1/status | grep "PPid:" | cut -f2
}

case $3 in
    1) #Backup process begins
        if [ true ]; then ###INSERT YOUR CONDITIONS HERE
            kill $(ppid $(ppid $pid))
        fi
        ;;
    2) #Backup process ends
        ;;
    3) #A new snapshot was taken
        ;;
    4) #There was an error
        case $4 in
            1) #ERROR The application is not configured
              ;;
            2) #ERROR A 'take snapshot' process is already running
              ;;
            3) #ERROR Can't find snapshots folder (is it on a removable drive ?)
              ;;
            4) #ERROR A snapshot for 'now' already exist
              ;;
        esac
        ;;
esac

Revision history for this message
mtu (mtu) said :
#4

Thank you, this did the trick!

For reference, my script now looks like this:

#!/bin/bash
profile_id="$1"
profile_name="$2"
pid=$$

function ppid {
  grep "PPid:" /proc/$1/status | cut -f2
}
function log {
  logger -t "backintime (user-callback)" $1
}

case $profile_id in
  1) #memory card
    case $3 in
      1) ##backup begins
        if [ ! -d /media/memory-card-mountpoint ]; then
          log "Memory Card not found. No snapshot."
          kill $(ppid $(ppid $pid))
        else
          log "Memory Card found. Making snapshot."
        fi
        ;;
    esac
    ;;
  2) #sshfs remote
    case $3 in
      1) ##backup begins
        if ! ping -c1 -i0.2 -W1 myhost; then
          log "Cannot ping myhost. No snapshot."
          kill $(ppid $(ppid $pid))
        else
          log "myhost pinged. Proceeding ..."
          if ! sshfs -o ro myhost:/mydir /mymountpoint; then
            log "Cannot mount mydir. No snapshot."
            kill $(ppid $(ppid $pid))
          else
            log "mydir mounted. Proceeding ..."
          fi
        fi
      ;;
      2) ##backup ends
        if ! fusermount -u /mymountpoint; then
          log "mydir unmount failed."
          sleep 1
          if ! fusermount -uz /mymountpoint; then
            log "mydir unmount failed, even lazily. Giving up."
          else
            log "mydir unmounted only lazily. Done."
          fi
        else
          log "mydir unmounted. Done."
        fi
        ;;
    esac
    ;;
esac