Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
- # PLEASE UPDATE CONFIG BELOW #
- #@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
- # local file backup directory
- path='/home/hary/backup/app'
- # ftp/sftp config
- ftptype="sftp" #ftp
- ftppath="/home/hary/backup/app"
- ftpuser="hary"
- ftppassword=""
- ftpserver="192.168.88.28"
- ftpport="4637"
- # app source path
- appdirpath="/app/development"
- # app backup
- appnames="ib cm"
- # backup file lifetime before delete
- lifetime=7
- #@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
- # PLEASE UPDATE CONFIG ABOVE #
- #@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
- archive='.tgz'
- tgl=`/bin/date +%Y%m%d`
- jam=`/bin/date +%H%M%S`
- tgljam=${tgl}_${jam}
- for app in ${appnames}; do
- filepath=${path}/${app}
- echo "Checking file lifetime ${filepath}"
- #find ${filepath} -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;
- find ${filepath} -maxdepth 1 -type f -mtime +${lifetime} -exec rm -rf {} \;
- filename=${app}_${tgljam}${archive}
- if [ ! -d ${filepath} ]; then /bin/mkdir -p ${filepath}; fi
- cd ${filepath}
- echo "Create/compress application backup ${filename}"
- if [ "${archive}" == ".tar.gz" ]
- then
- cd ${appdirpath}
- tar -czf ${filepath}/${filename} ${app} -R
- elif [ "${archive}" == ".tgz" ]
- then
- cd ${appdirpath}
- tar -czf ${filepath}/${filename} ${app} -R
- elif [ "${archive}" == ".zip" ]
- then
- zip -rv9 ${filepath}/${filename} "${appdirpath}/${app}"
- else
- echo "unknown archive type ${archive}"
- fi
- #touch ${filename}
- echo "Upload application backup ${filename}"
- if [ "${ftptype}" == "ftp" ]
- then
- lftp -u ${ftpuser},${ftppassword} -p ${ftpport} -e "set ftp:passive-mode on; mkdir -p ${ftppath}/${app}/${tgl}; cd ${ftppath}/${app}/${tgl}; mput ${filepath}/${filename}; quit" ${ftpserver}
- elif [ "${ftptype}" == "sftp" ]
- then
- lftp sftp://${ftpuser}:${ftppassword}@${ftpserver} -p ${ftpport} -e "mkdir -p ${ftppath}/${app}/${tgl}; cd ${ftppath}/${app}/${tgl}; put ${filepath}/${filename}; bye"
- else
- echo "unknown ftp type ${ftptype}"
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement