options -h and -l
This commit is contained in:
25
backup.sh
25
backup.sh
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user