Automatic Backup openHAB2 via GIT to BitBucket (FREE)

It’s the same. As far as Linux is concerned everything is a file so the ln command works the same for folders, devices, and files.

So you have your git controlled folder, let’s say it’s /opt/openhab. Then you need to create symbolic links so that /etc/open have points to /opt/openHAB/conf.

I always forget the other of the arguments so look it up to verify but I think it’s:

sudo ln -s /etc/openhab2 /opt/openhab/conf

There’s no tutorial I know of. Check the settings mentioned in this link, if that does not give you any hint you need to resort to generic debugging. Start here.

Are you still having issues with this? Can you provide an ‘ls -l’ on the directory where your script is located?

I think I know what happened. Run the following command:

chmod 755 /data/scripts/openhab2backup

I forgot to mention that the script needs to be executable. After making this change, test it by running the script:


I updated my original post to include this change toward the bottom.

Yes, now it is working. It is complicated for people who is not familiar with unix and permission settings.
I use different repository for conf and userdata, so I modify your script
here is what I do:

Go to, login
Create new repository. Format: [clientname]conf (all lowercase)
Create new repository. Format: [clientname]userdata (all lowercase)

mkdir ~/data
ssh-keygen -t rsa -C "[insert email registered to bitbucket here]"
cat ~/.ssh/
        copy ssh-rsa xxxx (without email)
        go to bitbucket > Bitbucket settings > SSH keys > add key
        give key name [clientname], paste
        test ssh connection
ssh -T [bitbucket username]
        expected response:
        #logged in as [bitbucket username]
        #You can use git or hg to connect to Bitbucket. Shell access is disabled.

cd ~/data

#clone conf repo
git clone[bitbucket username]/[repositoryname for conf].git

#move git file (rename old repository name)
mv [repositoryname]/.git /etc/openhab2/.git

#delete repository folder
rm -r [repositoryname]

/usr/bin/git add html
/usr/bin/git add icons
/usr/bin/git add items
/usr/bin/git add persistence
/usr/bin/git add rules
/usr/bin/git add scripts
/usr/bin/git add services
/usr/bin/git add sitemaps
/usr/bin/git add sounds
/usr/bin/git add things
/usr/bin/git add transform
/usr/bin/git add workspace
git commit -m "first push"
git push

#clone userdata repo
cd ~/data
git clone[bitbucket username]/[repositoryname for userdata].git

#move git file (rename old repository name)
mv [repositoryname]/.git /var/lib/openhab2/.git

rm -r [repositoryname]

cd /var/lib/openhab2
#git add available folders, except cache, log, and tmp folders
/usr/bin/git add config
/usr/bin/git add etc
/usr/bin/git add persistence

git commit -m "first push"
git push

sudo nano /etc/openhab2/ohbackupscript
        #copy text from table beside this, modify userdata folders to backup
chmod 0755 /etc/openhab2/ohbackupscript
crontab -e
        #paste this to last line
        00 00 * * * /etc/openhab2/ohbackupscript

I did try the idea with the symlinks - just one small problem: git is handling the symlinks as files, not as folders. Means that instead of the content at the other end of the symlink, only the symlinks themself are to be fund in the new git repo :sweat_smile:

Ah yes. All the “real files” need to be in the folder checked in by git. git will not follow the symlinks. Now it might work with hard links (ln -p instead of ln -s), but this only works if both the hard link and the file it links to are on the same file system.

Anyway, that’s why in the post above I create the symbolic link from /opt/openhab/conf to /etc/openhab2instead of the other way around.

1 Like