backintime icon indicating copy to clipboard operation
backintime copied to clipboard

notify-send Not Working from user-callback because of missing environment variables when called by cron

Open TwisX opened this issue 8 years ago • 10 comments

OS: Ubuntu 16.04.2 BackInTime: 1.1.20~alpha16 (testing)

I've created a simple user-callback script to show a notification when the backup completes, but the notification does not show up. The command notify-send "Backup Complete!" works when used in the terminal, so I know there's nothing wrong with the command.

I believe this has something to do with cron, so it may not be a direct BackInTime issue. From what I've read, it could be due to the DBUS_SESSION_BUS_ADDRESS variable not being available to cron jobs? I've tried several solutions found online, but none of them have worked for me.

Any help I could get with this would be great.

Here's my script:

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

case $reason in 2) #Backup process finished notify-send "Backup Complete!" ;; esac

Here's my debug log:

DEBUG: [common/backintime.py:584 argParse] Arguments: {'debug': True} | unknownArgs: []

Back In Time Version: 1.2.0~alpha16

Back In Time comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; type `backintime --license' for details.

DEBUG: [common/backintime.py:669 getConfig] config file: /home/user/.config/backintime/config DEBUG: [common/backintime.py:670 getConfig] share path: /home/user/.local/share/backintime DEBUG: [common/backintime.py:672 getConfig] profiles: 1=Main profile DEBUG: [common/pluginmanager.py:90 PluginManager.load] Register plugin path /usr/share/backintime/plugins DEBUG: [common/pluginmanager.py:106 PluginManager.load] Add plugin qt4plugin.py DEBUG: [common/pluginmanager.py:106 PluginManager.load] Add plugin usercallbackplugin.py DEBUG: [common/pluginmanager.py:106 PluginManager.load] Add plugin userscriptsplugin.py DEBUG: [common/pluginmanager.py:106 PluginManager.load] Add plugin notifyplugin.py DEBUG: [plugins/usercallbackplugin.py:46 UserCallbackPlugin.callback] Call user-callback: /home/user/.config/backintime/user-callback 1 Main profile 5 DEBUG: [plugins/usercallbackplugin.py:46 UserCallbackPlugin.callback] Call user-callback: /home/user/.config/backintime/user-callback 1 Main profile 7 DEBUG: [common/tools.py:1212 readCrontab] Read 3 lines from users crontab DEBUG: [common/config.py:1495 Config.removeOldCrontab] Clearing system Back In Time entries DEBUG: [common/config.py:1528 Config.cronLine] Profile: Main profile | Automatic backup: When drive get connected (udev) DEBUG: [common/config.py:1463 Config.setupCron] Udev rules added successfully DEBUG: [common/config.py:1479 setupCron] Crontab didn't change. Skip writing. DEBUG: [common/backintime.py:584 argParse] Arguments: {'debug': True, 'func': <function backup at 0x7f754515c510>, 'command': 'backup'} | unknownArgs: []

Back In Time Version: 1.2.0~alpha16

Back In Time comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; type `backintime --license' for details.

