Created
August 27, 2016 07:21
-
-
Save tim-tang/6b9cbf9205db124bd4535743da77df1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
#VRIABLES DEFINITION | |
CURRENT_YEAR=`date|cut -c 25-28` | |
CURRENT_MONTH=`date +%m` | |
CURRENT_DAY=`date +%d` | |
CURRENT_HOUR=`date|cut -c 12-13` | |
CURRENT_MINUTE=`date|cut -c 15-16` | |
CURRENT_SECOND=`date|cut -c 18-19` | |
LOG_DATE_FORMAT=$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DAY:$CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND | |
pidfile=`basename $0`.pid | |
run() | |
{ | |
here=$(pwd) | |
options='-azv --progress --exclude="*/log/*"' | |
password='--password-file=$here/rsyncd_repos.pas' | |
images='root@173.255.253.43:/root/everyday2.0/everyday/public/system' | |
scripts='root@173.255.253.43:/root/backup/' | |
notify='tim.tang@xplusz.com' | |
logfile=$here/$LOG_DATE_FORMAT.log | |
echo "Sync everyday file start at [$LOG_DATE_FORMAT]." | |
rsync $options $password $images $here > $logfile 2>&1 | |
tail -n188 $logfile | mail -s "Rsync backup everyday files complete" $notify | |
} | |
start() | |
{ | |
touch $pidfile | |
echo $$ > $pidfile | |
run | |
} | |
stop() | |
{ | |
kill -9 $(ps -ef | grep `cat $pidfile` | awk '{print $2}') | |
rm $pidfile | |
} | |
case "$1" in | |
start) | |
echo "Start backup...." | |
start | |
;; | |
stop) | |
echo "Stop backup...." | |
stop | |
;; | |
*) | |
echo "useage: "`basename $0`" (start | stop)" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment