Project

General

Profile

HowToInstallRedmineOnUbuntuServer » History » Version 23

Alexey Porotnikov, 2013-04-30 07:03
Misprint leading to obscure error. Instead of closing descriptor 6 the script creates empty file named as list of script flags.

1 19 Jan from Planio www.plan.io
h1. HowTo Install Redmine 1.3.x with Mercurial and Subversion on Ubuntu Server 10.04
2 1 Dimitry Profus
3
{{toc}}
4
5 2 Dimitry Profus
h2. Pre-install
6
7
# Set the timezone
8
<pre>
9
$ dpkg-reconfigure tzdata
10
11 11 Dimitry Profus
Select your timezone and exit.
12 2 Dimitry Profus
</pre>
13
# Set your hostname
14
<pre>
15 15 Dimitry Profus
$ sudo nano /etc/hostname
16 2 Dimitry Profus
17 5 Dimitry Profus
Enter your server name and save.
18 3 Dimitry Profus
19
eg.
20
21
redmine
22 2 Dimitry Profus
</pre>
23
# Map your fully qualified domain name (FQDN) to localhost
24
<pre>
25
$ sudo nano /etc/hosts
26
27
Add a line mapping local host to your FQDN and hostname and save. 
28
29
eg. 
30
31
127.0.0.1 redmine.domain.com redmine
32
</pre>
33
34 1 Dimitry Profus
h2. Redmine Installation
35
36
# Install the LAMP stack
37
<pre>
38
$ sudo tasksel install lamp-server
39
</pre>
40
# Install the required packages
41
<pre>
42 20 Peter Pan
$ sudo apt-get install build-essential subversion libmysqlclient-dev libdigest-sha1-perl libgemplugin-ruby libgemplugin-ruby1.8 libruby-extras libruby1.8-extras rails rake ruby rubygems rubygems1.8 ruby1.8-dev libopenssl-ruby1.8 
43 1 Dimitry Profus
</pre>
44 21 Peter Pan
-->Update rubygems
45
In some cases the your system will still be using rubygems 1.5, but you will need a later version. Check which version is installed by typing:
46
<pre>
47
$ gem --version
48
</pre>
49
If the version is 1.5: update rubygems
50
<pre>
51
gem install rubygems-update
52
cd /var/lib/gems/1.8/bin
53
sudo ./update_rubygems
54
</pre>
55
-->Install necessary gems
56 1 Dimitry Profus
<pre>
57 19 Jan from Planio www.plan.io
$ sudo gem install rails -v=2.3.14 --no-ri --no-rdoc
58 1 Dimitry Profus
$ sudo gem install rake -v=0.8.7 --no-ri --no-rdoc
59 18 Jan from Planio www.plan.io
$ sudo gem uninstall rake -v=0.9.2.2 
60 1 Dimitry Profus
$ sudo gem install i18n -v=0.4.2 --no-ri --no-rdoc
61
$ sudo gem install mysql --no-ri --no-rdoc
62
</pre> 
63
# Download Redmine into /user/share/redmine directory
64
<pre>
65 19 Jan from Planio www.plan.io
$ sudo svn co http://redmine.rubyforge.org/svn/branches/1.3-stable /usr/share/redmine
66 1 Dimitry Profus
</pre>
67
# Create an empty MySQL database and accompanying user named redmine for example.
68
<pre>
69
$ mysql -u root -p
70
(enter the mysql root user password)
71
> create database redmine character set utf8;
72
> create user 'redmine'@'localhost' identified by '[password]';
73
> grant all privileges on redmine.* to 'redmine'@'localhost' identified by '[password]';
74
> exit
75
</pre>
76
# Copy config/database.yml.example to config/database.yml and edit this file in order to configure your database settings for "production" environment.
77
<pre>
78
$ sudo cp /usr/share/redmine/config/database.yml.example /usr/share/redmine/config/database.yml
79
80
$ sudo nano /usr/share/redmine/config/database.yml
81
82
Modify to the following and save (ctrl+x)
83
84
production:
85
  adapter: mysql
86
  socket: /var/run/mysqld/mysqld.sock
87
  database: redmine
88
  host: localhost
89
  username: redmine
90
  password: [password]
91
  encoding: utf8
