[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Script para uso em backups...
From: |
Fernando Lemes da Silva |
Subject: |
Script para uso em backups... |
Date: |
Thu, 23 Oct 2003 14:27:10 -0300 |
Olá pessoal, terminei o script que estava fazendo... ele basicamente le
uma lista de arquivos e baseado em um banco de dados simples retorna quais
arquivos foram alterados desde a ultima execução. O que mais tomou tempo e
aumentou o codigo foi a interface com o usuário... Se alguem notar algum
erro, ou maneira de melhorar a eficiencia do código, por favor me de um
toque... futuramente pretendo disponibilizar estes scripts que já fiz em um
site ou coisa assim.
[]'s
Fernando Lemes
P.S. Ainda estou fazendo o segundo script para copiar os arquivos que
este script apontar...
------------------------------------------
#!/bin/bash
# Default configs
# Database filename
dbfile=".cfmod.db"
# Update md5 database
updatedb=1
# Clean database, purge inexistent files
cleandb=0
# Read stdin
usestdin=1
# Sort files
sort=0
if [ -e .cfmod.tmp ]; then rm -f .cfmod.tmp; fi
touch .cfmod.tmp
if [ "$1" = "" ]; then nopar=1; fi
while [ "$1" != "" ] || [ "$nopar" = "1" ]; do
invalid=1
if [ "$1" = "--noupdate" ]; then updatedb=0; invalid=0; fi
if [ "$1" = "--clean" ]; then cleandb=1; invalid=0; fi
if [ "$1" = "--sort" ]; then sort=1; invalid=0; fi
if [ "$1" = "--thisdb" ]; then if [ -e "$2" ]; then dbfile="$2"; shift;
invalid=0; else invalid=2; fi; fi
if [ "$1" = "--help" ] || [ "$nopar" = "1" ]; then
echo
1>&2
echo "cfmod v.1.1 - Check File Modifications"
1>&2
echo "Check file modifications using md5sum hash algorithm."
1>&2
echo
1>&2
echo " Usage:"
1>&2
echo " --clean : Clean database purging files that don't
exists anymore" 1>&2
echo " --file <filename> : Open <filename> to read files and
directories list" 1>&2
echo " --help : Display this message"
1>&2
echo " --noupdate : Don't update md5 database"
1>&2
echo " --sort : Sort filenames ascending. Must be set
before --file" 1>&2
echo " --thisdb <filename> : Use <filename> as an alternate md5
database" 1>&2
echo
1>&2
exit 0
fi
if [ "$1" = "--file" ]; then
if [ -e "$2" ]; then
usestdin=0
if [ -e .cfmod.tmp2 ]; then rm -f .cfmod.tmp2; fi
touch .cfmod.tmp2
while read filelist; do $(find "$filelist" -type f >> .cfmod.tmp2);
done < "$2"
if [ "$sort" = "1" ]; then sort .cfmod.tmp2 >> .cfmod.tmp;
else cat .cfmod.tmp2 >> .cfmod.tmp; fi
rm -f .cfmod.tmp2
invalid=0
shift
else invalid=2; fi
fi
if [ "$invalid" -eq "1" ]; then echo -e "\nError: Invalid option $1\a";
nopar=1; fi
if [ "$invalid" -eq "2" ]; then echo -e "\nError: File not found ($2)\a";
nopar=1; fi
shift
done
if [ ! -e "$dbfile" ]; then touch "$dbfile"; fi
#
# Check file $1, dbfile $2, update flag $3
#
function checkthisfile () {
a=$(md5sum "$1" | cut -f 1 -d " ")
b=$(grep "$1$" "$2" | cut -f 1)
if [ "$a" != "$b" ]; then
echo "$1"
if [ "$3" -eq "1" ]; then
if [ -z "$b" ]; then
echo -e "$a\t$1" >> "$2";
else
grep -v "$1$" "$2" > .cfmod.db.tmp
echo -e "$a\t$1" >> .cfmod.db.tmp;
rm -f "$2"
mv .cfmod.db.tmp "$2"
fi
fi
fi
}
# Main
if [ "$usestdin" -eq "1" ]; then
while read x; do checkthisfile "$x" "$dbfile" "$updatedb"; done
else
if [ "$(cat .cfmod.tmp | wc -l | sed 's/ //g')" -gt "0" ]; then
while read x; do checkthisfile "$x" "$dbfile" "$updatedb"; done <
.cfmod.tmp
else echo -e "Nothing to do.\a" 1>&2; exit 2; fi
if [ -e .cfmod.tmp ]; then rm -f .cfmod.tmp; fi
fi
# Clean db
if [ "$cleandb" -eq "1" ]; then
if [ -e .cfmod.db.tmp ]; then rm -f .cfmod.db.tmp; fi
touch .cfmod.db.tmp
while read x; do if [ -e "$(echo "$x" | cut -f 2)" ]; then echo "$x" >>
.cfmod.db.tmp; fi; done < $dbfile
rm -f $dbfile
mv .cfmod.db.tmp $dbfile
fi
exit 0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Script para uso em backups...,
Fernando Lemes da Silva <=