Closed metbril closed 7 years ago
Suggestions welcome, @ThomDietrich.
I was thinking of a backup script something like this:
#!/bin/bash
# stop openhab instance (here: systemd service)
echo "Stopping service..."
sudo systemctl stop openhab2.service
# backup current installation with settings
TIMESTAMP="`date +%Y%m%d_%H%M%S`";
bakdir="$HOME/openhab2-backup/$TIMESTAMP";
mkdir -p "${bakdir}"
cp -arv /etc/openhab2 "${bakdir}/conf"
#cp -arv /var/lib/openhab2 "${bakdir}/userdata"
find /var/lib/openhab2 \( -path /var/lib/openhab2/tmp -prune -o -path /var/lib/openhab2/cache -prune \) -o -name '*' -exec cp -arv {} "${bakdir}/userdata" \;
# restart openhab instance
echo "Starting service..."
sudo systemctl start openhab2.service
This is almost working.
Unfortunately, the find
command does not produce the expected results.
Some of the files are put in the root of the userdata
folder instead of the required subdirectory.
I need some help with this.
Hey @rtvb thanks for making us aware of the problem and posting a solution. I've written these instructions a while ago and they were not strictly meant to be a perfectly complete script. Of course I get why this should be the case.
My suggestion would actually be to stay simple and just delete after copying. What do you think?
cp -arv /var/lib/openhab2 "${bakdir}/userdata"
rm -rf "${bakdir}/userdata/tmp"
rm -rf "${bakdir}/userdata/cache"
The point with my issue is that I prefer to limit writes to the sd card. Than a rm before the backup would be better but in that case the start of the service requires downloading any binding etc.
So I still think a restricted copy would be better.
We could prevent tmp and cache being copied or explicitly copy only required folders. But the latter is less future proof.
$ du -hs /var/lib/openhab2/*
80M /var/lib/openhab2/cache
19M /var/lib/openhab2/tmp
...
I'm not sure if this is really an issue... Anyway, an easier solution you could go with is rsync: http://stackoverflow.com/a/14789400 Only downside: rsync is not available on all distros by default.
Btw. If you execute the commands fast enough the files might not even get written from cache to memory. But I'm now stepping into a gray area 🌫
It is not about the size of the file but about my SD card aging more quickly.
http://superuser.com/questions/17350/whats-the-life-expectancy-of-an-sd-card
I got your point and am aware of the problem.
How about rsync then?
Writing 100MB once (if they are actually written before deleting from cache) will not wear out your sd card at a considerable speed. 100MB is nothing against 100000 to one million writes plus wear leveling on a e.g. 16GB card. Don't you think?
Why not use subversion or something? Would be more flexible...
Hey @rvtb, I did a script whigh updates the oh2 installation with the latest snapshot. I'don't use rsync for backup. See here: https://github.com/openhab/openhab-docs/pull/307#issuecomment-278290828
@gahubs this ticket is not about version-controlling your configuration. The backup goal is to backup and restore all userdata in case of an upgrade or hardware switch.
@whopperg as said in the other issue, let's moveyour script to a PR, then discuss it there. Please post the PR here, so @rtvb can follow ;)
Fyi @rtvb @ThomDietrich : https://github.com/openhab/openhab-distro/pull/426
The backup script suggested at the linux installation page suggests copying the entire
/var/lib/openhab2
folder. I don't think this is necessary (and taking too much space of and writes to my RPi SD Card). The folderstmp
andcache
can be excluded. And at restoring them, these folders could first be simply removed.I'm not a Linux expert, but will suggest an updated script. At first sight the
cp
command does not have an "exclude" option, so some additional lines might be necessary to implicitly include folders.The restore script should then include some
rm
statements to remove what's needed.