options -h and -l

This commit is contained in:
2022-09-30 10:07:40 +02:00
parent eb903f25df
commit 92d3eef3cb

View File

@@ -1,17 +1,38 @@
#! /bin/bash
source /home/usera/functions.sh
source functions.sh
function listBackups {
ls -lrt $1
exit 0
}
function usage {
echo "$0 [-l] dir1 dir2"
echo "make or list backups"
exit 0
}
if [ $UID -ne 0 ] ; then
echo "need root"
exit 1
fi
while getopts l OPTION ; do
case $OPTION in
(l) listBackups ${backupdir}/.. ; ;;
(h) usage ; ;;
(*) usage ; ;;
esac
done
shift $((OPTIND -1))
backupdir=/var/backups/$(date -I)
mkdir -p $backupdir || myerror 2 "impossible de créer $backupdir"
for dir in "$@" ; do
test -d $dir || { echo $dir dont exist ; continue ; }
echo cp -a $dir bkpdir/
echo cp -a $dir $backupdir
done