Redmine: backup and restore

A series of articles on installing and configuring Redmine

  • Installing Redmine 4.0.5 NGINX PostgreSQL on Centos 7
  • Redmine update 4.0.5 – 4.1.0
  • Redmine: backup and restore

Redmine backup

Create a file with parameters for connecting to the database in order to create a PostgreSQL dump in the future without entering a password

                      
                        $ sudo nano /root/.pgpass
localhost:5432:redmine:redmine:%password%
$ sudo chmod 600 /root/.pgpass
                      
                    

We make a backup of the database:

                      
                        $ sudo pg_dump -d "redmine" -h localhost -Fc -U redmine -w -f "/opt/redmine/$(date +%Y%m%d_%H%M%S)_redmine.dump"
                      
                    

Making a backup of the directory where Redmine is installed

                      
                        $ tar -czf /opt/redmine/$(date +%Y%m%d_%H%M%S)_redmine.tar.gz /opt/redmine-4.0.5
                      
                    

These actions can be executed with a script and add the script to the crontab

Restoring Redmine

Consider the option when you need to restore Redmine to a clean server. First, we need to install Redmine in accordance with one of the previous articles, but p. 7 “Installing Redmine. Continuation “ will change a little:

Go to the directory and write the settings for PostgreSQL

                      
                        $ cd /opt/redmine-4.0.5/
$ bundle config build.pg --with-pg-config=/usr/pgsql-10/bin/pg_config
                      
                    

Install the necessary gems (in this case locally)

                      
                        $ bundle install --without development test mysql2 sqlite --local
                      
                    

Create a file with database connection parameters in order to create a PostgreSQL dump in the future without entering a password

                      
                        $ sudo nano /root/.pgpass
localhost:5432:redmine:redmine:%password%
$ sudo chmod 600 /root/.pgpass
                      
                    

Stop the Nginx web server so that there are no connections to the database

                      
                        $ sudo systemctl stop nginx
                      
                    

Connecting to the database

                      
                        $ sudo su - postgres
-bash-4.2$ psql
                      
                    

If PostgreSQL has a redmine database, for example, with test data, delete it and create a clean one

                      
                        postgres=# DROP DATABASE redmine;
postgres=# CREATE DATABASE redmine WITH ENCODING='UTF8' OWNER=redmine;
postgres=# q
-bash-4.2$ exit
                      
                    

We restore the database from the dump and start Nginx:

                      
                        $ sudo pg_restore -h localhost -U redmine -d "redmine" -v "/tmp/20200115_094958_redmine.dump"
$ sudo systemctl start nginx
                      
                    

Recovering Redmine files from the archive, saving them to the directory /opt/nginx-4.0.5

We start generating the token:

                      
                        $ bundle exec rake generate_secret_token
                      
                    

Updating the database structure

                      
                        $ RAILS_ENV=production bundle exec rake db:migrate
                      
                    

Reloading Nginx

                      
                        $ sudo systemctl restart nginx
                      
                    

Done, Redmine restored

Related Posts