Compare commits

1 Commits

Author SHA1 Message Date
96bf93020b solution 2022-05-20 12:07:39 +02:00

38
backup.sh Normal file
View File

@@ -0,0 +1,38 @@
#! /bin/bash
set -eu
IFS=$'\n\t'
[ $UID -eq 0 ] || { echo "need to be root" ; exit 1 ; }
if [ $# -lt 1 ] ; then
echo "missing dir list"
exit 1
fi
while getopts h OPTION ; do
case $OPTION in
(h)
echo "Usage: $0 dir1 [dir2] [dir3] [...]"
exit 0
;;
(*)
echo "Mauvaise option"
exit 1
;;
esac
done
bdir=/var/run/backup_$(date -I)
mkdir -p $bdir || exit 2
for dir in "$@" ; do
test -d $dir || { echo $dir dont exists ; continue ; }
dirname=$(basename $dir)
tar -cpzf ${bdir}/${dirname}.tgz $dir
echo $? > /run/${dirname}.status
done