sebbacon / home-automation

5 stars 0 forks source link

Back up Pi #3

Open sebbacon opened 6 years ago

sebbacon commented 6 years ago

Don't want to have to do all this again if the SD card corrupts...

This is a very good document about the problem.

Also thinking of when the Cube loses all its bindings, which apparently happens occasionally. We have to re-teach the Cube, but I'd like not to have to also re-create all the channels (not sure if I'd actually need to do that too).

sebbacon commented 6 years ago

Here's openhab2-specific backup/restore scripts

sebbacon commented 6 years ago

Config is stored within openHab in a json database

sebbacon commented 5 years ago
sebbacon commented 5 years ago

Dammit my 4TB drive isn't supported on Pi architecture

sebbacon commented 5 years ago

Addressing large drives fixed with apt-get install ntfs-3g

sebbacon commented 5 years ago

So I've actually done these things:

[18:29:01] root@openHABianPi:/etc/cron.d# cat openhab2-backup 
10 2 * * * DATE=`date +%Y%m%d`; /usr/bin/python3 /usr/local/python-maxcube-api/prog.py --host 192.168.1.190 --port 62910 dump > /mnt/backups/Seb/openhabian/prog/$DATE-prog.json
20 2 * * * /usr/share/openhab2/runtime/bin/backup
[17:45:33] openhabian@openHABianPi:/etc/cron.d$ grep -v '^$\|^\s*\#' /etc/rsnapshot.conf 
config_version  1.2
snapshot_root   /mnt/backups/Seb/openhabian/rsnapshot
no_create_root  1
cmd_cp      /bin/cp
cmd_rm      /bin/rm
cmd_rsync   /usr/bin/rsync
cmd_logger  /usr/bin/logger
retain  alpha   6
retain  beta    7
retain  gamma   4
verbose     2
loglevel    3
lockfile    /var/run/rsnapshot.pid
backup  /var/lib/openhab2/backups/      localhost/
backup  /etc/       localhost/
[17:45:40] openhabian@openHABianPi:/etc/cron.d$ cat rsnapshot 
# This is a sample cron file for rsnapshot.
# The values used correspond to the examples in /etc/rsnapshot.conf.
# There you can also set the backup points and many other things.
#
# To activate this cron file you have to uncomment the lines below.
# Feel free to adapt it to your needs.

0 */4       * * *       root    /usr/bin/rsnapshot alpha
30 3    * * *       root    /usr/bin/rsnapshot beta
0  3    * * 1       root    /usr/bin/rsnapshot gamma
30 2    1 * *       root    /usr/bin/rsnapshot delta

I've also made one-off disk image snapshots:

[17:04:29] root@openHABianPi:/mnt/backups/Seb/openhabian# dd bs=4M if=/dev/mmcblk0p1 | gzip > raspbian-boot.img.gz
[17:05:22] root@openHABianPi:/mnt/backups/Seb/openhabian# dd bs=4M if=/dev/mmcblk0p2 | gzip > raspbian-root.img.gz
sebbacon commented 5 years ago

I have also install exim and set up an alias for root in /etc/aliases, so I get emails from cron etc.

Keeping this open until I have a chance to check:

sebbacon commented 5 years ago

Had to install exim and configure to send mail out.

apt-get install exim4
dpkg-reconfigure exim4-config  
echo "root: seb.bacon@gmail.com" >> /etc/aliases
newalises

Exim configuration to use my ISP as a smarthost:

dc_eximconfig_configtype='satellite'
dc_other_hostnames='openHABianPi'
dc_local_interfaces='127.0.0.1 ; ::1'
dc_readhost='openHABian.baconconsulting.co.uk' ## it uses this for the sender domain
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost='smtp.aa.net.uk::587'
CFILEMODE='644'
dc_use_split_config='true'
dc_hide_mailname='true'
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'

Logrotate for openhab backups:

/var/lib/openhab2/backups/*zip {
        su openhab openhabian
    rotate 30
        daily   
    missingok
}