HowTo Migrate Redmine to a new server to a new Redmine version » History » Version 27
Etienne Massip, 2012-10-02 08:46
Spam squashing
| 1 | 1 | Gergely Szabo | h1. The Question |
|---|---|---|---|
| 2 | |||
| 3 | How to move your Redmine data to another machine with a newer Redmine version? |
||
| 4 | |||
| 5 | 2 | Gergely Szabo | |*Machine*|*OS*|*Redmine*| |
| 6 | 1 | Gergely Szabo | |Old|Ubuntu 10.04|0.9.3| |
| 7 | |New|Debian Wheezy Testing|1.1.2| |
||
| 8 | |||
| 9 | h1. The Answer |
||
| 10 | |||
| 11 | The answer can be found mainly in my well commented Redmine backup-script which can also restore data from backup. |
||
| 12 | The executable (chmod +x) script is called *redmine_bak*, residing in /root/redmine/ along with a git-repo. See details below. |
||
| 13 | <pre> |
||
| 14 | #!/bin/bash |
||
| 15 | usage() { |
||
| 16 | cat <<EOF |
||
| 17 | 3 | Gergely Szabo | Usage: redmine_bak [ -r | -h ] [commit msg] |
| 18 | 1 | Gergely Szabo | |
| 19 | When called without parameters, the Redmine database and files are dumped to |
||
| 20 | git-repo in /root/redmine, then the git-repo is pushed to ssh://git@GitServer. |
||
| 21 | |||
| 22 | 3 | Gergely Szabo | When the first parameter is none of the ones below, the same backup procedure |
| 23 | is done, but the commit message is the parameter list instead of the date. |
||
| 24 | |||
| 25 | 1 | Gergely Szabo | -r --restore |
| 26 | Beforehand, check out the desired version of the Redmine database from git-repo. |
||
| 27 | This command will restore that version into Redmine. |
||
| 28 | |||
| 29 | -h --help |
||
| 30 | Print this help text. |
||
| 31 | EOF |
||
| 32 | exit $1 |
||
| 33 | } |
||
| 34 | |||
| 35 | DATABASE=`cat /etc/redmine/default/database.yml | sed -rn 's/ *database: (.+)/\1/p'` |
||
| 36 | USERNAME=`cat /etc/redmine/default/database.yml | sed -rn 's/ *username: (.+)/\1/p'` |
||
| 37 | PASSWORD=`cat /etc/redmine/default/database.yml | sed -rn 's/ *password: (.+)/\1/p'` |
||
| 38 | FILES=/var/lib/redmine/default/files |
||
| 39 | cd /root/redmine |
||
| 40 | |||
| 41 | 3 | Gergely Szabo | # Help |
| 42 | if [ "$1" = "-h" -o "$1" = "--help" ]; then |
||
| 43 | usage 0 |
||
| 44 | 1 | Gergely Szabo | |
| 45 | # Restore |
||
| 46 | elif [ "$1" = "-r" -o "$1" = "--restore" ]; then |
||
| 47 | 3 | Gergely Szabo | /usr/bin/mysql --user=${USERNAME} --password=${PASSWORD} $DATABASE < redmine.sql |
| 48 | cp -f [!r][!e][!d][!m][!i][!n][!e]* $FILES |
||
| 49 | 1 | Gergely Szabo | |
| 50 | 3 | Gergely Szabo | # Backup |
| 51 | 1 | Gergely Szabo | else |
| 52 | 3 | Gergely Szabo | if [ "$1" ]; then MSG="$@"; else MSG="`date`"; fi |
| 53 | /usr/bin/mysqldump --user=${USERNAME} --password=${PASSWORD} --skip-extended-insert $DATABASE > redmine.sql |
||
| 54 | cp -f ${FILES}/* . |
||
| 55 | git add * |
||
| 56 | git commit -m "$MSG" |
||
| 57 | git push --all origin |
||
| 58 | 1 | Gergely Szabo | |
| 59 | fi |
||
| 60 | </pre> |
||
| 61 | |||
| 62 | h2. Prepare Git-repos for Backups |
||
| 63 | |||
| 64 | We have a third backup machine called GitServer which has a simple github service represented by the git user. We need a bare git repo for redmine: |
||
| 65 | <pre> |
||
| 66 | git@GitServer ~ $ mkdir redmine.git && cd redmine.git && git --bare init |
||
| 67 | </pre> |
||
| 68 | |||
| 69 | On the Old Redmine machine: We assume its root has a passphrase-less ssh-key, and his public key is stored on the GitServer backup machine in /home/git/.ssh/authorized_keys. |
||
| 70 | |||
| 71 | Create git-repo on Old Redmine machine: |
||
| 72 | <pre> |
||
| 73 | 2 | Gergely Szabo | # cd /root/redmine |
| 74 | 1 | Gergely Szabo | # git init |
| 75 | # git remote add ssh://git@GitServer/~/redmine.git |
||
| 76 | </pre> |
||
| 77 | |||
| 78 | h2. Backing Up the Old Machine |
||
| 79 | |||
| 80 | redmine_bak is called every midnight by cron without parameters, which means back-up. |
||
| 81 | It gets database-name, MySQL username and password from the database.yml file. |
||
| 82 | Besides the database, the uploaded files are saved too, see the FILES variable for their location. |
||
| 83 | |||
| 84 | After dumping the database to redmine.sql and copying the files to /root/redmine/ they are all committed to the git repo which, in turn is pushed to the backup-box (GitServer). |
||
| 85 | |||
| 86 | The advantage of the git-repo is that you can go back to the last correct version even if you notice a corruption 2 weeks too late. You could even use git-bisect. |
||
| 87 | |||
| 88 | Before the migration, the last backup from the old machine is available on GitServer. |
||
| 89 | |||
| 90 | h2. The New Machine |
||
| 91 | |||
| 92 | Redmine's email config should be simply copied from Old the New. Somehow. It's located here: |
||
| 93 | <pre>/etc/redmine/default/email.yml</pre> |
||
| 94 | |||
| 95 | You should be root, have a passphrase-less ssh-key, stored on the GitServer backup machine in /home/git/.ssh/authorized_keys. Same as with the Old Redmine machine. Let's clone the backup repo to the new box. |
||
| 96 | <pre> |
||
| 97 | # cd /root |
||
| 98 | # git clone ssh://git@GitServer/~/redmine.git |
||
| 99 | </pre> |
||
| 100 | |||
| 101 | We assume you already have a running Redmine on the New machine with a virgin database. |
||
| 102 | Import the saved database into Redmine, then migrate the database and restart Redmine: |
||
| 103 | <pre> |
||
| 104 | # cd /root/redmine |
||
| 105 | # ./redmine_bak --restore |
||
| 106 | # cd /usr/share/redmine |
||
| 107 | # rake db:migrate RAILS_ENV=production |
||
| 108 | # touch /usr/share/redmine/tmp/restart.txt |
||
| 109 | </pre> |
||
| 110 | |||
| 111 | That's it. |
||
| 112 | |||
| 113 | We also need to set up regular backups on the new machine as well: |
||
| 114 | <pre> |
||
| 115 | # crontab -e |
||
| 116 | </pre> |
||
| 117 | 2 | Gergely Szabo | This will open up your favourite editor vi, vi, vi or vi. Or in my case, mcedit. Add a line to create a backup every midnight (Midnight cron jobs with Midnight Commander): |
| 118 | 1 | Gergely Szabo | <pre> |
| 119 | 0 0 * * * /root/redmine/redmine_bak |
||
| 120 | </pre> |