#!/bin/bash
#all.file.backup.sh
BACKDIR=/path/to/your/back/dir/`date +%Y%m%d`/
LOGFILE=/path/to/your/log/file.log
ORIPATH=/path/to/your/original/dir/

echo “Backup BEGIN at `date +%Y%m%d-%H:%M:%S`“ >> $LOGFILE
# is EXIST the Directory of Backup
if [ ! -d $BACKDIR ]; then
mkdir -p $BACKDIR
echo “Created $BACKDIR at `date +%Y%m%d-%H:%M:%S`“ >> $LOGFILE
fi
# is exist of log file
if [ ! -f $LOGFILE ]; then
touch $LOGFILE
echo “Create $LOGFILE at `date +%Y%m%d-%H:%M:%S`“ >> $LOGFILE
fi

SUBDIRLIST=`ls -p $ORIPATH | grep / | tr -d /`
for subdir in $SUBDIRLIST
do
echo ‘#####################’ >> $LOGFILE
echo “Backup $file at `date +%Y%m%d-%H:%M:%S`“ >> $LOGFILE
tar -zcvf $BACKDIR/$subdir.tar.gz $ORIPATH/$subdir
echo ‘#####################’ >> $LOGFILE
done

echo “Backup END at `date +%Y%m%d-%H:%M:%S`“ >> $LOGFILE