-
Notifications
You must be signed in to change notification settings - Fork 9
/
atlassian_full_backup
executable file
·99 lines (84 loc) · 2.6 KB
/
atlassian_full_backup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# This script is meant to be run as a root cronjob to backup a Confluence or JIRA server
# It utilizes two scripts:
# - atlassian_fs_backup - create filesystem backup
# - atlassian_db_backup - crate database backup
#
# After the backup completes successfully, we check to see that only seven days worth of
# backup directories. Anything older than seven days is removed.
# Must be root to run this script
if [ "`/usr/bin/id -urn`" != "root" ] ; then
echo -e "\nYou must be root to execute this script \n"
exit 1
fi
USAGE() {
echo -e "\nUsage: `basename $0` [ -c | -j ] "
echo -e "-c --> Backup Confluence"
echo -e "-j --> Backup JIRA"
}
BACKUP_DIR="/atlassianbackup"
SCRIPT_DIR="/usr/local/bin/atlassian"
FS_BACKUP="${SCRIPT_DIR}/atlassian_fs_backup"
DB_BACKUP="${SCRIPT_DIR}/atlassian_db_backup"
TODAY=`date "+%Y%m%d"`
DAYSAGO=`date -d 'now - 1 days' "+%Y%m%d"`
APP="null"
while getopts ":cj" OPT ; do
case ${OPT} in
c)
APP="confluence"
FS_OPTIONS="-c"
DB_OPTIONS="-c -s"
;;
j)
APP="jira"
FS_OPTIONS="-j"
DB_OPTIONS="-j -s"
;;
\?)
echo -e "\nInvalid option: -${OPTARG}" >&2
USAGE
exit 1
;;
:)
echo -e "\nOption -${OPTARG} requires an argument" >&2
USAGE
exit 1
;;
esac
done
if [ "${APP}" == "null" ] ; then
USAGE
exit 1
fi
DAILY_BACKUP_DIR="${BACKUP_DIR}/${APP}/${TODAY}"
# -------------------------------------------------------------
# Execute Full Backup
# -------------------------------------------------------------
mkdir -p ${DAILY_BACKUP_DIR}
echo -e "\nPerforming ${APP} filesystem backup..."
${FS_BACKUP} ${FS_OPTIONS}
if [ $? -ne 0 ] ; then
echo -e "Error performing ${APP} filesystem backup! Exiting from backup process.\n"
exit 1
fi
echo -e "\nPerforming ${APP} database backup..."
${DB_BACKUP} ${DB_OPTIONS}
if [ $? -ne 0 ] ; then
echo -e "Error performing ${APP} database backup! Exiting from backup process.\n"
exit 1
fi
mv ${BACKUP_DIR}/${APP}_*_${TODAY_}* ${DAILY_BACKUP_DIR}
# -------------------------------------------------------------
# Rotate Backup Files - Keep Files for ${DAYSAGO}
# -------------------------------------------------------------
BACKUP_DATES=`find ${BACKUP_DIR}/${APP} -type d -name "[0-9]*" -printf "%f\n" | sort -n`
# Each backup directory is named in YYYYMMDD format based on the day it was created.
# If a directory's name is older than $DAYSAGO, the directory is removed.
if [ -n "${BACKUP_DATES}" ] ; then
for DATE in ${BACKUP_DATES} ; do
if [ $(( ${DATE} - ${DAYSAGO} )) -lt 0 ] ; then
rm -rf ${BACKUP_DIR}/${APP}/${DATE}
fi
done
fi