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