Project

General

Profile

HowToInstallRedmineOnUbuntuServer » History » Version 21

Peter Pan, 2012-07-08 16:56

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
 
271
PerlLoadModule Apache::Redmine
272
ScriptAlias /hg  "/var/hg/hgwebdir.cgi"
273
<Location /hg  >
274
	AuthType Basic
275
	AuthName "Redmine Mercurial Repository" 
276
	Require valid-user
277
278
	#Redmine auth
279
	PerlAccessHandler Apache::Authn::Redmine::access_handler
280
	PerlAuthenHandler Apache::Authn::Redmine::authen_handler
281
	RedmineDSN "DBI:mysql:database=redmine;host=localhost" 
282
	RedmineDbUser "redmine" 
283
	RedmineDbPass "password" 
284
</Location>
285
</pre>
286
# Add a symbolic link to Redmine.pm
287
<pre>
288
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm
289
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm  
290
</pre>
291
# Enable the required Apache modules and restart Apache
292
<pre>
293
$ sudo /etc/init.d/apache2 restart
294
</pre>
295
# Create a new test repository and project in Redmine
296
<pre>
297
$ sudo hg init /var/hg/repos/test
298
$ sudo chown -R www-data:www-data /var/hg/repos/test
299
300
Create a new project with and identifier 'test'
301
302
In the project Settings > Repository set
303
SCM: Mercurial
304
Path to repository: /var/hg/repos/test
305
Press the 'Create' button
306
307
Goto to the Repository tab of the test project
308
</pre>
309
# View the test repository in the web browser 
310
<pre>
311
> http://[my site name]/hg/test
312
</pre>
313
314
h2. Subversion Integration
315
316
# Install the latest Mercurial release 
317
<pre>
318
$ sudo apt-get install subversion libapache2-svn libapache-dbi-perl libapache2-mod-perl2
319
</pre>
320
# Create the svn repository directory
321
<pre>
322
$ sudo mkdir /var/svn
323
</pre>
324
# Setup permissions
325
<pre>
326
$ sudo chown -R www-data:www-data /var/svn
327
</pre>
328
# Add a symbolic link to Redmine.pm
329
<pre>
330
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache/Redmine.pm
331
$ sudo ln -s /usr/share/redmine/extra/svn/Redmine.pm /usr/lib/perl5/Apache2/Redmine.pm  
332
</pre>
333
# Create a Apache config file
334
<pre>
335
$ sudo nano /etc/apache2/conf.d/svn.config
336
</pre>
337
Add the following and save
338
<pre>
339
PerlLoadModule Apache::Redmine
340
<Location /svn>
341
	DAV svn
342
	SVNParentPath "/var/svn" 
343
	Order deny,allow
344
	Deny from all
345
	Satisfy any
346
347
	PerlAccessHandler Apache::Authn::Redmine::access_handler
348
	PerlAuthenHandler Apache::Authn::Redmine::authen_handler
349
	AuthType Basic
350
	AuthName "Redmine Subversion Repository" 
351
352
	#read-only access    
353
	<Limit GET PROPFIND OPTIONS REPORT>
354
		Require valid-user
355
		Allow from [my server ip]
356
		# Allow from another-ip
357
		 Satisfy any
358
	</Limit>
359
		# write access
360
		<LimitExcept GET PROPFIND OPTIONS REPORT>
361
		Require valid-user
362
	</LimitExcept>
363
364
	## for mysql
365
	RedmineDSN "DBI:mysql:database=redmine;host=localhost" 
366
	RedmineDbUser "redmine" 
367
	RedmineDbPass "password" 
