From 79545ec6cdf60db2eae1d1cf8ce5708a8ecb18be Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 10 Aug 2015 14:47:35 +0200 Subject: [PATCH] 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. --- .../files/sysmocom-backup-data | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/recipes-apps/sysmocom-backup-data/files/sysmocom-backup-data b/recipes-apps/sysmocom-backup-data/files/sysmocom-backup-data index 94eeb12..d78e458 100755 --- a/recipes-apps/sysmocom-backup-data/files/sysmocom-backup-data +++ b/recipes-apps/sysmocom-backup-data/files/sysmocom-backup-data @@ -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" }