Files
shl_backup/backup.sh
2022-09-30 13:54:02 +02:00

64 lines
1.0 KiB
Bash

#! /bin/bash
source functions.sh
pidfile=/var/run/backup_script
mylog 0 "backup starts"
trap cleanup EXIT
function cleanup {
echo "bye bye"
test -f $pidfile && rm -f $pidfile
mylog 0 "backup done"
}
if [ -f $pidfile ] ; then
pid=$(cat $pidfile)
if [ -d /proc/$pid ] ; then
myerror 42 "$pid already running"
else
rm -f $pidfile
fi
fi
echo $$ > $pidfile
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
backupdir=/var/backups/$(date -I)
while getopts hl OPTION ; do
case $OPTION in
(l) listBackups ${backupdir}/.. ; ;;
(h) usage ; ;;
(*) usage ; ;;
esac
done
shift $(( OPTIND - 1))
mkdir -p $backupdir || myerror 2 "impossible de créer $backupdir"
for dir in "$@" ; do
test -d $dir || { echo $dir dont exist ; mylog 2 "$dir dont exists" ; continue ; }
echo cp -a $dir $backupdir
mylog $? "backup of $dir done"
done