92
</pre>
93
# Generate a session store secret.
94
<pre>
95
$ cd /usr/share/redmine
96
97
$ sudo rake generate_session_store
98
</pre>
99
# Create the database structure, by running the following command under the application root directory:
100
<pre>
101
$ cd /usr/share/redmine
102
103
$ sudo rake db:migrate RAILS_ENV="production" 
104
</pre>
105
# Insert default configuration data in database, by running the following command:
106
<pre>
107
$ sudo RAILS_ENV=production rake redmine:load_default_data
108
</pre>
109
# Setting up permissions
110
<pre>
111
$ cd /usr/share/redmine
112 8 Dimitry Profus
$ sudo chown -R www-data:www-data files log tmp public/plugin_assets
113 1 Dimitry Profus
</pre>
114
# Test using the webrick web server
115
<pre>
116
$ cd /usr/share/redmine
117
118
$ ruby script/server webrick -e production
119
120
Point your web browser at http://[my server ip]:3000
121
122
You should now see the application welcome page.
123
</pre>
124
125
126
h2. Apache Integration
127
128
# Install the required packages
129
<pre>
130
$ sudo apt-get install libapache2-mod-passenger
131
</pre>
132
# Add a symbolic link to the public redmine web directory
133
<pre>
134
$ sudo ln -s /usr/share/redmine/public /var/www/redmine
135
</pre>
136
# Configure Passanger to run as www-data
137
<pre>
138
$ sudo nano /etc/apache2/mods-available/passenger.conf
139
140
Add the follow line and save (ctrl+x)
141
142
PassengerDefaultUser www-data
143
</pre>
144
# Create a new Apache site file
145
<pre> 
146
$ sudo nano /etc/apache2/sites-available/redmine 
147
</pre>
148
Add the following lines and save (ctrl+x)
149
<pre>
150
<VirtualHost *:80>
151
        ServerAdmin webmaster@localhost
152
        DocumentRoot /var/www
153
        ServerName myservername
154
        
155
        RewriteEngine on
156
        RewriteRule   ^/$  /redmine  [R]
157
158
        <Directory /var/www/redmine>
159
                RailsBaseURI /redmine
160
                PassengerResolveSymlinksInDocumentRoot on
161
        </Directory>
162
163
        ErrorLog /var/log/apache2/error.log
164
165
        # Possible values include: debug, info, notice, warn, error, crit,
166
        # alert, emerg.
167
        LogLevel warn
168
169
        CustomLog /var/log/apache2/access.log combined
170
</VirtualHost>
171
</pre>
172
For SSL add the following text instead
173
<pre>
174
<VirtualHost *:443>
175
        ServerAdmin webmaster@localhost
176
        DocumentRoot /var/www
177
        ServerName myservername
178
179
        SSLEngine On
180
        SSLCertificateFile /etc/apache2/ssl/redmine.pem
181
182
        RewriteEngine on
183
        RewriteRule   ^/$  /redmine  [R]
184
185
        <Directory /var/www/redmine>
186
                RailsBaseURI /redmine
187
                PassengerResolveSymlinksInDocumentRoot on
188
        </Directory>
189
190
        ErrorLog /var/log/apache2/error.log
191
192
        # Possible values include: debug, info, notice, warn, error, crit,
193
        # alert, emerg.
194
        LogLevel warn
195
196
        CustomLog /var/log/apache2/access.log combined