368
</Location>
369
</pre>
370
# Enable the required Apache modules and restart Apache
371
<pre>
372
$ sudo a2enmod dav_svn
373
$ sudo /etc/init.d/apache2 restart
374
</pre>
375
# Create a new test repository
376
<pre>
377
$ sudo svnadmin create /var/svn/test
378
$ sudo chown -R www-data:www-data /var/svn/test
379
</pre>
380
381
h2. Automate Repository Creation
382
383
# Enable WS for repository management and generate and API key
384
<pre>
385
* From the Redmine Administration menu select Settings
386
* Click on the Repositories tab
387
* Enable the 'Enable WS for repository management' checkbox
388
* Click the 'Generate a key' link 
389
* Press the 'Save' button
390
</pre>
391
# Modify reposman.rb
392
<pre>
393 16 Dimitry Profus
$ sudo nano /usr/share/redmine/extra/svn/reposman.rb
394 1 Dimitry Profus
395
Add the following to module SCM and save  
396
397
  module Mercurial
398
    def self.create(path)
399
      Dir.mkdir path
400
      Dir.chdir(path) do
401
        system_or_raise "hg init"
402
      end
403
    end
404
  end
405
</pre>
406
# Schedule the reposman.rb script to run every minute
407
<pre>
408
$ sudo nano /etc/cron.d/redmine
409
</pre>
410
Add one of the following lines (not both) and save.
411
(Note: you will need to replace [my API key]  with the API key you generated in step 1) 
412
.
413
To create subversion repositories add:
414
<pre>
415 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
416 1 Dimitry Profus
</pre>
417
OR to create Mecurial repositories add:
418
<pre>
419
* * * * * 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
420
</pre>
421
422
h2. Automatic refresh of repositories in Redmine
423
424
# Schedule the fetch_changesets script to run every 15 minutes
425
<pre>
426 16 Dimitry Profus
$ sudo nano /etc/cron.d/redmine
427 1 Dimitry Profus
428
Add the following line and save
429
430
*/15 * * * * root ruby /usr/share/redmine/script/runner "Repository.fetch_changesets" -e production > /dev/null 2>&1
431
</pre>
432
# Setup a changegroup script on the Mercurial server to run fetch_changesets after each push to a Mercurial repository 
433
<pre>
434
$ sudo nano /var/hg/changegroup-hook
435
</pre>
436
Add the following text and save
437
(Note: you will need to replace [your API key] the API key you generated in Redmine
438
<pre>
439
#!/bin/sh
440
curl "http://localhost/redmine/sys/fetch_changesets?key=[your API key]"  > /dev/null 2>&1
441
</pre>
442
Setup permissions
443
<pre>
444
$ sudo chown www-data:www-data /var/hg/changegroup-hook
445
$ sudo chmod ug+x /var/hg/changegroup-hook
446
</pre>
447
Modify the hgweb.config file
448
<pre>
449
$ sudo nano /var/hg/hgweb.config
450
</pre>
451
Add the following section and save
452
<pre>
453
[hooks]
454
changegroup = /var/hg/changegroup-hook
455
</pre>
456
457
h2. Email Integration
458
459
# Install and configure Sendmail
460
<pre>
461
$ sudo apt-get install sendmail
462
$ sudo sendmailconfig
463
464
(Answer Yes to all questions which you will be asked)
465
</pre>
466
# Update the Redmine configuration file
467
<pre>
468
$ sudo nano /usr/share/redmine/config/configuration.yml
469
470
Add the following text and save
471
472
 production:
473
   email_delivery:
474
     delivery_method: :sendmail
475
</pre>
476
477
h2. Backup to Amazon S3 cloud storage
478
479
# Create an account at http://aws.amazon.com/ 
480
# Create a S3 bucket using the aws management console https://console.aws.amazon.com/ec2/home
481
# View your Access Keys at https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
482
# Build and install fuse to 2.8.4
483
<pre>
484
$ sudo wget https://launchpad.net/ubuntu/+archive/primary/+files/fuse_2.8.4.orig.tar.gz
485
$ cd fuse-2.8.4/
486
$ tar xzf fuse_2.8.4.orig.tar.gz 
487
$ sudo ./configure 
488
$ sudo make
489
$ sudo make install
490
</pre>
491
# Build and install s3fs 1.61 
492
<pre>
493
$ sudo apt-get install libxml2-dev
494
$ wget http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz
495
$ tar xzf s3fs-1.61.tar.gz 
496
$ cd s3fs-1.61/
497
$ sudo ./configure 
498
$ sudo make
499
$ sudo make install
500
</pre>
501
# Create a s3fs password file
502
<pre>
503
$ sudo nano /etc/passwd-s3fs
504
</pre>
505
Added your 'Access Key ID' and 'Secret Access Key' separated by a colon
506
<pre>
507
[accessKeyId]:[secretAccessKey]
508
</pre>
509
Setup permissions
510
<pre>
511 6 Dimitry Profus
sudo chmod 640 /etc/passwd-s3fs
512 1 Dimitry Profus
</pre> 
513
# Create mounting point
514
<pre>
515
$ sudo mkdir /mnt/s3
516
</pre>
517
# Mount your S3 bucket
518
<pre>
519
$ sudo s3fs [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
520
</pre>
521
# Test it worked and unmount
522
<pre>
523
$ echo hello > /mnt/s3/welcome.txt
524
$ ls /mnt/s3
525
$ sudo umount /mnt/s3
526
</pre>
527
# Create upstart job to mount the s3 file system start up
528
<pre>
529
$ sudo nano /etc/init/s3.conf
530
</pre>
531
Add the following text and save.
532
<pre>
533
description "Mount Amazon S3 file system on system start"
534
535
start on (local-filesystems and net-device-up IFACE!=lo)
536
stop on runlevel [016]
537
538
respawn
539
540
exec s3fs -f [your-s3-bucket-name] /mnt/s3 -ouse_cache=/tmp -o allow_other
541
</pre>
542
# Start the s3 job
543
<pre>
544
sudo start s3
545
</pre>
546
# Test it worked
547
<pre>
548
$ echo hello > /mnt/s3/welcome2.txt
549
$ ls /mnt/s3
550
</pre>
551
# Create the backup script file
552
<pre>
553
$ sudo apt-get install mailutils
554
$ sudo nano /usr/local/bin/backup-redmine.sh
555
</pre>
556
Add the following text and save.
557
<pre>
558 13 Dimitry Profus
#!/bin/bash
559 1 Dimitry Profus
# Script to backup Redmine files to a mounted storage device
560
# with daily, weekly, monthly backup rotation
561
562 12 Dimitry Profus
# Sysadmin email address
563
sysadmin_email="admin@domain.com"
564 1 Dimitry Profus
565
# What to backup
566 12 Dimitry Profus
db_dump_file="/usr/share/redmine/db/redmine-database-dump.sql"
567 1 Dimitry Profus
568 13 Dimitry Profus
backup_files="$db_dump_file /usr/share/redmine/files /var/hg /var/svn /etc/apache2/conf.d/hg.conf"
569 12 Dimitry Profus
backup_files="$backup_files /etc/apache2/sites-available/redmine /etc/init/s3.conf /etc/cron.d/redmine"
570
backup_files="$backup_files /usr/local/bin/backup-redmine.sh"
571
572 1 Dimitry Profus
# Where to backup to
573 12 Dimitry Profus
backup_dir="/mnt/s3"
574 1 Dimitry Profus
575
# Set database access
576 12 Dimitry Profus
redmine_db_name="redmine"
577
redmine_db_user="redmine"
578
redmine_db_password="password"
579 1 Dimitry Profus
580
# Encryption
581 12 Dimitry Profus
encrypt="true"
582 13 Dimitry Profus
secret_passphrase="password"
583 1 Dimitry Profus
584 12 Dimitry Profus
# Set rotation schedule in units of days ( 0 = disabled )
585 1 Dimitry Profus
daily_remove_older_than=6
586 12 Dimitry Profus
weekly_remove_older_than=31
587 1 Dimitry Profus
monthly_remove_older_than=62
588
589
# Redirect stderr to a log file
590 12 Dimitry Profus
error_log="/tmp/backup-redmine.log"
591 1 Dimitry Profus
exec 6>&2
592
exec 2>$error_log
593
594
on_exit() {
595
    # Restore IO output
596
    exec 2>&6  6>$-
597
598
    # Check for errors
599
    if [ -s "$error_log" ]; then
600 12 Dimitry Profus
        logger -t "$0" -s "#### Backup Failed ####"
601
        logger -t "$0" -s -f "$error_log"
602
        cat "$error_log" | mail -s "Backup failed!"  $sysadmin_email
603 1 Dimitry Profus
     else
604 12 Dimitry Profus
        logger -t "$0" -s "Backup Complete"
605 1 Dimitry Profus
    fi
606
607
    # Clean up
608
    rm -f $error_log
609
}
610
611
trap on_exit EXIT SIGHUP SIGINT SIGQUIT SIGTERM
612
613
# Setup variables for the archive filename.
614
hostname=$(hostname -s)
615
date_stamp=`date +%Y-%m-%d`                    # Date p e.g 2011-12-31
616
date_day_of_week=`date +%A`                    # Day of the week e.g. Monday
617
date_day_of_month=`date +%e`                   # Date of the Month e.g. 27
618
619
# Is the  backup directory mounted?
620
mount | grep -sq "$backup_dir"
621
if  [ $? != 0 ]; then
622
   echo "backup destination ${backup_dir} is not mounted" >&2
623
  exit 1
624 12 Dimitry Profus
fi
625 1 Dimitry Profus
626 12 Dimitry Profus
# Delete old archives
627 13 Dimitry Profus
find "${backup_dir}" -mtime +"$monthly_remove_older_than" -type f -name "${hostname}_fullbackup_monthly*" -exec rm {} \;
628
find "${backup_dir}" -mtime +"$weekly_remove_older_than" -type f -name "${hostname}_fullbackup_weekly*" -exec rm {} \;
629
find "${backup_dir}" -mtime +"$daily_remove_older_than" -type f -name "${hostname}_fullbackup_daily*" -exec rm {} \;
630 1 Dimitry Profus
631 12 Dimitry Profus
# Determine the backup schedule
632 1 Dimitry Profus
if [[ $monthly_remove_older_than -gt "0" && $date_day_of_month == "1" ]]; then
633 12 Dimitry Profus
    schedule="monthly"
634
elif [[ $weekly_remove_older_than -gt "0" && $date_day_of_week == "Saturday" ]]; then
635
    schedule="weekly"
636
elif [[ $daily_remove_older_than -gt "0" ]]; then
637
    schedule="daily"
638
else
639 1 Dimitry Profus
    echo "Invalid backup rotation schedule" >&2
640 12 Dimitry Profus
    exit 1
641 1 Dimitry Profus
fi
642 12 Dimitry Profus
643 13 Dimitry Profus
archive_file="${backup_dir}/${hostname}_fullbackup_${schedule}_${date_stamp}.tgz"
644 12 Dimitry Profus
645 1 Dimitry Profus
# Dump the redmine database
646 12 Dimitry Profus
rm -f "${db_dump_file}"
647 1 Dimitry Profus
mysqldump --user="${redmine_db_name}" --password="${redmine_db_password}" "${redmine_db_name}" > $db_dump_file
648
649
# Write the archive file to the backup directory
650
if [ $encrypt == "true" ]; then
651 13 Dimitry Profus
    tar czP ${backup_files} | gpg -c -z 0 --yes --no-use-agent --passphrase="${secret_passphrase}" -o "${archive_file}.gpg"
652 1 Dimitry Profus
else
653 13 Dimitry Profus
    tar czfP "${archive_file}" ${backup_files}
654 1 Dimitry Profus
fi
655
656
if [ -s "$error_log" ]; then
657
    exit 1
658
else
659
    exit 0
660
fi
661
</pre>
662
# Setup permissions 
663
<pre>
664 6 Dimitry Profus
sudo chmod 770 /usr/local/bin/backup-redmine.sh
665 1 Dimitry Profus
</pre>
666
# Schedule the backup to run once a day at 12am
667
<pre>
668
$ sudo nano /etc/cron.d/redmine
669
670
Add the following line and save
671
672
0 0 * * * root /usr/local/bin/backup-redmine.sh
673
</pre>
674
# Test the script
675
<pre>
676
$ sudo backup-redmine.sh
677
$ ls -R /mnt/s3
678
</pre>