Last active
January 2, 2019 12:29
-
-
Save rollcabbage/5e5e88995c57732ae20f to your computer and use it in GitHub Desktop.
files or log files backup script; backup object and destination be defined by associative array
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 | |
# | |
# created by RiHaku on June 2015 | |
# | |
# mount -t nfs -o rw,rsize=8192,wsize=8192,hard,intr,noatime,bg,nfsvers=3 10.51.0.91:/DMZ /mnt/data | |
# mount -t nfs -o rw,rsize=8192,wsize=8192,hard,intr,noatime,bg,nfsvers=3 10.51.0.91:/TRUST /mnt/data | |
# | |
# mount check; if not mounted, exit with status code | |
df -h | awk 'NR == 5 {print $1}' | grep 10.51.0.91 >/dev/null 2>&1 | |
if [[ $? -ne 0 ]]; then | |
logger "ERROR:NFS is not been mounted!" | |
exit $? | |
fi | |
# backup destination check; if not exist, create the directory | |
BACKUP_DESTINATION=`df -h | awk 'NR == 5{print $6}'`/backup_lastest/$HOSTNAME | |
if [[ ! -d $BACKUP_DESTINATION ]]; then | |
mkdir -p $BACKUP_DESTINATION | |
fi | |
# define backup object and destination | |
declare -A backup_list | |
backup_list=( | |
# ["/var/spool/cron/root"]="$BACKUP_DESTINATION/conf" | |
# ["/etc/httpd/conf/httpd.conf"]="$BACKUP_DESTINATION/conf" | |
# ["/etc/httpd/conf.d/www.rearie.jp_18080.conf"]="$BACKUP_DESTINATION/conf" | |
# ["/etc/httpd/conf.d/www.rearie.jp_18443.conf"]="$BACKUP_DESTINATION/conf" | |
# ["/opt/app/tomcat8-front/conf/server.xml"]="$BACKUP_DESTINATION/conf" | |
# ["/opt/app/tomcat8-front/conf/context.xml"]="$BACKUP_DESTINATION/conf" | |
# ["/var/log/secure"]="$BACKUP_DESTINATION/log/syslog" | |
# ["/var/log/messages"]="$BACKUP_DESTINATION/log/syslog" | |
# ["/var/log/maillog"]="$BACKUP_DESTINATION/log/syslog" | |
# ["/var/log/httpd"]="$BACKUP_DESTINATION/log/apachelog" | |
# ["/opt/app/tomcat8-front/logs"]="$BACKUP_DESTINATION/log/applog" | |
# ["/opt/app/tomcat8-front/webapps"]="$BACKUP_DESTINATION/app" | |
# ["/var/spool/cron/root"]="$BACKUP_DESTINATION/conf" | |
# ["/etc/httpd/conf/httpd.conf"]="$BACKUP_DESTINATION/conf" | |
# ["/etc/httpd/conf.d/mng.rearie.jp_28080.conf"]="$BACKUP_DESTINATION/conf" | |
# ["/etc/httpd/conf.d/mng.rearie.jp_28443.conf"]="$BACKUP_DESTINATION/conf" | |
# ["/opt/app/tomcat8-mng/conf/server.xml"]="$BACKUP_DESTINATION/conf" | |
# ["/opt/app/tomcat8-mng/conf/context.xml"]="$BACKUP_DESTINATION/conf" | |
# ["/var/log/secure"]="$BACKUP_DESTINATION/log/syslog" | |
# ["/var/log/messages"]="$BACKUP_DESTINATION/log/syslog" | |
# ["/var/log/maillog"]="$BACKUP_DESTINATION/log/syslog" | |
# ["/var/log/httpd"]="$BACKUP_DESTINATION/log/apachelog" | |
# ["/opt/app/tomcat8-mng/logs"]="$BACKUP_DESTINATION/log/applog" | |
# ["/opt/app/tomcat8-mng/webapps"]="$BACKUP_DESTINATION/app" | |
["/var/spool/cron/root"]="$BACKUP_DESTINATION/conf" | |
["/etc/httpd/conf/httpd.conf"]="$BACKUP_DESTINATION/conf" | |
["/etc/httpd/conf.d/www.stg.rearie.jp_18080.conf"]="$BACKUP_DESTINATION/conf" | |
["/etc/httpd/conf.d/www.stg.rearie.jp_18443.conf"]="$BACKUP_DESTINATION/conf" | |
["/etc/httpd/conf.d/www.rearie.jp_19080.conf"]="$BACKUP_DESTINATION/conf" | |
["/etc/httpd/conf.d/www.rearie.jp_19443.conf"]="$BACKUP_DESTINATION/conf" | |
["/opt/app/tomcat8-front/conf/server.xml"]="$BACKUP_DESTINATION/conf" | |
["/opt/app/tomcat8-front/conf/context.xml"]="$BACKUP_DESTINATION/conf" | |
["/etc/httpd/conf.d/mng.stg.rearie.jp_28080.conf"]="$BACKUP_DESTINATION/conf-mng" | |
["/etc/httpd/conf.d/mng.stg.rearie.jp_28443.conf"]="$BACKUP_DESTINATION/conf-mng" | |
["/etc/httpd/conf.d/mng.rearie.jp_29080.conf"]="$BACKUP_DESTINATION/conf" | |
["/etc/httpd/conf.d/mng.rearie.jp_29443.conf"]="$BACKUP_DESTINATION/conf" | |
["/opt/app/tomcat8-mng/conf/server.xml"]="$BACKUP_DESTINATION/conf-mng" | |
["/opt/app/tomcat8-mng/conf/context.xml"]="$BACKUP_DESTINATION/conf-mng" | |
["/var/log/secure"]="$BACKUP_DESTINATION/log/syslog" | |
["/var/log/messages"]="$BACKUP_DESTINATION/log/syslog" | |
["/var/log/maillog"]="$BACKUP_DESTINATION/log/syslog" | |
["/var/log/httpd"]="$BACKUP_DESTINATION/log/apachelog" | |
["/opt/app/tomcat8-front/logs"]="$BACKUP_DESTINATION/log/applog" | |
["/opt/app/tomcat8-mng/logs"]="$BACKUP_DESTINATION/log/applog-mng" | |
["/opt/app/tomcat8-front/webapps"]="$BACKUP_DESTINATION/app" | |
["/opt/app/tomcat8-mng/webapps"]="$BACKUP_DESTINATION/app-mng" | |
) | |
# if not exist, create the directory | |
if [[ ! -d ${backup_list[@]} ]]; then | |
mkdir -p ${backup_list[@]} | |
fi | |
for i in ${!backup_list[@]}; do | |
if [[ -f $i ]]; then | |
rsync -alrogpvt $i ${backup_list[$i]} | |
elif [[ -d $i ]]; then | |
rsync -alrogpvt $i/* ${backup_list[$i]} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment