1 项目备份 变量的形式 定时任务不执行就都写成了绝对路径
#!/bin/bash # # 项目路径 /usr/local/tomcat-bjkjdx 备份文件路径/usr/local/bak #BACKUP_BASE=/usr/local #/user/local/bak #BACKUP_HOME=$BACKUP_BASE/bak #判断是都存在bak文件自动创建 if [ ! -d /usr/local/bak ];then mkdir -p /usr/local/bak echo "已创建目录正在执行备份" else echo "正在执行应用备份" fi cd /usr/local/bak; tar -zcvf tomcat7_`date +%F`.tar.gz --exclude=*tar --exclude=*gz --exclude=*zip --exclude=*bak --exclude=logs /usr/local/tomcat7 #Remove more than 90 days before the backup find /usr/local/bak -mtime +90 -type f -exec rm {} /;
vim /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .—————- minute (0 – 59)
# | .————- hour (0 – 23)
# | | .———- day of month (1 – 31)
# | | | .——- month (1 – 12) OR jan,feb,mar,apr …
# | | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
44 13 * * * /home/oracle/back/oracle_back.sh
crontab /etc/crontab
crontab -l 检查是否备份
2 oracle 备份
DATE=$(date '+%Y%m%d%H%M%S') su - oracle -c " expdp username/password@orcl directory=dum dumpfile=username_$DATE.dmp logfile=username_$DATE.log full=y"
cd /home/oracle/back/
tar zcvf username_$DATE.tar.gz username_$DATE.*
find /home/oracle/back/ -mtime +90 -name "*.dmp" -exec rm -rf {} /;
find /home/oracle/back/ -mtime +90 -name "*.log" -exec rm -rf {} /;
find /home/oracle/back/ -mtime +180 -name "*.tar.gz" -exec rm -rf {} /;
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/244777.html