diff --git a/backup.sh b/backup.sh new file mode 100644 index 0000000..1e914c4 --- /dev/null +++ b/backup.sh @@ -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 \ No newline at end of file