less than 1 minute read

#!/bin/bash

20120116 admin

registed Crontab

0 5 * * * /bin/bash /root/file_backup.sh > /dev/null 2>&1

#

export LANG=ko_KR.euckr

HNAME=uname -n LOGDIR=’/root/log’ SYSADMIN=”admin@admin.com” BACKUPDATE=date --date='now' +%Y%m%d CONTENTS=”[FileServerBackup] $HNAME Server $BACKUPDATE Batch Job Report” LOGFILE=”$LOGDIR/$BACKUPDATE-file_backup.sh_log”

IO redirection for logging.

exec 6>&1       # Link file descriptor #6 with stdout.                 # Saves stdout. exec > $LOGFILE # stdout replaced with file $LOGFILE.

외부서버 디스크 마운트

mkdir /file_backup mount /dev/sdc1  /file mount -t cifs //XXX.XXX.XXX.XXX/YYY/ /file_backup -o username=USER,password=PASS,iocharset=euc-kr,ro

RSYNC 로 복사

DIRLIST=ls -D /file_backup/ for DIRL in $DIRLIST do         rsync -av /file_backup/$DIRL   /file/ done

외부서버 디스크 언마운트

umount /file_backup umount /file rm -rf /file_backup

#Clean up IO redirection exec 1>&6 6>&-      # Restore stdout and close file descriptor #6.

/bin/cat $LOGFILE mail -s “$CONTENTS” $SYSADMIN

🔗original-link

Updated: