Browse Source

sysmocom-backup-data: add alternative package for overlay based systems

When using squashfs + overlayfs a root, we need to store the backup
somewhere else and restore it on every boot. Do avoid breaking existing
users, this is implemented in a separate recipe (as suggested by Holger).
neels/inmarsat
Jan Luebbe 6 years ago
committed by Holger Hans Peter Freyther
parent
commit
5b5741f314
  1. 20
      recipes-apps/sysmocom-backup-data/files/default.files
  2. 7
      recipes-apps/sysmocom-backup-data/files/sysmobts-v2/data.mount
  3. 56
      recipes-apps/sysmocom-backup-data/files/sysmocom-backup
  4. 7
      recipes-apps/sysmocom-backup-data/files/sysmocom-bsc/data.mount
  5. 7
      recipes-apps/sysmocom-backup-data/files/sysmocom-odu/data.mount
  6. 26
      recipes-apps/sysmocom-backup-data/files/sysmocom-restore
  7. 12
      recipes-apps/sysmocom-backup-data/files/sysmocom-restore.service
  8. 37
      recipes-apps/sysmocom-backup-data/sysmocom-backup-data_1.0.bb

20
recipes-apps/sysmocom-backup-data/files/default.files

@ -0,0 +1,20 @@
etc/hostname
etc/ifplugd.sh
etc/network/interfaces
etc/openvpn
etc/opkg/sysmocom-config.conf
etc/osmocom/osmo-bsc-mgcp.cfg
etc/osmocom/osmo-bsc.cfg
etc/osmocom/osmo-bts.cfg
etc/osmocom/osmo-nitb.cfg
etc/osmocom/osmo-pcu.cfg
etc/osmocom/osmo-sgsn.cfg
etc/systemd/system/multi-user.target.wants/osmo-nitb.service
etc/systemd/system/multi-user.target.wants/osmo-bsc.service
etc/systemd/system/multi-user.target.wants/osmo-sgsn.service
etc/ggsn.conf
etc/default
var/lib/osmocom/hlr.sqlite3
etc/lcr
etc/udhcpd.conf
etc/sysmocom/backup.d

7
recipes-apps/sysmocom-backup-data/files/sysmobts-v2/data.mount

@ -0,0 +1,7 @@
[Unit]
Description=/data
[Mount]
What=ubi0:data
Where=/data
Type=ubifs

56
recipes-apps/sysmocom-backup-data/files/sysmocom-backup

@ -0,0 +1,56 @@
#!/bin/sh
# Make sure to look at sysmocom-restore to check if the file would
# be restored right. Currently only some dirs get restored.
FILES="etc/sysmocom/backup.d"
# Pick some extra files
if [ -e /etc/sysmocom/backup.d/ ]; then
for extra in `ls /etc/sysmocom/backup.d/*.backup`;
do
echo "Add extras from $extra."
FILES="$FILES `cat $extra`"
done
fi
DATE=`date +%Y%m%d`
do_backup_files() {
BACKUP_FILE="/data/sysmocom-backup_$DATE.tar"
# 0. Sanity checking
if [ -e $BACKUP_FILE ]; then
echo "The backup file '$BACKUP_FILE' already exists. Exiting!"
exit 1
fi
# 1. Create an empty archive..
tar -cf $BACKUP_FILE --files-from=/dev/null
# 2. Add all the files... we need
for file in $FILES;
do
if [ -e "/$file" ]; then
tar -rf $BACKUP_FILE --transform='s,^,content/,' -C / $file
fi
done
# 3. Generate more information
NAME="/tmp/backup.$RANDOM"
mkdir $NAME
opkg list_installed > $NAME/installed_packages
/sbin/ifconfig | grep HWaddr | cut -d ' ' -f 11 > $NAME/mac_addr
# 4. Add the more information
tar -rf $BACKUP_FILE --transform='s,^,info/,' -C $NAME installed_packages mac_addr
# 5. Create stable link
ln -sf $BACKUP_FILE /data/sysmocom-backup.tar
# 6.
echo "The backup was stored to $BACKUP_FILE"
}
do_backup_files

7
recipes-apps/sysmocom-backup-data/files/sysmocom-bsc/data.mount

@ -0,0 +1,7 @@
[Unit]
Description=/data
[Mount]
What=/dev/sda4
Where=/data
Type=ext4

7
recipes-apps/sysmocom-backup-data/files/sysmocom-odu/data.mount

@ -0,0 +1,7 @@
[Unit]
Description=/data
[Mount]
What=ubi0:data
Where=/data
Type=ubifs

26
recipes-apps/sysmocom-backup-data/files/sysmocom-restore

@ -0,0 +1,26 @@
#!/bin/sh
do_extract() {
# List the files and check if grep hits something
SEARCH=`tar -tvf $1 | grep $2`
RES=$?
if [ $RES = 0 ]; then
tar --transform='s,^content/,,' -C / -xvf $1 $2
else
echo "Directory '$2' is not in backup '$1'."
fi
}
do_restore_files() {
BACKUP_FILE=$1
if [ ! -e "$BACKUP_FILE" ] ; then
echo "The backup file '$BACKUP_FILE' does not exist. Exiting!"
exit 1
fi
echo "Going to extract files from the backup '$BACKUP_FILE'"
do_extract $BACKUP_FILE content/etc
do_extract $BACKUP_FILE content/var/lib/osmocom
}
do_restore_files $1

12
recipes-apps/sysmocom-backup-data/files/sysmocom-restore.service

@ -0,0 +1,12 @@
[Unit]
Description=Restore Configuration Backup
Requires=data.mount
After=data.mount
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/sbin/sysmocom-restore /data/sysmocom-backup.tar
[Install]
WantedBy=multi-user.target

37
recipes-apps/sysmocom-backup-data/sysmocom-backup-data_1.0.bb

@ -0,0 +1,37 @@
DESCRIPTION = "sysmocom config backup and restore scripts"
LICENSE = "GPLv3+"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
PR = "r12"
SRC_URI = " \
file://sysmocom-backup \
file://sysmocom-restore \
file://data.mount \
file://sysmocom-restore.service \
file://default.files \
"
RDEPENDS_${PN} = "tar"
RCONFLICTS_${PN} = "symocom-backup"
inherit systemd
do_install() {
install -d ${D}${sbindir}
install -m 0755 ${WORKDIR}/sysmocom-backup ${D}${sbindir}/
install -m 0755 ${WORKDIR}/sysmocom-restore ${D}${sbindir}/
install -d ${D}${sysconfdir}/sysmocom/backup.d
install -m 0644 ${WORKDIR}/default.files ${D}${sysconfdir}/sysmocom/backup.d/
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/data.mount ${D}${systemd_unitdir}/system/
install -m 0644 ${WORKDIR}/sysmocom-restore.service ${D}${systemd_unitdir}/system/
}
PACKAGES =+ "${PN}-default"
FILES_${PN}-default = "${sysconfdir}/sysmocom/backup.d/"
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "data.mount sysmocom-restore.service"
SYSTEMD_AUTO_ENABLE_${PN} = "enable"
Loading…
Cancel
Save