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" }