Due to many issues with data loss and system failures, I now setup my backup solution as one of the first steps after installation, before even starting to use openHAB.
The documentation for installing Amanda using openhabian is here. In my opinion it is very detailed in some aspects that are not essential for the average openHAB user, and too sparse in other aspects more important to the task at hand. I wanted to have a working backup setup, without necessarily becoming an expert in Amanda.
Since I am not an Amanda expert, my ability to answer questions may be limited. I am also sure that there are better ways to do the things described in the tutorial, so I look forward to constructive criticism that I can incorporate to the post. Without further ado, here are the steps I followed to get Amanda working on my Raspberry Pi 3B+.
Prepare Storage for the Backups
I used an empty 500GB external USB hard drive with one ext4 partition, previously formatted using gparted on my Ubuntu machine.
Connect external hard drive to USB on Raspberry Pi
Create the mount directory on the RPi. I used the location /mnt/ext-storage.
sudo mkdir /mnt/ext-storage
Configure the RPi to automatically mount the USB hard drive on startup by editing the /etc/fstab file. This tutorial was very helpful. The new line in my /etc/fstab file looks like this:
PARTUUID=d7d8daba-01 /mnt/ext-storage ext4 defaults,auto,users,rw,nofail,noatime 0 0
- Test that it works with
sudo mount -a. The mountpoint for the USB hard drive (in my case sda1) should be visible when executing the
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 465.8G 0 disk └─sda1 8:1 0 465.8G 0 part /mnt/ext-storage mmcblk0 179:0 0 14.9G 0 disk ├─mmcblk0p1 179:1 0 256M 0 part /boot └─mmcblk0p2 179:2 0 14.6G 0 part /
- I created another directory on the USB hard drive for the Amanda backup data
sudo mkdir /mnt/ext-storage/amanda
Configure Permissions for Storage Location
There is a lot of emphasis in the Amanda for openhabian documentation on ensuring that the
backup user has write access to the storage area before installing Amanda, but no clear explanation on how to do this.
- As described in the docs, I changed the owner of the storage area to user
sudo chown -R backup:backup /mnt/ext-storage/amandaand checked that it worked with
Note: this needs to be done with the
openhabian user because the
backup user is not a ‘sudoer’
In my case, I could not change to the
su backupas it was asking for a password which is not documented. So I changed the password for the user with
sudo passwd backup
Then I was getting the error
This account is currently not availablewhen doing
su backupto switch to the
After some digging, it turns out that this means that there is no valid shell set for this user (see link), whatever that means
It was easily fixed by executing the
sudo chsh -s /bin/bash backupcommand. After this I could switch user with
Finally I could test that user
backupcould indeed create and delete a file in the storage area /mnt/ext-storage/amanda.
– Move to correct location with
– Create file with
– Check that the file is owned by
– Delete file with
Configure Samba Share of Amanda Images
I want to access the backup images created by Amanda from my Ubuntu machine. For this I created the directory
Since Samba is already installed and configured on the Raspberry Pi, this is as easy as adding the folder where the images will be stored to the Samba configuration file. A good guide for Samba on the Raspberry Pi in general can be found here.
/etc/samba/smb.conf file now has the following added directly after the
[backup-images] comment=backup images of openhab system path=/mnt/ext-storage/amanda/images writable=yes public=no create mask=0777 directory mask=0777
sudo systemctl restart smbd the share should now be visible in Ubuntu, and can be mounted in Ubuntu or other OS if necessary.
Installing Amanda via the openhabian Configuration Tool
sudo openhabian-configand select option 52.
The first prompt in the Amanda installation is to enter an email address to send backup reports. This will not work unless it was previously configured, which I did not try to do.
After entering the email address, it takes a while for Amanda to install.
The second prompt is for a password for the user
backup. I entered the same password that I had selected previously when running
sudo passwd backup
Then you are prompted if you want to setup a backup mechanism based on locally attached or NAS mounted storage. Select
The backup directory is requested, in my case
Storage capacity dedicated to the backup must be entered. I put 5 times the size of my SD card (16GB).
The next prompt asks if Amanda should do a raw backup of the SD card. I wanted to be able to not just restore files but also simply flash my backed up system image to another SD card, so I selected
Backup SD. Note that raw SD card backups take a long time and hog system resources.
Then setup informs that it will label removable storage media and create 15 virtual containers. Select
Now it gets a little confusing. The next prompt is about creating an Amazon S3 based backup. The question at the end of the prompt is
Continue with Amanda installation?which to me is misleading.
Noquits the whole Amanda installation, when in fact it only skips the Amazon S3 configuration. Selecting
Nois therefore fine if you don’t need S3.
You should then see a confirmation that installation was successful.
Test Amanda Backup
Now we want to test Amanda, to make sure that it is working as expected before things start to fail.
First switch to user
Then use the command
amcheck openhab-dirto check the Amanda status.
openhab-diris the backup configuration using local usb or mounted NAS storage. This should result in something like:
Amanda Tape Server Host Check ----------------------------- slot 1: contains an empty volume Will write label 'openHABian-openhab-dir-001' to new volume in slot 1. NOTE: skipping tape-writable test NOTE: storage 'openhab-dir': retentions-tapes (14) <= runspercycle (14) NOTE: host info dir '/var/lib/amanda/openhab-dir/curinfo/openhab' does not exist It will be created on the next run NOTE: index dir '/var/lib/amanda/openhab-dir/index/openhab' does not exist it will be created on the next run Server check took 0.958 seconds Amanda Backup Client Hosts Check -------------------------------- Client check: 1 host checked in 4.588 seconds. 0 problems found. (brought to you by Amanda 3.5.1)
Start the manual backup with
amdump openhab-dir. This can take a long time and a status is not provided, just a busy command line.
After completion, check the backup report with
amreport openhab-dir. You should see something like:
backup@openhab:~$ amreport openhab-dir Hostname: openhab Org : openHABian openhab-dir Config : openhab-dir Date : September 10, 2020 These dumps were to tapes openHABian-openhab-dir-001, openHABian-openhab-dir-002. The next 10 tapes Amanda expects to use are: 10 new tapes. STATISTICS: Total Full Incr. Level:# -------- -------- -------- -------- Estimate Time (hrs:min) 0:13 Run Time (hrs:min) 0:49 Dump Time (hrs:min) 0:36 0:36 0:00 Output Size (meg) 7752.6 7752.6 0.0 Original Size (meg) 15521.2 15521.2 0.0 Avg Compressed Size (%) 49.9 49.9 -- DLEs Dumped 5 5 0 Avg Dump Rate (k/s) 3662.3 3662.3 -- Tape Time (hrs:min) 0:36 0:36 0:00 Tape Size (meg) 7752.6 7752.6 0.0 Tape Used (%) 145.4 145.4 0.0 DLEs Taped 5 5 0 Parts Taped 6 6 0 Avg Tp Write Rate (k/s) 3670.0 3670.0 -- USAGE BY TAPE: Label Time Size % DLEs Parts openHABian-openhab-dir-001 0:24 5460672K 100.0 5 5 openHABian-openhab-dir-002 0:12 2477962K 45.4 0 1 NOTES: planner: tapecycle (14) <= runspercycle (14) planner: Adding new disk openhab:/dev/mmcblk0. planner: Adding new disk openhab:/boot. planner: Adding new disk openhab:/etc. planner: Adding new disk openhab:/var/lib/openhab2. planner: Adding new disk openhab:/opt/zram/persistence.bind. planner: WARNING: no history available for openhab:/opt/zram/persistence.bind; guessing that size will be 500000 KB planner: WARNING: no history available for openhab:/var/lib/openhab2; guessing that size will be 500000 KB planner: WARNING: no history available for openhab:/etc; guessing that size will be 500000 KB planner: WARNING: no history available for openhab:/boot; guessing that size will be 500000 KB taper: Slot 1 without label can be labeled taper: tape openHABian-openhab-dir-001 kb 5460674 fm 5 [OK] taper: Slot 2 without label can be labeled taper: tape openHABian-openhab-dir-002 kb 2477962 fm 1 [OK] big estimate: openhab /boot 0 est: 500032K out 36419K big estimate: openhab /etc 0 est: 500032K out 654K big estimate: openhab /var/lib/openhab2 0 est: 500032K out 251695K big estimate: openhab /opt/zram/persistence.bind 0 est: 500032K out 0K DUMP SUMMARY: DUMPER STATS TAPER STATS HOSTNAME DISK L ORIG-KB OUT-KB COMP% MMM:SS KB/s MMM:SS KB/s ----------------------------------------- ----------------------- -------------- ------------- openhab /boot 0 54730 36419 66.5 0:09 3838.3 0:09 4046.6 openhab /dev/mmcblk0 0 15558144 7649866 49.2 35:05 3633.8 35:03 3637.6 openhab /etc 0 2760 654 23.7 0:01 647.3 0:00 6540.0 openhab /opt/zram/persistence.bind 0 10 1 10.0 0:01 0.8 0:02 0.0 openhab /var/lib/openhab2 0 278020 251695 90.5 0:51 4960.2 0:49 5136.6 (brought to you by Amanda version 3.5.1)
- Now you should test restoring the raw image of the SD card that was just backed up. To search for the raw SD card backups use:
amadmin openhab-dir find openhab /dev/mmcblk0
This should result in something like this:
backup@openhab:~$ amadmin openhab-dir find openhab /dev/mmcblk0 date host disk lv storage pool tape or file file part status 2020-09-10 14:17:09 openhab /dev/mmcblk0 0 openhab-dir openhab-dir openHABian-openhab-dir-001 5 1/2 OK 2020-09-10 14:17:09 openhab /dev/mmcblk0 0 openhab-dir openhab-dir openHABian-openhab-dir-002 1 2/2 OK
- Note the date on the backup you want to restore (YYYYMMDDhhmmss).
- Restore the raw SD card backup with:
amfetchdump -p openhab-dir openhab /dev/mmcblk0 <YYYYMMDDhhmmss> > /mnt/ext-storage/amanda/images/<filename>
Replace the date from the backup you want to restore (without the <> characters), and select your desired filename. This can take a while and should result in something like this:
ackup@openhab:~$ amfetchdump -p openhab-dir openhab /dev/mmcblk0 20200910141709 > /mnt/ext-storage/amanda/images/openhab-20200910 2 volume(s) needed for restoration The following volumes are needed: openHABian-openhab-dir-001 openHABian-openhab-dir-002 Press enter when ready Reading label 'openHABian-openhab-dir-001' filenum 5 split dumpfile: date 20200910141709 host openhab disk /dev/mmcblk0 part 1/UNKNOWN lev 0 comp N program APPLICATION 5153056 kb Reading label 'openHABian-openhab-dir-002' filenum 1 split dumpfile: date 20200910141709 host openhab disk /dev/mmcblk0 part 2/UNKNOWN lev 0 comp .gz program APPLICATION 7649866 kb
After completion, you should have the backup image in the
/mnt/ext-storage/amanda/imagesdirectory, which is also accessible from Ubuntu since we configured it to be shared through Samba.
.rawextension to the image file and flash to another SD card with Balena Etcher.
Note: I had issues when doing this because the original SD card on the RPi was larger (~100MB or so) than the replacement SD card I had, which made the backup image larger than the available storage. Balena Etcher then says the target is too small and flash is not possible. I’m still looking for the best way to handle this, open to suggestions. Reducing the size of the rootfs partition on the original SD card with gparted was not successful, as it seems Amanda backs up the entire SD card, allocated or not. Currently testing with pishrink.
- Amanda should now be doing the backups automatically. Check periodically for new entries with
amadmin openhab-dir find openhab /dev/mmcblk0
- openhabian v1.5 Stable
- openhab 2.5.8-1
- Raspberry Pi 3B+
- Added Note about image size when flashing a smaller SD card with Balena Etcher.