Created
June 21, 2016 03:52
-
-
Save rkdgusrnrlrl/134ec83aa62dbaa5955491cdc42df735 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
#!/bin/bash | |
# 만든이 : 강현구(rkdgusrnrlrl@gmail.com) | |
# 제작일 : 2016-03-01 | |
# 사용방법 : backup {백업할파일명} => 해당 폴더에 해당 파일명 뒤에 날짜가 붙어서 백업됨 | |
# ex : member.db.20160301.back | |
# 개선 사항 | |
# - 옵션을 통해 백업 폴더 설정 | |
# | |
echo "backup start" | |
full_path=$1 | |
DIR=$(dirname "${full_path}") | |
FILE_NAME=$(basename "${full_path}") | |
echo "${DIR}" | |
echo "${FILE_NAME}" | |
if [ $full_path ] #파일 명 인자 체크 | |
then | |
if [ -f $full_path ] #파일 유무 체크 | |
then | |
echo "파일이 존재합니다." | |
if [ ! -d ${DIR}/back ] | |
then | |
echo "백업폴더가 존재 하지 않으므로 생성합니다." | |
mkdir ${DIR}/back | |
fi | |
date +%Y%m%d | xargs -i cp -p $full_path $DIR/back/$FILE_NAME.{}.back | |
echo "백업은 완료 하였습니다." | |
else | |
echo "파일이 존재하지 않습니다." | |
fi | |
else | |
echo "파일명을 입력해주세요" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment