Project

General

Profile

HowTo Migrate Redmine to a new server to a new Redmine version » History » Version 2

Gergely Szabo, 2011-04-02 10:31

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
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 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>