Install, Configure, and Test Amanda on openhabian for beginners

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 lsblk command
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 backup with sudo chown -R backup:backup /mnt/ext-storage/amanda and checked that it worked with ls -l

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 backup user with su backup as 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 available when doing su backup to switch to the backup user

  • 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 backup command. After this I could switch user with su backup

  • Finally I could test that user backup could indeed create and delete a file in the storage area /mnt/ext-storage/amanda.
    – Move to correct location with cd /mnt/ext-storage/amanda
    – Create file with touch testfile
    – Check that the file is owned by backup with ls -l
    – Delete file with rm testfile

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 /mnt/ext-storage/amanda/images.

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.

My /etc/samba/smb.conf file now has the following added directly after the [openHAB-logs] section.

[backup-images]
  comment=backup images of openhab system
  path=/mnt/ext-storage/amanda/images
  writable=yes
  public=no
  create mask=0777
  directory mask=0777

After executing 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

  • Execute sudo openhabian-config and 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.
    6.4.1 Amanda Email
    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 Yes.

  • The backup directory is requested, in my case /mnt/ext-storage/amanda6.4.4 Storage Location

  • Storage capacity dedicated to the backup must be entered. I put 5 times the size of my SD card (16GB).
    6.5.5 Storage Capacity

  • 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 Continue.

  • 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.

    I would interpret that selecting No quits the whole Amanda installation, when in fact it only skips the Amazon S3 configuration. Selecting No is 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 backup with su backup

  • Then use the command amcheck openhab-dir to check the Amanda status. openhab-dir is 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/images directory, which is also accessible from Ubuntu since we configured it to be shared through Samba.

  • Add a .raw extension 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

System

  • openhabian v1.5 Stable
  • openhab 2.5.8-1
  • Raspberry Pi 3B+

Edits

  • Added Note about image size when flashing a smaller SD card with Balena Etcher.
19 Likes

Thanks for taking the time to write this down.
May I ask you to contribute the essentials of this as a PR so it becomes a part of the official docs where you think they are “sparse” ? I’d assume you agree that it makes more sense to keep all the relevant information in one (official) location.

Some comments:

Check out the new auto backup feature.


All of this (password, shell) is set during Amanda install. You need not / should not manually do that beforehand so I cannot recommend doing what you did here.
Once install completes this is set and you can use the following to switch users

[21:51:17] openhabian@openHABianPi:~$ sudo su - backup
[21:51:26] backup@openHABianPi:~$

or this to execute single commands as user backup:

[22:08:18] openhabian@openHABianPi:/opt/openhabian$ sudo -u backup id
uid=34(backup) gid=34(backup) Gruppen=34(backup),6(disk),26(tape)
[22:08:22] openhabian@openHABianPi:/opt/openhabian$

Well.It’s not wrong, you can do it like this but if your client is a UNIX machine (which is is a pretty uncommon case, usually it’s a Windows box) I wouldn’t recommend to use Samba for that purpose.
The reasons for that are the same as those why you should not use CIFS/Samba to mount the storage from a remote server. See explanation in the Amanda README.
NFS will be the natural choice.

You need a mail relay to work to send mails. openHABian provides exim for that purpose.
Then again if you have not yet installed exim, you should be asked during Amanda installation right at the beginning even before asking for the email address.
You skipped that or messed with exim or your OS beforehand? At least it doesn’t happen on a “normal” system.

I changed that final question to read “Setup Amanda on AWS ?”

That’s a pretty ugly situation you should avoid in the first place by getting proper replacement gear.
I’ve added that recommendation to the official docs.
I intentionally omitted any instructions how to work around as they all require a fair amount of UN*X knowledge and there is a very high risk involved that something goes badly wrong, destroying your working system’s card.
The only real good way to handle this is to avoid this by getting a large enough card in the first place.

Well that was quick :wink:

I haven’t made a PR before but I’ll give it a shot when I get the chance.

This seems like an interesting feature, but my understanding is it’s still in beta? Some questions about this feature:

  • Does the auto-backup mirror the SD card continuously or at a specific time interval?

  • Is there any way to activate auto-backup after unattended installation?

  • In my openhabian configuration tool I cannot see menu option 54. Is this only available on openhabian v1.6 alpha? Or when auto-backup is activated? I am using v1.5 [stable] hoping for stability.

  • The instructions for when a card is broken are not clear to me:
    – Should the backup SD card simply be inserted into the RPi and used to boot?
    – Does the Amanda installation backup just the openhab files, or also raw images if there is enough space?

The problem is that the installation docs (under the heading Software Installation) ask the user to make sure that the backup user is the storage area owner and test file creation/deletion before installing Amanda. If a user follows the instruction sequence, they will encounter the same issue I had.

I will look into NFS, but for now Samba is working well and it means I can access the backed up images also from a Windows machine.

The Amanda installation did not ask me if I had setup exim or prompt me to install it before asking for the email address (which was the first prompt). It was a clean openhabian 1.5 install and Amanda was the first thing I did after configuring SSH access.

:+1:

I was under the impression that all SD cards have slightly differing capacity, and the only way to ensure that they were the same was to buy them together. Granted, I could have used the ‘smaller’ card as the original one and the larger one as the replacement.

pishrink seemed to work well and the backed up image is up and running.

BTW I appreciate all the time and work you have put into this, installing everything from scratch would have been a much bigger hassle and possibly induced rage quit.

1 Like

It won’t get out there if noone tests it :wink:

full dump once a month, daily rsync diff

The image version does not really make a difference as installation will clone the latest version from Github repo either way.
Currently you need to use the master branch (until next patchday when it’ll be forwarded into stable).

There’s menu options to interactively mirror your card. And to install Amanda, of course.

Yes. You are welcome to test and to improve the instructions. Obviously they’re pretty beta so far.

By default yes (same as in interactive install). But you can change disklist at any later time.

Had issues with permissions when using the Samba shares from Ubuntu (especially with openHAB configuration files, I had to create/save them with sudo from the Ubuntu machine) so chose to test nfs. This was successful using the following tutorials.

Server (RPi) Side
This and this combined. I did not change the owner of the shared directories and files, but did open up all permissions on the exported directories.

Client (Ubuntu) Side
This

My /etc/exports file on the server side is below. Be sure to change <client_IP> for the IP address of your Ubuntu machine.

/var/lib/openhab2 <client_IP>(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)
/etc/openhab2 <client_IP>(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)
/mnt/ext-storage/amanda/images <client_IP>(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.