#!/bin/bash
backup_dir=
/data/backup/confluence
backup_log=
/data/backup/log/backup
.log
err_log=
/data/backup/log/err
.log
date_time=`
date
+
"%Y%m%d%H%M"
`
#delete backup file for 14 days ago
find
/usr/local/confluence-data/backups/
* -atime +14 -name
"backup*"
-
exec
rm
-rf {} \;
#delete tomcat log for a week ago
find
/usr/local/apache-tomcat-7
.0.63
/logs/
* -
type
f -atime -7 -
exec
rm
-rf {} \;
#print line of separation to log
echo
-e
"\033[33m--------------------------------------\033[0m"
>> ${backup_log}
echo
-e `
date
+
"%Y-%m-%d %H:%M"
` >> ${backup_log}
echo
-e
"Starts backing up confluence...."
>> ${backup_log}
#mysql backup
mysqldump -uroot -pcarkey confluence >
/usr/local/confluence_
${date_time}.sql 2>>${err_log}
if
[
"$?"
-
ne
0 ];
then
echo
-e
"\033[31mconfluence database backup failed!\033[0m"
>> ${backup_log}
echo
-e
"\033[33m--------------------------------------\033[0m"
>> ${backup_log}
echo
-e
"\n"
>> ${backup_log}
echo
-e
"at ${date_time} confluence backup mysql error"
>> ${err_log}
echo
-e
"\n"
>> ${err_log}
exit
1
else
echo
-e
"\033[32mconfluence database backup success!\033[0m"
>> ${backup_log}
fi
#backup confluence
cd
/usr/local
zip -r9 ${backup_dir}
/confluence_
${date_time}.zip apache-tomcat-7.0.63 confluence_${date_time}.sql confluence-data -x
"confluence-data/backups/*"
1>
/dev/null
2>>${err_log}
if
[
"$?"
-
ne
0 ];
then
echo
-e
"\033[31mconfluence packaged failed!\033[0m"
>> ${backup_log}
echo
-e
"\033[33m--------------------------------------\033[0m"
>> ${backup_log}
echo
-e
"\n"
>> ${backup_log}
echo
-e
"at ${date_time} packaged confluence file error"
>> ${err_log}
echo
-e
"\n"
>> ${err_log}
rm
-rf
/usr/local/confluence_
${date_time}.sql
exit
2
else
rm
-rf
/usr/local/confluence_
${date_time}.sql
echo
-e
"\033[32mconfluence Packaging Success!\033[0m"
>> ${backup_log}
echo
-e
"\033[33m--------------------------------------\033[0m"
>> ${backup_log}
echo
-e
"\n"
>> ${backup_log}
fi
find
${backup_dir}/* -
type
f -atime +15 -
exec
rm
-rf {} \;