exit code is always 0

Bug #1040995 reported by John M
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)
Changed in backintime:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Rafael (rafaelliu) wrote :

+1

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

Looks like a quick fix

Revision history for this message
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)
Changed in backintime:
milestone: none → 1.1.0
Revision history for this message
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)

Revision history for this message
Germar (germar) wrote :

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

Germar (germar)
Changed in backintime:
status: Confirmed → Fix Committed
Germar (germar)
Changed in backintime:
status: Fix Committed → Fix Released
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.