Project

General

Profile

RedmineBackupRestore » History » Version 11

stefan pofahl, 2025-01-31 17:22

1 1 Go MAEDA
h1. Backing up and restoring Redmine
2
3
{{>toc}}
4
5
h2. Backup
6
7
Redmine backups should include:
8
* Database
9 4 Go MAEDA
* Attachments (stored in the @files@ directory under the installation directory by default)
10 1 Go MAEDA
11
h3. Backing up database
12
13
h4. MySQL
14
15
The @mysqldump@ command can be used to backup the contents of your MySQL database to a text file. For example:
16
<pre>
17 4 Go MAEDA
/usr/bin/mysqldump -u <username> -p<password> -h <hostname> <redmine_database> > /path/to/backup/db/redmine.sql
18 1 Go MAEDA
</pre>
19
20 2 Go MAEDA
You can find @<username>@, @<password>@, @<hostname>@, and @<redmine_database>@ in the file @config/database.yml@. @<host_name>@ may not be required depending on your installation of the database.
21
22 1 Go MAEDA
h4. PostgreSQL
23
24
The @pg_dump@ command can be used to backup the contents of a PostgreSQL database to a text file. Here is an example:
25
<pre>
26 2 Go MAEDA
/usr/bin/pg_dump -U <username> -h <hostname> -Fc --file=redmine.sqlc <redmine_database>
27 1 Go MAEDA
</pre>
28
29 2 Go MAEDA
You can find @<username>@, @<hostname>@, and @<redmine_database>@ in the file @config/database.yml@. @<hostname>@ may not be required depending on your installation of the database. The @pg_dump@ command will prompt you to enter the password when necessary.
30
31 1 Go MAEDA
h4. SQLite
32
33
SQLite databases are all contained in a single file, so you can back them up by copying the file to another location.
34 2 Go MAEDA
35
You can determine the file name of SQLite database by looking at @config/database.yml@.
36 1 Go MAEDA
37
h3. Backing up attachments
38
39 3 Go MAEDA
All file uploads are stored in @attachments_storage_path@ (defaults to the @files/@ directory). You can copy the contents of this directory to another location to easily back it up.
40
41 10 stefan pofahl
+WARNING:+ @attachments_storage_path@ may point to a different directory other than @files/@. Be sure to check the setting in @$RAILS_ROOT/$RAILS_ROOT/config/configuration.yml@ to avoid making a useless backup.
42
This file may not exist (status: Redmine v5.0.4), it exist a template @$RAILS_ROOT/config/configuration.yml.example@ to change
43
the standard values, copy this file and rename it to @$RAILS_ROOT/$RAILS_ROOT/configuration.yml@.
44 11 stefan pofahl
In my installation via Debian package, the attached files are stored in
45
@/var/lib/redmine/default/files@.
46
You can find this folder by file search, attach a file to wiki-page or add a document to a project and look for "*_filename.filextention", in my case the stored file start with 12 digits: <@yymmddhhmmss@>.
47
Interesting is also where the file @Gemfile.lock@ is located, for me it was two levels above in the folder hierarchy: @/var/lib/redmine/files@
48
Keep also in mind, you may you have plugins installed that my have a different storage location, in my case it is the plugin "DMSF":https://www.redmine.org/plugins/redmine_dmsf.
49 1 Go MAEDA
50
h3. Sample backup script
51
52
Here is a simple shell script that can be used for daily backups (assuming you're using a MySQL database):
53
54
<pre>
55
# Database
56
/usr/bin/mysqldump -u <username> -p<password> <redmine_database> | gzip > /path/to/backup/db/redmine_`date +%Y-%m-%d`.gz
57
58
# Attachments
59
rsync -a /path/to/redmine/files /path/to/backup/files
60
</pre>
61
62
h2. Restore
63
64 5 Gerd Pokorra
h3. Restoring a database
65
66
h4. MySQL
67
68 6 Gerd Pokorra
For example if you have a gziped dump file with the name @2018-07-30.gz@, then the database can be restored with the following command:
69 5 Gerd Pokorra
70
<pre>
71
gunzip -c 2018-07-30.gz | mysql -u <username> --password <redmine_database>
72
Enter password:
73
</pre>
74
75
h4. PostgreSQL
76
77 7 Gerd Pokorra
When the option @-Fc@ of the command @pg_dump@ is used like it is at the above example then you need to use the command @pg_restore@:
78
79
<pre>
80
pg_restore -U <username> -h <hostname> -d <redmine_database> redmine.sqlc
81
</pre>
82
83
otherwise a text file can be restored with @psql@:
84
85
<pre>
86
psql <redmine_database> < <infile>
87
</pre> 
88 5 Gerd Pokorra
89
h4. SQLite
90
91 8 Gerd Pokorra
Copy the database file from the backup location.