exit code is always 0

Bug #1040995 reported by John M on 2012-08-24
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Back In Time
Fix Released
Medium
Unassigned

Bug Description

It appears that backintime always returns an exit code of 0. This makes proper scripting difficult. I run backintime from a cron job and there's no way to check if it failed. Which means I have to manually check everyday if the backup ran.

It should return a non-zero exit code in case of some failure, as is standard for any console program. I understand that there is some kind of of callback mechanism that one can use, but simply fixing the application return code to work properly would be nicer.

Dan (danleweb) on 2012-08-24
Changed in backintime:
importance: Undecided → Medium
status: New → Confirmed
Rafael (rafaelliu) wrote :

+1

Really make scripting impossible. Should comply to Linux standard exit codes.

Looks like a quick fix

Rafael (rafaelliu) wrote :

Looks like there's a plugin functionality built in BiT. Looking at the sources, appears to me that it already does a look of error handling through PluginManager.on_error().

A simple hack would be to edit pluginmanager.py and add a sys.exit() call:

        def on_error( self, code, message = '' ):
                for plugin in self.plugins:
                        plugin.on_error( code, message )

                # exit code
                sys.exit( code )

Of course, you will have to import sys..

Germar (germar) on 2014-01-02
Changed in backintime:
milestone: none → 1.1.0
Julian Gilbey (jdg) wrote :

Better than Rafael's hack is the following: in common/snapshots.py, take_snapshot returns a success status. This function is called by the take_snapshot function in common/backintime.py, but the return value is ignored. So instead, take_snapshot in common/backintime.py should read:

def take_snapshot( cfg, force = True ):
    logger.openlog()
    tools.load_env(cfg)
    ret = snapshots.Snapshots( cfg ).take_snapshot( force )
    logger.closelog()
    return ret

and then in the start_app loop in common/backintime.py do something like the following:

        if arg == '--backup' or arg == '-b':
            ret = take_snapshot( cfg, True )
            if ret:
                sys.exit(0)
            else:
                sys.exit(1)

        if arg == '--backup-job':
            ret = take_snapshot( cfg, False )
            if ret:
                sys.exit(0)
            else:
                sys.exit(1)

Germar (germar) wrote :

Thanks Julian, I'll have a look soon. BTW attached diffs are easier to read than inline code

Germar (germar) on 2014-04-02
Changed in backintime:
status: Confirmed → Fix Committed
Germar (germar) on 2015-01-15
Changed in backintime:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers