commit fe922b7fd5875497bb2f0ea2b0b5fbbf677c5630 Author: Thomas Constans Date: Thu May 19 18:58:17 2022 +0200 solution diff --git a/backup.sh b/backup.sh new file mode 100644 index 0000000..f249592 --- /dev/null +++ b/backup.sh @@ -0,0 +1,23 @@ +#! /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 + +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