sysmoocom-backup-data: Optimize taking a backup

With the ro image we have a cheap way to figure out which
files were changed. We can run cmp between the to be backed
up file. This way the stored data will be minimal in the
sense of changed files.
This commit is contained in:
Holger Hans Peter Freyther 2015-08-10 14:47:35 +02:00
parent 09dbe7bd33
commit 79545ec6cd
1 changed files with 31 additions and 8 deletions

View File

@ -16,6 +16,31 @@ fi
DATE=`date +%Y%m%d`
# Called for a file. Compare with the content in /ro-root
# if this file has been modified and only take it then. In
# case the file is not present it in /ro-root it will be
# added to the backup set
backup_file() {
cmp -s /$2 /ro-root/$2
if [ $? -ne 0 ]; then
echo "Adding $2"
tar -rf $1 --transform='s,^,content/,' -C / $2
fi
}
# Check if this is a file, otherwise descend
handle_file() {
if [ -f "/$2" -a -e "/$2" ]; then
backup_file $1 $2
fi
if [ -d "/$2" -a -e "/$2" ]; then
for file in /$2/*;
do
# Construct to have no leading /
handle_file $1 $2/`basename $file`
done
fi
}
do_backup_files() {
BACKUP_FILE="/data/sysmocom-backup_$DATE.tar"
@ -32,24 +57,22 @@ do_backup_files() {
# 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
handle_file $BACKUP_FILE $file
done
# 3. Generate more information
NAME="/tmp/backup.$RANDOM"
# 4. Generate more information
NAME="/tmp/backup.$$"
mkdir $NAME
opkg list_installed > $NAME/installed_packages
/sbin/ifconfig | grep HWaddr | cut -d ' ' -f 11 > $NAME/mac_addr
# 4. Add the more information
# 5. Add the more information
tar -rf $BACKUP_FILE --transform='s,^,info/,' -C $NAME installed_packages mac_addr
# 5. Create stable link
# 6. Create stable link
ln -sf $BACKUP_FILE /data/sysmocom-backup.tar
# 6.
# 76
echo "The backup was stored to $BACKUP_FILE"
}