Skip to content
Snippets Groups Projects
Commit 8f967bab authored by Florent Gluck's avatar Florent Gluck
Browse files

added backup.sh

parent 4cca3c27
Branches master
No related tags found
No related merge requests found
#!/bin/bash
function copy {
echo "Copie de $1"
cp $1 $2
if [ $? -ne 0 ]; then
echo "Failed copying $1 to $2" >&2
exit 5
fi
name=$(basename $1)
f=$2/$name
chmod 440 $f
if [ $? -ne 0 ]; then
echo "Failed chaning $f permissions" >&2
exit 6
fi
}
if [ $# -ne 2 ]; then
name=$(basename $0)
echo "Usage: $name src dest" >&2
echo "src source directory containing txt and dat files" >&2
echo "dst destination directory" >&2
exit 1
fi
if [ ! -d $1 ]; then
echo "source directory not found or not a directory!" >&2
exit 2
fi
DATA=$1
BACKUP=$2
# Si repertoire existe
if [ -d $BACKUP ]; then
# Efface les anciens backups
rm -f $BACKUP/*
if [ $? -ne 0 ]; then
echo "Failed removing files" >&2
exit 3
fi
else
# Cree repertoire
mkdir -p $BACKUP
if [ $? -ne 0 ]; then
echo "Failed creating $BACKUP directory" >&2
exit 4
fi
fi
# Backup les fichiers .txt et .dat
for f in $DATA/*.txt $DATA/*.dat; do
copy $f $BACKUP # appel à la fonction
done
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment