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