#!/bin/bash

#
# Create a backup list for each astium. with all the backup that are in the daily and weekly archive.
#
for serial in `ls /home/|grep "[0-9]\{5\}"|grep -v ^n`
do
        > /tmp/backup-$serial.txt
        for file in `find -L /home/$serial/archive/ -maxdepth 4 -name .backup_date -type f`
	do
                epoch_time=`cat $file`
                backup_directory=`dirname $file|sed -e s#/home/$serial/archive/##g`
                echo "$epoch_time,$backup_directory" >> /tmp/backup-$serial.txt
        done

        # Move old list to .old, overwrite if needed.
        if [ -f /home/$serial/.backup_lists ]
        then
                mv -f /home/$serial/.backup_lists /home/$serial/.backup_lists.old
        fi

        # Create a list of all backups.
        > /home/$serial/.backup_lists
        if [ -f /tmp/backup-$serial.txt ]
        then
                cat /tmp/backup-$serial.txt|sort -n|uniq > /home/$serial/.backup_lists

		# Remove tmp file.
		rm -f /tmp/backup-$serial.txt
        fi
done
