Alex Suslin

I'm a well known person within myself.

Daily Backup Atlassian JIRA & Confluence on Windows

Requirements:

  • daily jira & confluence mysql database backup;
  • daily backup of jira & confluence attachments directory;
  • backups archiving;
  • deleting the old backups (more than 14 days);

Please note that I had a requirements for windows machine, and I understand that linux provides more scalabale and elegant way to do that. That is a basic script that can be used as a working solution, any system administrator can do that without my help :)

At first, let’s define the variables:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
::Path to the directory with attachments (JIRA or Confluence)
set attachments="C:\Program Files\Atlassian\Application Data\JIRA\data"

:: Path to the directory for daily backups
set backup_folder=D:\Backups\Atlassian\JIRA\daily_backups

:: Path to mysqldump.exe
set mysqldump_path="C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe"

:: Username of MySQL database
set dbuser=root

:: Password to MySQL database
set dbpass=<change password>

:: Database that we're going to backup (JIRA or Confluence)
set dbname=jiradb

Every backup should have a unique name. So I’m proposing to use year, month, day and time interval in that name.

1
2
3
4
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set dt=%%c-%%a-%%b)
For /f "tokens=1-4 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b%%c%%d)
set backupdate=%1%dt%_%tm%
set date_folder=%1%dt%

Please feel free to name it as you wish. In my case the name pattern is : [db name].YYYY-MM-DD_tt

date_folder variable is for a directory. I’d like to have a folder with the name like YYYY-MM-DD that will be created on a daily basis and put the proper backups in it.

Thus, let’s create the directory if it is not created yet:

1
2
3
if exist %backup_folder%\%date_folder% GOTO NODIR
   mkdir %backup_folder%\%date_folder%
:NODIR

After that, the regular backup process with the help of mysqldump and archiving with 7zip. After that we can clean the archived file (as we have archive).

1
2
3
%mysqldump_path% --user=%dbuser% --password=%dbpass% --databases %dbname% > "%backup_folder%\%date_folder%\%dbname%.%backupdate%.sql"
"zip\7za.exe" a -tzip "%backup_folder%\%date_folder%\%dbname%.%backupdate%.zip" "%backup_folder%\%date_folder%\*.sql"
del "%backup_folder%\%date_folder%\*.sql"

Do not forget to archive our attachments:

1
"zip\7za.exe" a -tzip %backup_folder%\%date_folder%\attachments.%backupdate%.zip %attachments%

And what we still have to do is to delete the old backups:

1
forfiles -p %backup_folder% -s -d -14 -c "cmd /c if @isdir == TRUE rd /s /q @path"

That’s it! Now we can use that batch script in Windows Task Scheduler and scheduled it on a daily basis.

P.S. If the task is not working, please check: - Task should be launched even when the user is logged off - The user that is launching that task has the permissions to do that (r/w permissions) - Task should be launched from the directory where the script is located (optional parameter, but it is required to set the proper path)

P.P.S. If you would like to download script, please find it here: download

Comments