197
</VirtualHost>
198
</pre>
199
# Enable the Redmine website
200
<pre>
201
$ sudo a2dissite default
202
$ sudo a2ensite redmine
203
</pre> 
204
# Enable the Passenger and Rewite modules and restart Apache
205
<pre>
206
$ sudo a2enmod passenger
207
$ sudo a2enmod rewrite
208
$ sudo /etc/init.d/apache2 restart
209
</pre> 
210
# Test the setup
211
<pre>
212
Open up your favorite web browser and goto
213
214
http://[my site or ip]/redmine
215
</pre>
216
217
h2. Mercurial Integration
218
219
# Install the latest Mercurial release 
220
<pre>
221
$ sudo apt-get install python-software-properties
222
$ sudo add-apt-repository ppa:mercurial-ppa/releases
223
$ sudo apt-get update
224
$ sudo apt-get install mercurial libapache-dbi-perl libapache2-mod-perl2
225
</pre>
226
# Create the hg web directory
227
<pre>
228
$ sudo mkdir -p /var/hg/repos
229
</pre>
230
# Create the web cgi script file
231
<pre>
232
$ sudo nano /var/hg/hgwebdir.cgi
233
234
Add the following and save
235
236
#!/usr/bin/env python
237
#
238
from mercurial import demandimport; demandimport.enable()
239
from mercurial.hgweb.hgwebdir_mod import hgwebdir
240
import mercurial.hgweb.wsgicgi as wsgicgi
241
application = hgwebdir('hgweb.config')
242
wsgicgi.launch(application)
243
</pre>
244
# Create the cgi web config file 
245
<pre>
246
$ sudo nano /var/hg/hgweb.config
247
248
Add the following and save
249
250
[paths]
251
/=/var/hg/repos/**
252
253
[web]
254
allow_push = *
255
push_ssl = false
256
allowbz2 = yes
257
allowgz = yes
258
allowzip = yes
259
</pre>
260
# Setup permissions
261
<pre>
262
$ sudo chown -R www-data:www-data /var/hg
263
$ sudo chmod gu+x /var/hg/hgwebdir.cgi
264
</pre>
265
# Create a Apache config file
266
<pre>
267
$ sudo nano /etc/apache2/conf.d/hg.config
268
269
Add the following and save
270 22 Marcelo vk
# Use PerlLoadModule Apache2::Redmine when using apache2, or else you might get weird errors trying to authenticate.
271 1 Dimitry Profus
 
272
PerlLoadModule Apache::Redmine
273
ScriptAlias /hg  "/var/hg/hgwebdir.cgi"
274
<Location /hg  >
275
	AuthType Basic
276
	AuthName "Redmine Mercurial Repository" 
277
	Require valid-user
278
279
	#Redmine auth
280
	PerlAccessHandler Apache::Authn::Redmine::access_handler
281
	PerlAuthenHandler Apache::Authn::Redmine::authen_handler
282
	RedmineDSN "DBI:mysql:database=redmine;host=localhost" 
283
	RedmineDbUser "redmine" 
284
	RedmineDbPass "password" 
285
</Location>
286
</pre>
287
# Add a symbolic link to Redmine.pm
288
<pre>
289
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm
290
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm  
291
</pre>
292
# Enable the required Apache modules and restart Apache
293
<pre>
294
$ sudo /etc/init.d/apache2 restart
295
</pre>
296
# Create a new test repository and project in Redmine
297
<pre>
298
$ sudo hg init /var/hg/repos/test
299
$ sudo chown -R www-data:www-data /var/hg/repos/test
300
301
Create a new project with and identifier 'test'
302
303
In the project Settings > Repository set
304
SCM: Mercurial
305
Path to repository: /var/hg/repos/test
306
Press the 'Create' button
307
308
Goto to the Repository tab of the test project
309
</pre>
310
# View the test repository in the web browser 
311
<pre>
312
> http://[my site name]/hg/test
313
</pre>
314
315
h2. Subversion Integration
316
317
# Install the latest Mercurial release 
318
<pre>
319
$ sudo apt-get install subversion libapache2-svn libapache-dbi-perl libapache2-mod-perl2
320
</pre>
321
# Create the svn repository directory
322
<pre>
323
$ sudo mkdir /var/svn
324
</pre>
325
# Setup permissions
326
<pre>
327
$ sudo chown -R www-data:www-data /var/svn
328
</pre>
329
# Add a symbolic link to Redmine.pm
330
<pre>
331
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm
332
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm  
333
</pre>
334
# Create a Apache config file
335
<pre>
336
$ sudo nano /etc/apache2/conf.d/svn.config
337
</pre>
338
Add the following and save
339
<pre>
340
PerlLoadModule Apache::Redmine
341
<Location /svn>
342
	DAV svn
343
	SVNParentPath "/var/svn" 
344
	Order deny,allow
345
	Deny from all
346
	Satisfy any
347
348
	PerlAccessHandler Apache::Authn::Redmine::access_handler
349
	PerlAuthenHandler Apache::Authn::Redmine::authen_handler
350
	AuthType Basic
351
	AuthName "Redmine Subversion Repository" 
352
353
	#read-only access    
354
	<Limit GET PROPFIND OPTIONS REPORT>
355
		Require valid-user
356
		Allow from [my server ip]
357
		# Allow from another-ip
358
		 Satisfy any
359
	</Limit>
360
		# write access
361
		<LimitExcept GET PROPFIND OPTIONS REPORT>
362
		Require valid-user
363
	</LimitExcept>
364
365
	## for mysql
366
	RedmineDSN "DBI:mysql:database=redmine;host=localhost" 
367
	RedmineDbUser "redmine" 
368
	RedmineDbPass "password" 
369
</Location>
370
</pre>
371
# Enable the required Apache modules and restart Apache
372
<pre>
373
$ sudo a2enmod dav_svn
374
$ sudo /etc/init.d/apache2 restart
375
</pre>
376
# Create a new test repository
377
<pre>
378
$ sudo svnadmin create /var/svn/test
379
$ sudo chown -R www-data:www-data /var/svn/test
380
</pre>
381
382
h2. Automate Repository Creation
383
384
# Enable WS for repository management and generate and API key
385
<pre>
386
* From the Redmine Administration menu select Settings
387
* Click on the Repositories tab
388
* Enable the 'Enable WS for repository management' checkbox
389
* Click the 'Generate a key' link 
390
* Press the 'Save' button
391
</pre>
392
# Modify reposman.rb
393
<pre>
394 16 Dimitry Profus
$ sudo nano /usr/share/redmine/extra/svn/reposman.rb
395 1 Dimitry Profus
396
Add the following to module SCM and save  
397
398
  module Mercurial
399
    def self.create(path)
400
      Dir.mkdir path
401
      Dir.chdir(path) do
402
        system_or_raise "hg init"
403
      end
404
    end
405
  end
406
</pre>
407
# Schedule the reposman.rb script to run every minute
408
<pre>
409
$ sudo nano /etc/cron.d/redmine
410
</pre>
411
Add one of the following lines (not both) and save.
412
(Note: you will need to replace [my API key]  with the API key you generated in step 1) 
413
.
414
To create subversion repositories add:
415
<pre>
416 17 Dimitry Profus
* * * * * root ruby /usr/share/redmine/extra/svn/reposman.rb --redmine localhost/redmine --scm Subversion --svn-dir /var/svn --owner www-data --url file:///var/svn --key=[my API key] >> /var/log/reposman.log
417 1 Dimitry Profus
</pre>
418
OR to create Mecurial repositories add:
419
<pre>
420
* * * * * root ruby /usr/share/redmine/extra/svn/reposman.rb --redmine localhost/redmine --scm Mercurial --svn-dir /var/hg/repos --owner www-data --url /var/hg/repos --key=[my API key] >> /var/log/reposman.log
421
</pre>
422
423
h2. Automatic refresh of repositories in Redmine
424
425
# Schedule the fetch_changesets script to run every 15 minutes
426
<pre>
427 16 Dimitry Profus
$ sudo nano /etc/cron.d/redmine
428 1 Dimitry Profus
429
Add the following line and save
430
431
*/15 * * * * root ruby /usr/share/redmine/script/runner "Repository.fetch_changesets" -e production > /dev/null 2>&1
432
</pre>
433
# Setup a changegroup script on the Mercurial server to run fetch_changesets after each push to a Mercurial repository 
434
<pre>
435
$ sudo nano /var/hg/changegroup-hook
436
</pre>
437
Add the following text and save
438
(Note: you will need to replace [your API key] the API key you generated in Redmine
439
<pre>
440
#!/bin/sh
441
curl "http://localhost/redmine/sys/fetch_changesets?key=[your API key]"  > /dev/null 2>&1
442
</pre>
443
Setup permissions
444
<pre>
445
$ sudo chown www-data:www-data /var/hg/changegroup-hook
446
$ sudo chmod ug+x /var/hg/changegroup-hook
447
</pre>
448
Modify the hgweb.config file
449
<pre>
450
$ sudo nano /var/hg/hgweb.config
451
</pre>
452
Add the following section and save
453
<pre>
454
[hooks]
455
changegroup = /var/hg/changegroup-hook
456
</pre>
457
458
h2. Email Integration
459
460
# Install and configure Sendmail
461
<pre>
462
$ sudo apt-get install sendmail
463
$ sudo sendmailconfig
464
465
(Answer Yes to all questions which you will be asked)
466
</pre>
467
# Update the Redmine configuration file
468
<pre>
469
$ sudo nano /usr/share/redmine/config/configuration.yml
470
471
Add the following text and save
472
473
 production:
474
   email_delivery:
475
     delivery_method: :sendmail
476
</pre>
477
478
h2. Backup to Amazon S3 cloud storage
479
480
# Create an account at http://aws.amazon.com/ 
481
# Create a S3 bucket using the aws management console https://console.aws.amazon.com/ec2/home
482
# View your Access Keys at https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
483
# Build and install fuse to 2.8.4
484
<pre>
485
$ sudo wget https://launchpad.net/ubuntu/+archive/primary/+files/fuse_2.8.4.orig.tar.gz
486
$ cd fuse-2.8.4/
487
$ tar xzf fuse_2.8.4.orig.tar.gz 
488
$ sudo ./configure 
489
$ sudo make
490
$ sudo make install
491
</pre>
492
# Build and install s3fs 1.61 
493
<pre>
494
$ sudo apt-get install libxml2-dev
495
$ wget http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz
496
$ tar xzf s3fs-1.61.tar.gz 
497
$ cd s3fs-1.61/
498
$ sudo ./configure 
499
$ sudo make
500
$ sudo make install
501
</pre>
502
# Create a s3fs password file
503
<pre>
504
$ sudo nano /etc/passwd-s3fs
505
</pre>
506
Added your 'Access Key ID' and 'Secret Access Key' separated by a colon
507
<pre>
508
[accessKeyId]:[secretAccessKey]
509
</pre>
510
Setup permissions
511
<pre>
512 6 Dimitry Profus
sudo chmod 640 /etc/passwd-s3fs
513 1 Dimitry Profus
</pre> 
514
# Create mounting point
515
<pre>
516
$ sudo mkdir /mnt/s3
517
</pre>
518
# Mount your S3 bucket
519
<pre>
520
$ sudo s3fs [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
521
</pre>
522
# Test it worked and unmount
523
<pre>
524
$ echo hello > /mnt/s3/welcome.txt
525
$ ls /mnt/s3
526
$ sudo umount /mnt/s3
527
</pre>
528
# Create upstart job to mount the s3 file system start up
529
<pre>
530
$ sudo nano /etc/init/s3.conf
531
</pre>
532
Add the following text and save.
533
<pre>
534
description "Mount Amazon S3 file system on system start"
535
536
start on (local-filesystems and net-device-up IFACE!=lo)
537
stop on runlevel [016]
538
539
respawn
540
541
exec s3fs -f [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
542
</pre>
543
# Start the s3 job
544
<pre>
545
sudo start s3
546
</pre>
547
# Test it worked
548
<pre>
549
$ echo hello > /mnt/s3/welcome2.txt
550
$ ls /mnt/s3
551
</pre>
552
# Create the backup script file
553
<pre>
554
$ sudo apt-get install mailutils
555
$ sudo nano /usr/local/bin/backup-redmine.sh
556
</pre>
557
Add the following text and save.
558
<pre>
559 13 Dimitry Profus
#!/bin/bash
560 1 Dimitry Profus
# Script to backup Redmine files to a mounted storage device
561
# with daily, weekly, monthly backup rotation
562
563 12 Dimitry Profus
# Sysadmin email address
564
sysadmin_email="admin@domain.com"
565 1 Dimitry Profus
566
# What to backup
567 12 Dimitry Profus
db_dump_file="/usr/share/redmine/db/redmine-database-dump.sql"
568 1 Dimitry Profus
569 13 Dimitry Profus
backup_files="$db_dump_file /usr/share/redmine/files /var/hg /var/svn /etc/apache2/conf.d/hg.conf"
570 12 Dimitry Profus
backup_files="$backup_files /etc/apache2/sites-available/redmine /etc/init/s3.conf /etc/cron.d/redmine"
571
backup_files="$backup_files /usr/local/bin/backup-redmine.sh"
572
573 1 Dimitry Profus
# Where to backup to
574 12 Dimitry Profus
backup_dir="/mnt/s3"
575 1 Dimitry Profus
576
# Set database access
577 12 Dimitry Profus
redmine_db_name="redmine"
578
redmine_db_user="redmine"
579
redmine_db_password="password"
580 1 Dimitry Profus
581
# Encryption
582 12 Dimitry Profus
encrypt="true"
583 13 Dimitry Profus
secret_passphrase="password"
584 1 Dimitry Profus
585 12 Dimitry Profus
# Set rotation schedule in units of days ( 0 = disabled )
586 1 Dimitry Profus
daily_remove_older_than=6
587 12 Dimitry Profus
weekly_remove_older_than=31
588 1 Dimitry Profus
monthly_remove_older_than=62
589
590
# Redirect stderr to a log file
591 12 Dimitry Profus
error_log="/tmp/backup-redmine.log"
592 1 Dimitry Profus
exec 6>&2
593
exec 2>$error_log
594
595
on_exit() {
596
    # Restore IO output
597 23 Alexey Porotnikov
    exec 2>&6  6>&-
598 1 Dimitry Profus
599
    # Check for errors
600
    if [ -s "$error_log" ]; then
601 12 Dimitry Profus
        logger -t "$0" -s "#### Backup Failed ####"
602
        logger -t "$0" -s -f "$error_log"
603
        cat "$error_log" | mail -s "Backup failed!"  $sysadmin_email
604 1 Dimitry Profus
     else
605 12 Dimitry Profus
        logger -t "$0" -s "Backup Complete"
606 1 Dimitry Profus
    fi
607
608
    # Clean up
609
    rm -f $error_log
610
}
611
612
trap on_exit EXIT SIGHUP SIGINT SIGQUIT SIGTERM
613
614
# Setup variables for the archive filename.
615
hostname=$(hostname -s)
616
date_stamp=`date +%Y-%m-%d`                    # Date p e.g 2011-12-31
617
date_day_of_week=`date +%A`                    # Day of the week e.g. Monday
618
date_day_of_month=`date +%e`                   # Date of the Month e.g. 27
619
620
# Is the  backup directory mounted?
621
mount | grep -sq "$backup_dir"
622
if  [ $? != 0 ]; then
623
   echo "backup destination ${backup_dir} is not mounted" >&2
624
  exit 1
625 12 Dimitry Profus
fi
626 1 Dimitry Profus
627 12 Dimitry Profus
# Delete old archives
628 13 Dimitry Profus
find "${backup_dir}" -mtime +"$monthly_remove_older_than" -type f -name "${hostname}_fullbackup_monthly*" -exec rm {} \;
629
find "${backup_dir}" -mtime +"$weekly_remove_older_than" -type f -name "${hostname}_fullbackup_weekly*" -exec rm {} \;
630
find "${backup_dir}" -mtime +"$daily_remove_older_than" -type f -name "${hostname}_fullbackup_daily*" -exec rm {} \;
631 1 Dimitry Profus
632 12 Dimitry Profus
# Determine the backup schedule
633 1 Dimitry Profus
if [[ $monthly_remove_older_than -gt "0" && $date_day_of_month == "1" ]]; then
634 12 Dimitry Profus
    schedule="monthly"
635
elif [[ $weekly_remove_older_than -gt "0" && $date_day_of_week == "Saturday" ]]; then
636
    schedule="weekly"
637
elif [[ $daily_remove_older_than -gt "0" ]]; then
638
    schedule="daily"
639
else
640 1 Dimitry Profus
    echo "Invalid backup rotation schedule" >&2
641 12 Dimitry Profus
    exit 1
642 1 Dimitry Profus
fi
643 12 Dimitry Profus
644 13 Dimitry Profus
archive_file="${backup_dir}/${hostname}_fullbackup_${schedule}_${date_stamp}.tgz"
645 12 Dimitry Profus
646 1 Dimitry Profus
# Dump the redmine database
647 12 Dimitry Profus
rm -f "${db_dump_file}"
648 1 Dimitry Profus
mysqldump --user="${redmine_db_name}" --password="${redmine_db_password}" "${redmine_db_name}" > $db_dump_file
649
650
# Write the archive file to the backup directory
651
if [ $encrypt == "true" ]; then
652 13 Dimitry Profus
    tar czP ${backup_files} | gpg -c -z 0 --yes --no-use-agent --passphrase="${secret_passphrase}" -o "${archive_file}.gpg"
653 1 Dimitry Profus
else
654 13 Dimitry Profus
    tar czfP "${archive_file}" ${backup_files}
655 1 Dimitry Profus
fi
656
657
if [ -s "$error_log" ]; then
658
    exit 1
659
else
660
    exit 0
661
fi
662
</pre>
663
# Setup permissions 
664
<pre>
665 6 Dimitry Profus
sudo chmod 770 /usr/local/bin/backup-redmine.sh
666 1 Dimitry Profus
</pre>
667
# Schedule the backup to run once a day at 12am
668
<pre>
669
$ sudo nano /etc/cron.d/redmine
670
671
Add the following line and save
672
673
0 0 * * * root /usr/local/bin/backup-redmine.sh
674
</pre>
675
# Test the script
676
<pre>
677
$ sudo backup-redmine.sh
678
$ ls -R /mnt/s3
679
</pre>