Create shell scripts that backup and restore configuration files used by the sysmocom products.hfreyther/master-next
parent
e9379558e3
commit
c4c453a1db
@ -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/openvpn
|
||||
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/ggsn.conf \
|
||||
etc/default/osmo-nitb \
|
||||
etc/default/osmo-bsc \
|
||||
etc/default/osmocom-tcpdump \
|
||||
var/lib/osmocom/hlr.sqlite3 \
|
||||
"
|
||||
DATE=`date +%Y%m%d`
|
||||
|
||||
|
||||
do_backup_files() {
|
||||
BACKUP_FILE="/home/root/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.
|
||||
echo "The backup was stored to $BACKUP_FILE"
|
||||
}
|
||||
|
||||
do_backup_files
|
@ -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 -C / -xvf $1 --strip=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
|
@ -0,0 +1,13 @@
|
||||
DESCRIPTION = "sysmocom config backup and restore scripts"
|
||||
LICENSE = "GPLv3+"
|
||||
LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
|
||||
PR = "r3"
|
||||
|
||||
SRC_URI = "file://sysmocom-backup file://sysmocom-restore"
|
||||
RDEPENDS_${PN} = "tar"
|
||||
|
||||
do_install() {
|
||||
install -d ${D}${sbindir}
|
||||
install -m 0755 ${WORKDIR}/sysmocom-backup ${D}${sbindir}/
|
||||
install -m 0755 ${WORKDIR}/sysmocom-restore ${D}${sbindir}/
|
||||
}
|
Loading…
Reference in new issue