Prerequisites
Goals
2. Install amanda
apt-get install amanda-server
apt-get install amanda-client
3. Create the config directory
mkdir /etc/amanda/openhab-dir
4. Create the main config file
Show /etc/amanda/opehab-dir/amanda.conf
Hide /etc/amanda/opehab-dir/amanda.conf
⇛ Watch the parameters marked in red! To copy to clipboard, click the code
org "openHABian openhab-dir" # Organization name for reports mailto "RECIPIENT@DOMAIN.TLD" # Email address to receive reports netusage 10000 Kbps # Bandwidth limit, 10M dumpcycle 14 days # when fulldump will be forced, inbetween incremental backups are possible (14 days = every 14 days fulldump) runspercycle 14 # how often will a backup be started (using amdump cronjob) within a dumpcycle (14 / 14 days = once per day) tapecycle 15 tapes # recommended formula: value = (runspercycle + 1) * runtapes runtapes 1 # just one tape / one slot per backup (don't use more than one tapes, even if tape is full -> generate error) tpchanger "chg-disk:/mnt/NAS" # The tape-changer glue script taper-parallel-write 2 autolabel "openHABian-openhab-dir-%%%" empty changerfile "/etc/amanda/openhab-dir/storagestate" # The tape-changer or SD- or disk slot or S3 state file tapelist "/etc/amanda/openhab-dir/tapelist" # The tapelist file tapetype DIRECTORY infofile "/var/lib/amanda/openhab-dir/curinfo" # Database directory logdir "/var/log/amanda/openhab-dir" # Log directory indexdir "/var/lib/amanda/openhab-dir/index" # Index directory # tapetypes as defined in 'tapetype' above define tapetype DIRECTORY { # Define our tape behaviour length 15360 mbytes # size of every virtual container (= max. usage per directory) } amrecover_changer "changer" # Changer for amrecover #configurations (how to dump) for 'disklist' file define dumptype global { # The global dump definition maxdumps 2 # maximum number of backups run in parallel holdingdisk no # Dump to temp disk (holdingdisk) before backup to tape index yes # Generate index. For restoration usage } define dumptype root-tar { # How to dump root's directory global # Include global (as above) program "GNUTAR" # Program name for compress estimate server # Estimate the backup size before dump comment "root partitions dumped with tar" compress none # No compression index # Index this dump priority low # Priority level } define dumptype user-tar { # How to dump user's directory root-tar # Include root-tar (as above) comment "user partitions dumped with tar" priority medium # Priority level } define application-tool app_amraw { # how to dump the SD card's raw device /dev/mmcblk0 plugin "amraw" # uses 'dd' } define dumptype amraw { global program "APPLICATION" application "app_amraw" } #define dumptype comp-user-tar { # How to dump & compress user's directory # user-tar # Include user-tar (as above) # compress client fast # Compress in client side with less CPU (fast) #} # vim: filetype=conf
5. Create client authentication file
/etc/amanda/openhab-dir/amanda-client.conf
auth "local"
6. Create the disklist (here mmcblk0 is the internal eMMC)
/etc/amanda/openhab-dir/disklist
hostname /dev/mmcblkX amraw
7. Set user permissions for user backup
chown -R backup:backup /etc/amanda/openhab-dir/
8. Run the script below to
Hint: Run the script with bash shell, not sh!
Show script
Hide script
#!/bin/bash
# Created by Boris Manojlovic (modified by Stefan Haupt)
# License: Public Domain
# GLOBALS
CFGNAME=""
TAPENAME=""
MAXTAPES=""
VTAPESFOLDER=""
usage () {
echo
echo "USAGE:"
echo " $0 <CONFIG_NAME> <TAPENAME> # you can provide the tapename here"
echo " $0 <CONFIG_NAME> # the script will ask you for the tape name"
echo
echo "Example:"
echo " $0 openhab-dir mytape"
echo
return 0
}
readconfig () {
CFGNAME=$1
TAPENAME=$2
if [ ! -f /etc/amanda/$CFGNAME/amanda.conf ]; then
echo "ERROR:No Config \"${CFGNAME}\" file found"
return -1
fi
# Get number of tapes in "charger"
MAXTAPES=`grep tapecycle /etc/amanda/${CFGNAME}/amanda.conf |grep -v ^#|cut -d " " -f 2`
VTAPESFOLDER=`grep tpchanger /etc/amanda/${CFGNAME}/amanda.conf|grep -v ^#|cut -d '"' -f 2|cut -d ':' -f 2`
if [ "x${VTAPESFOLDER}" == "x" ]; then
echo "ERROR: Unable to read 'tpchanger' value from /etc/amanda/${CFGNAME}/amanda.conf"
return -1
fi
echo "Please type in tape label text: "
if [ "x${TAPENAME}" == "x" ]; then
read TAPENAME
fi
if [ "x${TAPENAME}" == 'x' ] ; then
echo "ERROR:TAPENAME cannot be empty"
return -1
fi
echo "Name of tape which will be used is: ${TAPENAME}"
return 0
}
if [ $# -lt 1 ]; then
usage
else
CONFIG=$1
TAPENAME=$2
readconfig ${CONFIG} ${TAPENAME}
if [ $? -ne 0 ];then
echo "Exiting"
exit -1
fi
echo "DEBUG:CFGNAME=${CFGNAME} TAPENAME=${TAPENAME} MAXTAPES=${MAXTAPES} VTAPESFOLDER=${VTAPESFOLDER}"
mkdir -p ${VTAPESFOLDER}
cd ${VTAPESFOLDER}
for i in `seq 1 ${MAXTAPES}`; do
mkdir -p slot$i;
done
chown -R backup:backup ${VTAPESFOLDER}
ls -al ${VTAPESFOLDER}
usermod --shell /bin/bash backup
for i in `seq 1 ${MAXTAPES}`; do
su - backup -c 'amlabel $0 $1$2 slot $2' -- ${CONFIG} ${TAPENAME} ${i}
done
fi
# end of script
9. Create /etc/cron.d/amanda
0 1 * * 3 backup /usr/sbin/amdump openhab-dir >/dev/null 2>&1 0 0/2 * * * backup /usr/sbin/amcheck -m openhab-dir >/dev/null 2>&1 0 2 * * * root (tar czf /mnt/NAS/amanda_data_$(date +\%Y\%m\%d\%H\%M\%S).tar.gz -C / etc/amanda var/lib/amanda) 30 2 * * * root (tar --exclude=var/lib/openhab2/cache --exclude=var/lib/openhab2/tmp -czf /mnt/NAS/system_data_$(date +\%Y\%m\%d\%H\%M\%S).tar.gz -C / etc/cron.d usr/local/bin etc/openhab2 var/lib/openhab2 var/log/openhab2) 45 2 * * * root (find /mnt/NAS -mtime +180 -delete)
10. Test your configuration
You might see some info messages that some files don't exist, which will be created the next time you start your backup.
cd /tmp
su backup
amcheck openhab-dir
1. At first you need to download Linux for your device - here Armbian for Orange Pi +2E - and write the image to your SD Card (e.g. with Win32DiskImager).
Then boot your device from the SD Card and install amanda:
apt-get update
apt-get install amanda-server
apt-get install amanda-client
2. Make sure your NFS share is mounted during boot
3. Assign a shell to user backup
usermod --shell /bin/bash backup
4. Assign a shell to user backup
usermod --shell /bin/bash backup
1. Extract the latest backup amanda data from NFS share
cd / tar xvzf /mnt/NAS/amanda_data_TIMESTAMP.tar.gz
2. Change to user backup
su backup
3. Create restore image from slot data
Syntax: amfetchdump -p openhab-dir ORIGINALHOSTNAME ORIGINALDEVICE DATE_TO_RESTORE_TO_YYYYMMDD > /mnt/NAS/restoreimage Example: amfetchdump -p openhab-dir smarthome /dev/mmcblk0 20180702 > /mnt/synology/restoreimage
4. Dump image to eMMC
Attention: When booted from SD Card the eMMC is /dev/mmcblk1
Remark: dd does not output any progress bar, you just have to wait
dd bs=4M if=/mnt/
NAS
/restoreimage of=/dev/mmcblk1
1. Optional: Verify slot data
dd if=/mnt/NAS/slots/slotX/0000..._dev_...0 bs=32k count=1
Should output something like:
...
To restore, position tape at start of file and run:
dd if=<tape> bs=32k skip=1 | /bin/gzip -dc | /usr/lib/amanda/application/amraw restore [./file-to-restore]+
2. Create restore image from slot data
Attention: When booted from SD Card the eMMC is /dev/mmcblk1
Remark: dd does not output any progress bar, you just have to wait
cd directory_with_enough_space dd if=/mnt/NAS/slots/slotX/0000...._dev_....0 bs=32k skip=1 | /bin/gzip -dc | /usr/lib/amanda/application/amraw restore
3. Dump image to eMMC
dd bs=4M if=/mnt/NAS/amraw-restored of=/dev/mmcblk1
rm -rf /var/lib/amanda/openhab-dir/* rm -rf /var/log/amanda/openhab-dir/* rm -rf /var/log/amanda/client/openhab-dir/* rm -rf /var/log/amanda/server/openhab-dir/* rm /etc/amanda/openhab-dir/tapelist
Eventually this recreate the target directory structure / slots as described above.