Files
shell_log/backup.sh
2022-05-20 11:13:34 +02:00

32 lines
559 B
Bash

#! /bin/bash
set -eu
IFS=$'\n\t'
function _log {
logfile=$(basename $0).log
echo $(date) $@ >> $logfile
}
_log "starting"
[ $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
ret=$?
echo $ret > /run/${dirname}.status
_log backup of $dir done with code $ret
done
_log "done"