Im attempting to make a manual Button within the sitemap, that when I press it, it will run the backup command line for OpenHAB2 and save the file with a format similar to OHbackup_30-01-2018_1154.zip on a network share.
- I am using Armbain (Ubuntu for ARM processors basically).
- My $OPENHAB_RUNTIME doesnt work, so I am specifying the exact path to the folders to run the commands (I have seen this problem detailed elsewhere).
- Everything else within OpenHAB is generally running well
What I have done so far is:
- Create a local symbolic link to my network path https://wiki.ubuntu.com/MountWindowsSharesPermanently#Mount_password_protected_network_folders
- Created a bash script backup.sh and placed it in the Openhab Shares folder,
today=`date '+%d-%m-%Y_at_%H%M'` filename="/media/openhabbackup/OHbackup_$today.zip" /usr/share/openhab2/runtime/bin/backup $filename
- Added an ITEM
- Added a button in sitemap
Switch item=BACKUP mappings=["BACKUP"="Backup"]
- Finally a Rule, which takes effect when the button is pressed
rule "BACKUP" when Item BACKUP received command BACKUP then executeCommandLine=("sudo bash /etc/openhab2/scripts/backup.sh") end
According to the Openhab.log, the script executes.
I have 2 problems from this:
if I run the script manually from the command line, it DOES backup in the correct location, but my filename isnt OHbackup_$today.zip it actually becomes a random name e.g. last time I ran the script, the file was called O8715Q~W however, if I rename it as a ZIP file, it is a working file. What have I done wrong in my shell script?
When the command is executed from OpenHAB basic UI, the logs say it runs, but nothing happens, no files are created. Ive tried variations such as:
executeCommandLine=("sudo bash /etc/openhab2/scripts/backup.sh") executeCommandLine=("sudo@@bash@@/etc/openhab2/scripts/backup.sh") executeCommandLine=("bash /etc/openhab2/scripts/backup.sh") executeCommandLine=("bash@@/etc/openhab2/scripts/backup.sh") executeCommandLine=("/etc/openhab2/scripts/backup.sh")
I have done a chmod +x backup.sh
If anyone has any thoughts/insight as to what Im doing wrong or a more efficient way to do this, it would be great to hear!