Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

Backup Atlassian

Download the file and use search and replace in a text editor

atlassianbackup.sh

##You can make a copy of script and use a program (I use GEdit) to FIND AND REPLACE to easily convert to working copy-paste code!

## This backs up the /var/atlassian/application-data/* && /opt/atlassian/*
##Variables
#[DATABASE] with WP MySQL database name
#[DOMAIN] with domain
#[USERNAME] with MySQL real username
#[PASSWD] with password for MySQL username
#[BACKUPTARGET] without trailing /
#I recommend filling in bottom part as you go along!

1. Create Exclude file for excluding Files/Folders from Backup

mkdir -p [BACKUPTARGET]/[DOMAIN]/tar
touch [BACKUPTARGET]/[DOMAIN]/exclude.sh && nano [BACKUPTARGET]/[DOMAIN]/exclude.sh && chmod 600 [BACKUPTARGET]/[DOMAIN]/exclude.sh && sudo chown $USER:nogroup [BACKUPTARGET]/[DOMAIN]/exclude.sh 

--You should just create the exclude_wp.sh and not use if you don't want to, this command will work if file exists and is empty, but at a later date you can add to it without modifying Crontab. (The TAR command will fail if file does not exist!)

Example exclude_wp.sh

Lets say site is /var/www/html/domain/ & and the file tree is

/var/www/html/domain/file1
/var/www/html/domain/file2
/var/www/html/domain/file3
/var/www/html/domain/folder1
/var/www/html/domain/folder2
/var/www/html/domain/folder3

You want to exclude file1 and folder 1

exclude_wp.sh contents would be:

file1
folder1

OR
folder1
file1

2. Create and test TAR statement

tar -czf [BACKUPTARGET]/[DOMAIN]/tars/"VAR$(date '+%F').tar.gz" -C / var/atlassian/application-data/ -X [BACKUPTARGET]/[DOMAIN]/exclude.sh
tar -czf [BACKUPTARGET]/[DOMAIN]/tars/"OPT$(date '+%F').tar.gz" -C / opt/atlassian/ -X [BACKUPTARGET]/[DOMAIN]/exclude.sh 

3. Create password file to prevent the need for user input when accessing MySQL via CLI

mkdir [BACKUPTARGET]/[DOMAIN]/sqldumps 
nano [BACKUPTARGET]/[DOMAIN]/.sqlpwd && chmod 600 [BACKUPTARGET]/[DOMAIN]/.sqlpwd && sudo chown $USER:nogroup [BACKUPTARGET]/[DOMAIN]/.sqlpwd 

.sqlpwd contents

[mysqldump] # NEEDED FOR DUMP
user=[USERNAME]
password=[PASSWD]

[mysql] # NEEDED FOR RESTORE
user=[USERNAME]
password=[PASSWD] 

 

4. Create SQL statement and test!

SQL CLI Syntax

mysqldump --defaults-extra-file=[BACKUPTARGET]/[DOMAIN]/.sqlpwd [DATABASE] > [BACKUPTARGET]/[DOMAIN]/sqldumps/"$(date '+%F').sql" 

5. Create FIND statement to find and remove all backups older then 1 week.

find [BACKUPTARGET]/[DOMAIN]/sqldumps -mtime +7 -delete && find [BACKUPTARGET]/[DOMAIN]/tars -mtime +7 -delete 

6. Create Script to be called by Crontab

nano [BACKUPTARGET]/[DOMAIN]/atlassian_backup.sh && sudo chmod 700 [BACKUPTARGET]/[DOMAIN]/atlassian_backup.sh && sudo chown $USER:nogroup [BACKUPTARGET]/[DOMAIN]/atlassian_backup.sh 

atlassian_backup.sh contents

*Example*:

#!/bin/bash
 
TAR STATEMENT
SQL STATEMENT
FIND STATEMENT

 

Try running script via

./atlassian_backup.sh

and if SQL and TAR files show up, delete them to test Crontab later!

7. Create Crontab Entry:

crontab -e

 

First Test via: *Run every 2 minutes*

*/2 * * * * [BACKUPTARGET]/[DOMAIN]/atlassian_backup.sh

 

Should see both TAR and SQL dump show up in under 5 minutes

Change Crontab Entry to: *Run @ 5 AM Daily*

* 5 * * * [BACKUPTARGET]/[DOMAIN]/atlassian_backup.sh

#(Optional) Fill In here for Reference

1. exclude.sh:
2. TAR STATEMENT:
3. .SQLPWD:
4. SQL STATEMENT:
5. FIND STATEMENT:
6. "SCRIPT" *backupwp.sh*
#!/bin/bash
TAR STATEMENT
SQL STATEMENT
FIND STATEMENT
7. CRONTAB ENTRY:

Example file tree once done:

[BACKUPLOCATION]/                       # Where ALL Domain/WordPress Site backups go
[BACKUPLOCATION]/[DOMAIN]/              # Domain/WordPress Site specific directory
[BACKUPLOCATION]/[DOMAIN]/exclude_wp.sh # Files and Folders to exclude from Domain TAR backup
[BACKUPLOCATION]/[DOMAIN]/.sqlpwd       # SQL Username and PWD on WP Database for Website
[BACKUPLOCATION]/[DOMAIN]/backupwp.sh   # Final Backup Script to be called by CRON
[BACKUPLOCATION]/[DOMAIN]/tars/         # Where TARs of WordPress Directory are stored
[BACKUPLOCATION]/[DOMAIN]/sqldumps/     # Where SQL dumps of the SQL database are stored

Real Example of my Script: (I no longer use CRON, but Jenkins, but its all the same really)

 

#!/bin/bash

tar -czf /Backups/atlassian/Jira/tars/"VAR$(date '+%F').tar.gz" -C / var/atlassian/application-data/ -X /Backups/atlassian/Jira/exclude.sh
tar -czf /Backups/atlassian/Jira/tars/"OPT$(date '+%F').tar.gz" -C / opt/atlassian/ -X /Backups/atlassian/Jira/exclude.sh
mysqldump --defaults-extra-file=/Backups/atlassian/Jira/.sqlpwd jiradb > /Backups/atlassian/Jira/sqldumps/"$(date '+%F').sql"
find /Backups/atlassian/Jira/sqldumps -mtime +7 -delete && find /Backups/atlassian/Jira/tars -mtime +7 -delete

 

 

  • No labels