DEBUG: [common/backintime.py:669 getConfig] config file: /home/user/.config/backintime/config DEBUG: [common/backintime.py:670 getConfig] share path: /home/user/.local/share/backintime DEBUG: [common/backintime.py:672 getConfig] profiles: 1=Main profile DEBUG: [common/pluginmanager.py:90 PluginManager.load] Register plugin path /usr/share/backintime/plugins DEBUG: [common/pluginmanager.py:106 PluginManager.load] Add plugin qt4plugin.py DEBUG: [common/pluginmanager.py:106 PluginManager.load] Add plugin usercallbackplugin.py DEBUG: [common/pluginmanager.py:106 PluginManager.load] Add plugin userscriptsplugin.py DEBUG: [common/pluginmanager.py:106 PluginManager.load] Add plugin notifyplugin.py INFO: [common/snapshots.py:632 Snapshots.backup] Lock DEBUG: [common/tools.py:1162 inhibitSuspend] Inhibit Suspend started. Reason: take snapshot DEBUG: [plugins/usercallbackplugin.py:46 UserCallbackPlugin.callback] Call user-callback: /home/user/.config/backintime/user-callback 1 Main profile 7 DEBUG: [plugins/usercallbackplugin.py:46 UserCallbackPlugin.callback] Call user-callback: /home/user/.config/backintime/user-callback 1 Main profile 1 INFO: [common/snapshots.py:664 Snapshots.backup] Take a new snapshot. Profile: 1 Main profile INFO: [common/snapshots.py:1010 Snapshots.takeSnapshot] Call rsync to take the snapshot DEBUG: [common/snapshots.py:690 Snapshots.backup] Call command "rsync --recursive --times --devices --specials --hard-links --human-readable --links --perms --executability --group --owner --info=progress2 --no-inc-recursive --delete --delete-excluded -v -i --out-format=BACKINTIME: %i %n%L --link-dest=../../20170526-144117-402/backup --chmod=Du+wx --exclude=/media/user/Seagate Backup Plus Drive/BackInTime --exclude=/home/user/.local/share/backintime --exclude=.local/share/backintime/mnt --include=/home/user/Pictures/ --include=/home/user/ --include=/home/ --exclude=.gvfs --exclude=.cache/* --exclude=.thumbnails* --exclude=[Tt]rash* --exclude=.backup --exclude=~ --exclude=.dropbox --exclude=/proc/* --exclude=/sys/* --exclude=/dev/* --exclude=/run/* --exclude=/etc/mtab --exclude=/var/cache/apt/archives/.deb --exclude=lost+found/ --exclude=/tmp/* --exclude=/var/tmp/* --exclude=/var/backups/* --include=/home/user/Pictures/** --exclude=* / /media/user/Seagate Backup Plus Drive/BackInTime/backintime/user-HP-Pavilion-dv7/user/1/new_snapshot/backup" DEBUG: [common/snapshots.py:690 Snapshots.backup] Command "rsync --recursiv..." returns 0 INFO: [common/snapshots.py:835 Snapshots.backupConfig] Save config file INFO: [common/snapshots.py:872 Snapshots.backupPermissions] Save permissions DEBUG: [common/snapshots.py:1057 Snapshots.takeSnapshot] Call command "rsync --dry-run -r --out-format=%n /media/user/Seagate Backup Plus Drive/BackInTime/backintime/user-HP-Pavilion-dv7/user/1/new_snapshot/backup/ /tmp/tmpbbbscs7z/" DEBUG: [common/snapshots.py:1057 Snapshots.takeSnapshot] Command "rsync --dry-run ..." returns 0 INFO: [common/snapshots.py:848 Snapshots.backupInfo] Create info file DEBUG: [common/tools.py:1101 writeTimeStamp] write timestamp '20170526 1449' into file '/home/user/.local/share/backintime/anacron/1_Main_profile' DEBUG: [common/snapshots.py:1726 Snapshots.createLastSnapshotSymlink] Create symlink /media/user/Seagate Backup Plus Drive/BackInTime/backintime/user-HP-Pavilion-dv7/user/1/last_snapshot => 20170526-144926-620 DEBUG: [common/snapshots.py:1396 Snapshots.freeSpace] Remove snapshots older than: 20070501-000000 DEBUG: [common/snapshots.py:1218 Snapshots.smartRemoveList] Considered: [20170526-144926-620, 20170526-144117-402, 20170526-143751-995, 20170526-143602-860, 20170526-143423-636, 20170526-142622-824, 20170526-142539-503, 20170526-142242-503, 20170526-110731-618, 20170526-091624-889, 20170525-224529-641] DEBUG: [common/snapshots.py:1109 Snapshots.smartRemoveKeepAll] Keep all >= 20170526-000000-545 and < 20170527-000000-702 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170526-000000-928 and < 20170527-000000-742 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170525-000000-199 and < 20170526-000000-972 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170524-000000-400 and < 20170525-000000-777 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170524-000000-395 and < 20170525-000000-242 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170523-000000-765 and < 20170524-000000-563 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170523-000000-114 and < 20170524-000000-726 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170522-000000-241 and < 20170523-000000-875 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170522-000000-964 and < 20170523-000000-259 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170521-000000-774 and < 20170522-000000-802 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170521-000000-772 and < 20170522-000000-540 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170520-000000-672 and < 20170521-000000-519 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170520-000000-785 and < 20170521-000000-361 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170521-000000-881 and < 20170529-000000-873 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170514-000000-974 and < 20170522-000000-926 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170514-000000-558 and < 20170522-000000-497 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170507-000000-471 and < 20170515-000000-474 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170507-000000-130 and < 20170515-000000-724 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170430-000000-181 and < 20170508-000000-269 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170430-000000-405 and < 20170508-000000-785 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170501-000000-473 and < 20170601-000000-126 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170401-000000-793 and < 20170501-000000-561 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170401-000000-292 and < 20170501-000000-157 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170301-000000-667 and < 20170401-000000-823 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170301-000000-418 and < 20170401-000000-442 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170201-000000-568 and < 20170301-000000-891 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170201-000000-908 and < 20170301-000000-521 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170101-000000-466 and < 20170201-000000-747 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170101-000000-991 and < 20170201-000000-671 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20161201-000000-806 and < 20170101-000000-632 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20161201-000000-757 and < 20170101-000000-511 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20161101-000000-100 and < 20161201-000000-942 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20161101-000000-873 and < 20161201-000000-439 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20161001-000000-353 and < 20161101-000000-280 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20161001-000000-611 and < 20161101-000000-906 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20160901-000000-672 and < 20161001-000000-117 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20160901-000000-395 and < 20161001-000000-635 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20160801-000000-389 and < 20160901-000000-985 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20160801-000000-713 and < 20160901-000000-375 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20160701-000000-470 and < 20160801-000000-421 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20160701-000000-368 and < 20160801-000000-405 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20160601-000000-909 and < 20160701-000000-691 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20160601-000000-303 and < 20160701-000000-633 DEBUG: [common/snapshots.py:1137 Snapshots.smartRemoveKeepFirst] Keep first >= 20170101-000000-789 and < 20180101-000000-825 DEBUG: [common/snapshots.py:1275 Snapshots.smartRemoveList] Keep snapshots: {20170526-143423-636, 20170526-091624-889, 20170526-144926-620, 20170526-142242-503, 20170526-142539-503, 20170525-224529-641, 20170526-110731-618, 20170526-142622-824, 20170526-143602-860, 20170526-143751-995, 20170526-144117-402} DEBUG: [common/snapshots.py:1431 Snapshots.freeSpace] Keep min free disk space: 1024 MiB DEBUG: [common/snapshots.py:1465 Snapshots.freeSpace] Keep min 2%% free inodes DEBUG: [plugins/usercallbackplugin.py:46 UserCallbackPlugin.callback] Call user-callback: /home/user/.config/backintime/user-callback 1 Main profile 3 20170526-144926-620 /media/user/Seagate Backup Plus Drive/BackInTime/backintime/user-HP-Pavilion-dv7/user/1/20170526-144926-620 DEBUG: [plugins/usercallbackplugin.py:46 UserCallbackPlugin.callback] Call user-callback: /home/user/.config/backintime/user-callback 1 Main profile 2 DEBUG: [plugins/usercallbackplugin.py:46 UserCallbackPlugin.callback] Call user-callback: /home/user/.config/backintime/user-callback 1 Main profile 8 INFO: [common/snapshots.py:737 Snapshots.backup] Unlock DEBUG: [common/tools.py:1182 unInhibitSuspend] Release inhibit Suspend Alarm clock DEBUG: [plugins/usercallbackplugin.py:46 UserCallbackPlugin.callback] Call user-callback: /home/user/.config/backintime/user-callback 1 Main profile 8 DEBUG: [plugins/usercallbackplugin.py:46 UserCallbackPlugin.callback] Call user-callback: /home/user/.config/backintime/user-callback 1 Main profile 6

