Project

General

Profile

RE: How to backup redmine? ยป redmine-backup.sh

Robert Klajko, 2013-06-06 09:49

 
1
#!/bin/dash
2
NOW=`date +'%Y.%m.%d %T'`
3
echo $NOW' Start'
4

    
5
DB_USERNAME='<USERNAME>'
6
DB_PASSWORD='<PASSWORD>'
7
DB_NAME='redmine_production'
8
REDMINE_ROOT='/var/www/redmine'
9
BACKUP_ROOT='/var/backups'
10
BACKUP_ROOT_REDMINE=$BACKUP_ROOT/redmine
11
BACKUP_ROOT_REDMINE_TMP=$BACKUP_ROOT/redmine/tmp
12

    
13
GS_FILENAME='redmine_full_backup_'`date +%Y%m%d`'.tar.gz'
14

    
15
NOW=`date +'%Y.%m.%d %T'`
16
#echo $NOW' Setting up directories'
17
mkdir $BACKUP_ROOT -p
18
mkdir $BACKUP_ROOT_REDMINE -p
19
rm -rf $BACKUP_ROOT_REDMINE_TMP/db
20
mkdir $BACKUP_ROOT_REDMINE_TMP/db -p
21
rm -rf $BACKUP_ROOT_REDMINE_TMP/files
22
mkdir $BACKUP_ROOT_REDMINE_TMP/files -p
23
mkdir $BACKUP_ROOT_REDMINE/full -p
24

    
25
NOW=`date +'%Y.%m.%d %T'`
26
echo $NOW' Backing up database'
27
/usr/bin/mysqldump -u $DB_USERNAME --password=$DB_PASSWORD $DB_NAME | gzip > $BACKUP_ROOT_REDMINE_TMP/db/mysql_`date +%Y%m%d`.sql.gz
28

    
29
NOW=`date +'%Y.%m.%d %T'`
30
echo $NOW' Backing up attachments'
31
rsync -a $REDMINE_ROOT/files/ $BACKUP_ROOT_REDMINE_TMP/files/
32

    
33
NOW=`date +'%Y.%m.%d %T'`
34
echo $NOW' Packing into single archive'
35
#tar -czPf $BACKUP_ROOT_REDMINE/$GS_FILENAME $BACKUP_ROOT_REDMINE_TMP
36
cd $BACKUP_ROOT_REDMINE_TMP
37
tar -czf $BACKUP_ROOT_REDMINE/full/$GS_FILENAME ./
38

    
39
NOW=`date +'%Y.%m.%d %T'`
40
echo $NOW' rsync to windows file server'
41
rsync -avz $BACKUP_ROOT_REDMINE/full/ /mnt/backupshare/redmine/
42

    
43
NOW=`date +'%Y.%m.%d %T'`
44
echo $NOW' Backup end'
    (1-1/1)