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