HowTo Migrate Redmine to a new server to a new Redmine version » History » Version 1
Gergely Szabo, 2011-03-31 17:53
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 | |*machine*|*OS*|*Redmine*| |
||
6 | |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 | Usage: redmine_bak [ -r | -h ] |
||
18 | |||
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 | -r --restore |
||
23 | Beforehand, check out the desired version of the Redmine database from git-repo. |
||
24 | This command will restore that version into Redmine. |
||
25 | |||
26 | -h --help |
||
27 | Print this help text. |
||
28 | EOF |
||
29 | exit $1 |
||
30 | } |
||
31 | |||
32 | DATABASE=`cat /etc/redmine/default/database.yml | sed -rn 's/ *database: (.+)/\1/p'` |
||
33 | USERNAME=`cat /etc/redmine/default/database.yml | sed -rn 's/ *username: (.+)/\1/p'` |
||
34 | PASSWORD=`cat /etc/redmine/default/database.yml | sed -rn 's/ *password: (.+)/\1/p'` |
||
35 | FILES=/var/lib/redmine/default/files |
||
36 | cd /root/redmine |
||
37 | |||
38 | # Backup |
||
39 | if [ "$1" = "" ]; then |
||
40 | /usr/bin/mysqldump --user=${USERNAME} --password=${PASSWORD} --skip-extended-insert $DATABASE > redmine.sql |
||
41 | cp -f ${FILES}/* . |
||
42 | git add * |
||
43 | git commit -m "`date`" |
||
44 | git push --all origin |
||
45 | |||
46 | # Restore |
||
47 | elif [ "$1" = "-r" -o "$1" = "--restore" ]; then |
||
48 | /usr/bin/mysql --user=${USERNAME} --password=${PASSWORD} $DATABASE < redmine.sql |
||
49 | cp -f [!r][!e][!d][!m][!i][!n][!e]* $FILES |
||
50 | |||
51 | # Help |
||
52 | elif [ "$1" = "-h" -o "$1" = "--help" ]; then |
||
53 | usage 0 |
||
54 | |||
55 | # Wrong parameter |
||
56 | else |
||
57 | usage 1 |
||
58 | |||
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 | # git init |
||
74 | # git remote add ssh://git@GitServer/~/redmine.git |
||
75 | </pre> |
||
76 | |||
77 | h2. Backing Up the Old Machine |
||
78 | |||
79 | redmine_bak is called every midnight by cron without parameters, which means back-up. |
||
80 | It gets database-name, MySQL username and password from the database.yml file. |
||
81 | Besides the database, the uploaded files are saved too, see the FILES variable for their location. |
||
82 | |||
83 | 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). |
||
84 | |||
85 | 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. |
||
86 | |||
87 | Before the migration, the last backup from the old machine is available on GitServer. |
||
88 | |||
89 | h2. The New Machine |
||
90 | |||
91 | Redmine's email config should be simply copied from Old the New. Somehow. It's located here: |
||
92 | <pre>/etc/redmine/default/email.yml</pre> |
||
93 | |||
94 | 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. |
||
95 | <pre> |
||
96 | # cd /root |
||
97 | # git clone ssh://git@GitServer/~/redmine.git |
||
98 | </pre> |
||
99 | |||
100 | We assume you already have a running Redmine on the New machine with a virgin database. |
||
101 | Import the saved database into Redmine, then migrate the database and restart Redmine: |
||
102 | <pre> |
||
103 | # cd /root/redmine |
||
104 | # ./redmine_bak --restore |
||
105 | # cd /usr/share/redmine |
||
106 | # rake db:migrate RAILS_ENV=production |
||
107 | # touch /usr/share/redmine/tmp/restart.txt |
||
108 | </pre> |
||
109 | |||
110 | That's it. |
||
111 | |||
112 | We also need to set up regular backups on the new machine as well: |
||
113 | <pre> |
||
114 | # crontab -e |
||
115 | </pre> |
||
116 | This will open up your favourite editor vi, vi, vi or vi. Or in my case, mcedit. You should add a line to create a backup every midnight: |
||
117 | <pre> |
||
118 | 0 0 * * * /root/redmine/redmine_bak |
||
119 | </pre> |