run script before actual backup

Bug #1145544 reported by Timmie
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Back In Time
Invalid
Undecided
Unassigned

Bug Description

I would like to be able to run a script such as a cleaning procedure before doing backup.

It woudl be nice to define suchin the setting.

BTW, the software is great.

Revision history for this message
Germar (germar) wrote :

this can be done with a user-callback script. Please take a look at the user-callback section in 'man backintime'

Regards,
Germar

Changed in backintime:
status: New → Invalid
Revision history for this message
Timmie (timmie) wrote :

Ah, ok Tha nk you.

But how to I configure this?

The man page could have a pointer here:

During backup process the application can call a user callback at different steps. This callback is
       "$XDG_CONFIG_HOME/backintime/user-callback" (by default $XDG_CONFIG_HOME is ~/.config).

       The first argument is the progile id (1=Main Profile, ...).

Do I store the script with that name in:
"$XDG_CONFIG_HOME/backintime/user-callback?
Or is it a config parameter?

Revision history for this message
Germar (germar) wrote :

Just create a script in '~/.config/backintime/user-callback'. BIT will automatically find and execute that during runtime. Here is a basic structure for your script:

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

case $3 in
    1) #Backup process begins
         #here you can add your action that will run before the backup start
         ;;
    2) #Backup process ends
         ;;
    3) #A new snapshot was taken
         ;;
    4) #There was an error
         case $4 in
            1) #The application is not configured
                  ;;
            2) #A "take snapshot" process is already running
                  ;;
            3) #Can't find snapshots folder (is it on a removable drive ?)
                  ;;
            4) #A snapshot for "now" already exist
                  ;;
        esac
        ;;
esac

Revision history for this message
jean-christophe manciot (manciot-jeanchristophe) wrote :

Great, but how can we link that script to a particular profile, i.e run it before/after a particluar backup profile is launched?

Revision history for this message
jean-christophe manciot (manciot-jeanchristophe) wrote :

In other words, Are these related to the backup profiles or to the user profile:
profile_id="$1"
profile_name="$2"

Revision history for this message
Germar (germar) wrote :

I don't understand what you mean with user profiles. But $profile_id or $1 is the profileID from BIT. The same that you would use to start a new snapshot from command line or crontab.

You can do something like this:

case $3 in
    1) #Backup process begins
        case $profile_id in
            1) #do something for Main Profile
                    ;;
            2) #do something different for your second profile
                    ;;
            *) #do this for all other profiles
                    ;;
        esac
esac

Revision history for this message
jean-christophe manciot (manciot-jeanchristophe) wrote :

OK, thanks.
I've tried first a simpler version located in "/root/.config/backintime/user-callback/my-script.sh" where nothing happens:

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

case $3 in
    1) #Backup process begins
         gnome-terminal --window-with-profile=Backup-CORSAIR-Ubuntu-14-Ext4 -e /home/actionmystique/Program-Files/Ubuntu/Manual-Backup/Backup-CORSAIR-Ubuntu-14-Ext4.sh
         ;;
    2) #Backup process ends
         ;;
    3) #A new snapshot was taken
         ;;
    4) #There was an error
         case $4 in
            1) #The application is not configured
                  ;;
            2) #A "take snapshot" process is already running
                  ;;
            3) #Can't find snapshots folder (is it on a removable drive ?)
                  ;;
            4) #A snapshot for "now" already exist
                  ;;
        esac
        ;;
esac

I suppose there's a way to analyze the error, but how?

Revision history for this message
jean-christophe manciot (manciot-jeanchristophe) wrote :

When I run the "gnome-terminal ..." command inside a terminal windows, everything works fine.

Revision history for this message
Germar (germar) wrote :

You have a folder called 'user-callback'. But the script itself must be named '/root/.config/backintime/user-callback'.

If you want to run multiple scripts from a directory you can take a look at https://code.launchpad.net/~bit-team/backintime/user-callback. I started to collect some examples in there.

Revision history for this message
jean-christophe manciot (manciot-jeanchristophe) wrote :

Got it, thanks. I've tried that, something happens now, but the results are strange. None of the regular commands of the script are recongnized (blkid, dd, fsarchiver: "command not found").

Below is one screenshot when my bash script is automatically launched from within "user-callback":
https://drive.google.com/file/d/0B5fXyIn0-GDFYXZud0tmSTdYSGM/edit?usp=sharing

Below is one screenshot when the same script is manually launched from the desktop:
https://drive.google.com/file/d/0B5fXyIn0-GDFdkNHLU5xV2tSSkk/edit?usp=sharing

Maybe your code does not allow the script "user-callback" to call other scripts, but only commands.

Revision history for this message
Germar (germar) wrote :

Looks like there is something missing in $PATH. Please add a line 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games' at start of your script (you get these with 'echo $PATH' from Terminal).

Revision history for this message
jean-christophe manciot (manciot-jeanchristophe) wrote :

It worked this time. Here is the "user-callback" script I've used in case other people are interested:

#!/bin/bash
profile_id="$1"
profile_name="$2"
PATH=/usr/local/ssl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:

case $3 in
    1) #Backup process begins
 case $profile_name in
            "Main profile") #do something for Main Profile
  <script call>
                    ;;
            "Another profile name" #do something for Another Profile
  <another script call>
                    ;;
            *) #do this for all other profiles
                    ;;
        esac
         ;;
    2) #Backup process ends
         ;;
    3) #A new snapshot was taken
         ;;
    4) #There was an error
         case $4 in
            1) #The application is not configured
                  ;;
            2) #A "take snapshot" process is already running
                  ;;
            3) #Can't find snapshots folder (is it on a removable drive ?)
                  ;;
            4) #A snapshot for "now" already exist
                  ;;
        esac
        ;;
esac

However, I have one suggestion: how about inserting the "script call" feature in the graphical interface which could create this "user-callback" file instead of having to manually edit it? There must be a way for you to get the user's PATH setting before the user's script is called.
We could even get the potential errors in the log.

Revision history for this message
Germar (germar) wrote :

Glad to hear that it works for you now. But one little hint: I'd use $profile_id instead of $profile_name because the name can change. 'Main Profile' will even change with different locales. E.g. it's 'Hauptprofile' with de_DE.UTF-8

There is a discussion in https://answers.launchpad.net/backintime/+question/249267 to add some example scripts and activate them from Settings dialog. I'm not sure yet how I would like to handle this.

Revision history for this message
jean-christophe manciot (manciot-jeanchristophe) wrote :

Thanks for the hint; it makes sense. However, we are not aware of how you've numbered the profiles:
- alphabetically?
- in the order in which they've been created?

I'm glad to hear you're considering the graphical suggestion, since you already have "expert options".
The way to present this feature seems pretty easy after all the work you've already done, for example:

- adding a new tab "Scripts",
- inserting a "Pre-snapshot" section with a browse button to insert the script name with all its path, exactly like the "Where to save snapshots" section in the first tab,
- inserting another "Post-snapshot" section with a browse button to insert the script name with all its path

Including some hints - about for example the fact that the correct Execute permission of the script must be set and to test the script before including it there - might be necessary.
However, this product is on Linux and most people know what is a script is; I don't think it is necessary to include examples within the settings window. Providing a link to a web resource listing some various examples should greatly enhance your product.
I'd be glad to contribute with some of my own backup-related scripts.

Revision history for this message
jean-christophe manciot (manciot-jeanchristophe) wrote :

I forgot to mention 2 points:
- the user should not need to insert a PATH setting inside his/her script.
- I'm not sure about the difference(s) between "Backup process ends" and "new snapshot was taken"

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.