TwisX avatar May 26 '17 19:05 TwisX

I am interested in your solution. I do SSH backup as root via cron (needs password once per login to unlock root's SSH key). I receive notify-send messages from BIT for at least some errors I have encountered. I would enjoy a BIT success message but I do not know enough to dig into the BIT code.

Outside of BIT: I tried to ask root's cron to run "backintime last-snapshot" in cron itself or in a script, thinking that would be something worth printing with "notify-send" but cron does not have password for root's SSH key.

Following this thread. Thanks.

ntrlshrp avatar Aug 01 '17 00:08 ntrlshrp

@ntrlshrp I could never get notify-send to work (quite certain it's just an issue with cron) so I ended up using Zenity. I actually like using Zenity a lot better for the completion message because it creates a pop up that doesn't go away until you manually close it. This might be annoying to some, but I like it because if I walk away from my PC while a backup is in progress, the completion message will be there waiting when I get back and I can know for sure that the backup completed.

Here's my user-callback if you're interested: (the "sleep 5" command is to give time for BIT to recognize my backup drive so it doesn't show an error. That might not be necessary in your case.)

#!/bin/bash profile_id="$1" profile_name="$2" reason="$3" date="date +'%A, %B %d - %r'"

case $reason in 1) #Backup process begins sleep 5 ;; 2) #Backup process finished zenity --info --text "Backup Complete!\n$(date +'%A, %B %d - %r')" ;; esac

TwisX avatar Aug 01 '17 02:08 TwisX

Looks like that this Issue has a solution and it is not direct related to BIT. I also would assume that this is related to cron.

@Germar can close this if you have no other questions.

buhtz avatar Oct 02 '17 13:10 buhtz

This is because procs started by cron have a very limited environ. Not only DBUS_SESSION_BUS_ADDRESS variable is missing. The fix for this would be a proper IPC and a BiT daemon. But again, that's a lot of work to do...

Germar avatar Oct 03 '17 21:10 Germar

I've also encountered this issue, and I think it would be a useful and natural feature to hook into backintime's notifications from user-callback.

emtiu avatar Sep 12 '22 09:09 emtiu